Skip to content

[flags] Encrypt FlagValues with the public key of Vercel without FLAGS_SECRET - #586

Open
luismeyer wants to merge 16 commits into
mainfrom
luismeyer/flag-values-platform-encryption
Open

luismeyer wants to merge 16 commits into
mainfrom
luismeyer/flag-values-platform-encryption

Conversation

@luismeyer

@luismeyer luismeyer commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Why

  • encryptFlagValues throws without FLAGS_SECRET, so a project needs a secret just to keep its flag values confidential.
  • The Flags Explorer can now decrypt values encrypted with the public key of Vercel through the API (vercel/api#103736, vercel/next-live-mode#3893 behind flags-explorer-api-decrypt).
  • This brings the platform encryption of the standard branch ([flags] FlagValues: projectIds in the protected header, flags-keys JWKS #575) to main, with the signature of encryptFlagValues unchanged.

What

  • With a secret (argument or FLAGS_SECRET), nothing changes.
  • Without one, encryptFlagValues encrypts with the public key from https://keys.vercel-flags.com/.well-known/jwks.json (ECDH-ES, A256GCM, projectIds and kid in the protected header, pur: flag-values, ver: 1, aud: vercel:flag-values). This is the format that @api/flag-values decrypts.
  • The project ID comes from VERCEL_PROJECT_ID, the VERCEL_OIDC_TOKEN of vercel env pull, or .vercel/project.json.
  • In SvelteKit, createHandle and encryptFlagValues no longer require a secret. Without one, the data-flag-values of a page use the public key, the overrides cookie is ignored, /.well-known/vercel/flags responds with 401, and precompute still requires a secret.
  • The key set is cached for 5 minutes. Concurrent loads share one request, and after a failed load there is a 30 s cooldown. A load stops after 5 s and tries one more time after a timeout: in a local production build of vercel-marketing (vercel/front#98090), busy build workers reached the timeout, and the cooldown then failed all five prerender attempts of Next.js.

Validation

  • New tests in flag-values-platform.test.ts cover the token format, finding the project ID, key caching and rotation, the error cooldown, and that a set FLAGS_SECRET is still used. without-secret.test.ts covers SvelteKit's createHandle and encryptFlagValues without a secret.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flags-playground Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-dev Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-flagsmith Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-growthbook Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-launchdarkly Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-openfeature Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-posthog Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-reflag Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-snippets Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-statsig Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
flags-sdk-sveltekit-snippets Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
shirt-shop Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC
shirt-shop-api Ready Ready Preview, v0 Nov 17, 2026 4:42pm UTC

…rcel-platform

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chriswdmr chriswdmr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Three things to fix before merge:

  • SvelteKit without a secret: a failure to load the key must not break the page render
  • Add a timeout to the key set fetch
  • Next.js middleware: remove the two new Edge Runtime build warnings

The other comments are suggestions and nits.

Comment thread packages/flags/src/sveltekit/index.ts Resolved
Comment thread packages/flags/src/lib/crypto.ts Resolved
Comment thread packages/flags/src/sveltekit/index.ts Resolved
luismeyer and others added 3 commits November 11, 2026 11:05
- Read env vars without a process global and from SvelteKit's $env
- Memoize the OIDC decode and the .vercel/project.json read
- No Edge Runtime warnings for process.getBuiltinModule / process.cwd
- Load the key set with a 5s timeout
- Rethrow framework control-flow errors instead of wrapping them
- SvelteKit: render the page without flag values when encryption fails
- Document that the fallback without a secret is silent

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…an decrypt

Note that decryptFlagValues, encryptFlagDefinitions and
decryptFlagDefinitions work only with a FLAGS_SECRET.

Co-Authored-By: Claude Code <noreply@anthropic.com>

@chriswdmr chriswdmr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes! One thing to fix before merge:

  • SvelteKit: loadEnv() must not put all private environment variables into the server bundle

Comment thread packages/flags/src/sveltekit/env.ts Resolved
luismeyer and others added 4 commits November 12, 2026 16:47
…ndle

Read the Vercel variables from $env/dynamic/private, by name, instead of
spreading $env/static/private.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…c keys

Load the key set with the fetch which Next.js replaced. The fetch of
Next.js made a static page dynamic for the no-store request, and failed
the build of a page with dynamic = 'error'.

Add a production build of a static Next.js page as a regression test.

Co-Authored-By: Claude Code <noreply@anthropic.com>
After five minutes, the key cache waited for the key host (up to the
timeout of five seconds) before it returned. It now returns the keys
which it has, and loads the new ones for the next call. Only the first
load and a refresh for a key which is not known wait.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Vercel removes an x-vercel-oidc-token header from each incoming request,
so a visitor can not choose the project of the host. Also name the token
of the request as a source of the project ID in the docs.

Co-Authored-By: Claude Code <noreply@anthropic.com>

@chriswdmr chriswdmr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! One comment about the key cache, for #587.

pending ??= load().finally(() => {
pending = undefined;
});
if (value !== undefined && !refresh) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (non-blocking): No limit on the age of the keys in memory

get() now returns the keys in memory at once when they are older than 5 minutes. There is no limit on that age: in my test, the first call after 24 h with no calls got the 24 h old key. In this PR that is only an old encryption key. But #587 verifies signatures with keys.get(), so a revoked key passes on the first request after an idle time. You gave this reason on #587.

Could get() wait for the load when the keys are older than a limit, for example 10 minutes? Then a busy instance does not wait, and an idle instance does not use very old keys.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in b636390: get() now waits for the load when the keys in memory are older than 10 minutes (staleMaxAgeMs). Between 5 and 10 minutes it still returns the keys in memory and reloads in the background, so a busy instance does not wait. The wait is at most the 5 s timeout, and a failed reload still keeps the keys in memory. Merged up the stack, so #587 and #589 verify with it too.

luismeyer and others added 3 commits November 13, 2026 10:42
…han ten minutes

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
… not fail a build

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
luismeyer and others added 2 commits November 17, 2026 14:07
…of Vercel does not load (#604)

* [flags] Return an empty value from encryptFlagValues when the public key of Vercel does not load

Without a FLAGS_SECRET, a key host which is down, or a request which
timed out, failed the build or the render of each page which encrypts
flag values. The values are only for the Vercel Toolbar, so
encryptFlagValues now warns and returns an empty string, and FlagValues
renders nothing for it. Errors of the configuration still throw.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* [flags] say that the flag values are left out of the page

The warning said "Could not encrypt the flag values", which reads as if
they are written to the page in plaintext.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

This branch was successfully deployed

14 active deployments
Preview – flags-sdk-dev — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-snippets — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-vercel — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-sveltekit-snippets — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-posthog — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-growthbook — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – shirt-shop — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-openfeature — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-flagsmith — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-launchdarkly — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-statsig — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-reflag — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-playground — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Preview – shirt-shop-api — b87b2ec6 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants