Repository navigation
Conversation
Co-Authored-By: Claude Code <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-Authored-By: Claude Code <noreply@anthropic.com>
…ads a code Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…nto luismeyer/precompute-deployment-key
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…PUTE_SECRET Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nto luismeyer/precompute-deployment-key
It printed once per build worker, and also when the task is never cached. The docs describe the fix. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / why
Precompute is the last v4 feature which throws without
FLAGS_SECRET. With this change, the precompute functions fall back to a key derived fromVERCEL_DEPLOYMENT_KEYwhen there is no secret.lib/precompute-secret.ts:deploymentPrecomputeSecret()derives 32 bytes with HKDF-SHA-256 (Web Crypto, so it works in the Edge runtime) and the infoflags:precompute:v1. The derived key is not the deployment key itself, so precompute does not share a key with other users ofVERCEL_DEPLOYMENT_KEY.secretargument, thenFLAGS_SECRET, thenFLAGS_PRECOMPUTE_SECRET(new, the name whichstandarduses), then the deployment key. With asecretargument or aFLAGS_SECRET, nothing changes:FLAGS_PRECOMPUTE_SECRETis only used when there is noFLAGS_SECRET.vercel buildwith--prebuilt).secretparameters in Next.js is nowundefinedand notprocess.env.FLAGS_SECRET. The functions read the variables themselves.serialize,deserialize,getPrecomputed,generatePermutations(and thusprecompute).precompute,generatePermutationsand the read of a precomputed flag, throughgetPrecomputeSecretinsveltekit/env.ts. A page reads a code with the secret of the handle (the secret passed tocreateHandle, or elseFLAGS_SECRET), or else with the defaults of precompute. As before this PR, the app must pass the same secret tocreateHandle,precomputeandgeneratePermutations, or none to all of them.next dev,vite dev, a localnext build && next start): when there is no secret and no deployment key, the functions use a fixed, public secret, but only when there is aVERCEL_OIDC_TOKENfor the environmentdevelopment(whatvercel env pullwrites; the token is only decoded, like infindVercelProject). It is the last in the order. WhenNODE_ENVis notdevelopment, they warn one time, because anyone can create a code with this secret. Without such a token (a custom host, or a project which never ranvercel env pull), they throw as before, and the error says to runvercel env pullor to setFLAGS_PRECOMPUTE_SECRET.VERCEL_DEPLOYMENT_KEY, the functions throw the same errors as before. "On Vercel" (isOnVercelinlib/vercel-platform.ts) means thatVERCELis set (a build or a deployment, alsovercel build) or that the request context of Vercel exists (every deployment at runtime).Why a key per deployment is enough
A code is created by the build (
generatePermutations) and by the middleware, and read by the pages of the same deployment. Vercel writesVERCEL_DEPLOYMENT_KEYwith one value to the build environment and to the runtime environment of a deployment (get-deployment-env-context.tsin vercel/api), so all three use the same key. HS256 is deterministic, so the build and the middleware create the same code for the same values. This is the same reasoning as the build secret ofwithFlagsonstandard.Limits
VERCEL_DEPLOYMENT_KEYis only set when the project exposes the system environment variables. A project without them must keepFLAGS_SECRET. This is accepted: the signed overrides and the flags discovery of this stack need them too. The docs (docs: FLAGS_SECRET is optional on Vercel #596) say so.VERCELis one of these variables too, so such a deployment is detected by the request context: the runtime throws. Verified on a test project: the build of such a project hasVERCEL=1and no key, so it throws.vercel buildwith--prebuiltis not covered, and this is accepted: the deployment does not exist at build time, so the build has no key and throws. Such projects must keepFLAGS_SECRET. The docs (docs: FLAGS_SECRET is optional on Vercel #596) say so.vercel env pullsigns with the public secret and warns; such a build must not be hosted outside of Vercel. On Vercel the public secret is never used.entrieswithgeneratePermutations) in a localvite buildwithoutFLAGS_SECRETthrows: the dynamic environment, which has theVERCEL_OIDC_TOKENof.env.local, can not be read while prerendering, and the static one is not read for it, so that the token is not put into the server bundle.FLAGS_SECRET.VERCEL_DEPLOYMENT_KEYis passed to the task but not hashed. Reproduced onflags-pr597-turbo-cache: aFULL TURBOdeploy serves prerendered pages which never match (404 withdynamicParams = false), and ISR revalidation throwssignature verification failed. Next.js with Skew Protection (default on Pro and Enterprise) is not affected, because turbo then hashesVERCEL_DEPLOYMENT_ID. The functions do not warn about it: a warning at build time printed once per build worker, and also for a task which is never cached. The fix is"env": ["VERCEL_DEPLOYMENT_KEY"]inturbo.jsonorFLAGS_PRECOMPUTE_SECRET. The docs (docs: FLAGS_SECRET is optional on Vercel #596) say so.Tests
packages/flags:pnpm test(20 files, 310 tests passed),pnpm type-check,pnpm checkandpnpm buildare ok.New tests: the derivation (stable, 32 bytes, different per deployment key, not the key itself), Next.js and SvelteKit without
FLAGS_SECRET(the build and the middleware create the same code, a page reads it, a code of another deployment is rejected, the order of the secrets, throws on Vercel without any key, the public secret with a development OIDC token, throws without it, the warning, a deployment withoutVERCEL).On Vercel: tested on the preview deployments of
vercel-site.By hand:
examples/snippetswithnext devand an emptyFLAGS_SECRETserves the precompute pages (App Router and Pages Router) with 200. With the fallback off, the same request fails withCan not serialize due to missing secret.🤖 Generated with Claude Code