Skip to content

[flags] encryptFlagValues returns an empty value when the public key of Vercel does not load - #604

Merged
luismeyer merged 2 commits into
luismeyer/flag-values-platform-encryptionfrom
luismeyer/encrypt-flag-values-degrade
Nov 17, 2026
Merged

luismeyer merged 2 commits into
luismeyer/flag-values-platform-encryptionfrom
luismeyer/encrypt-flag-values-degrade

Conversation

@luismeyer

@luismeyer luismeyer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Stacked on #586 (luismeyer/flag-values-platform-encryption), the PR which adds the encryption this changes.

This PR adds the KeySetError class to the key cache, which #587 also adds. When #586 is merged up into #587, packages/flags/src/lib/vercel-platform.ts can conflict there: keep the exported class of this PR.

What / why

This is a behavior change. Without a FLAGS_SECRET, encryptFlagValues loads the public key of Vercel from https://keys.vercel-flags.com/.well-known/jwks.json. When the key did not load, it threw, so a key host which is down failed the build of each prerendered page and the render of each dynamic page which calls it. The flag values are only for the Vercel Toolbar, so the page must not depend on the key host.

With this change, encryptFlagValues warns and returns an empty string when the key does not load, and FlagValues of flags/react renders nothing for an empty string.

  • lib/flag-values-platform.ts: encryptFlagValuesForPlatform catches only the KeySetError of the key cache (new on this base, exported, @internal; the cache threw a plain Error before) around publicKey.get(). That covers each way the key does not load: a timeout or a network error after the three attempts, a status which is not ok, a key set which is not valid or has no key for ECDH-ES, and the cooldown of 30 seconds after a failure.
  • The warning is flags: The flag values for the Vercel Toolbar are left out of the page. <cause>, at most one time in 30 seconds per process (warnWithCooldown). createHandle of SvelteKit logged flags: Could not encrypt the flag values for the Vercel Toolbar. <cause> before, which reads as if the values are written to the page in plaintext. Both now use one helper, warnFlagValuesLeftOut, so the SvelteKit message changes too.
  • The return type stays Promise<string>.
  • flags/react: FlagValues returns null for ''. A script tag with "" would make the Toolbar send an empty string to the decrypt API.
  • SvelteKit: createHandle already rendered the page without the flag values. It now also returns the HTML unchanged for the empty string, so it never injects a script tag with "". Its catch stays for the other failures without a secret (no project ID). The warning is the same as before. encryptFlagValues of flags/sveltekit returns the empty string too.

What still throws

  • Neither a secret nor a project ID (flags: Missing FLAGS_SECRET or a project ID ...), and a project ID which is too long. In Next.js the app calls encryptFlagValues itself, so these are for the developer. They are checked before the key is loaded.
  • A secret which is not valid. With a secret nothing changes: the public key is never loaded.
  • An error with which a framework controls the render (it has a digest, e.g. DYNAMIC_SERVER_USAGE of Next.js). The key cache does not wrap it, and it is not caught here.

Evidence

  • A single timeout of the key request failed a production build of vercel-docs-geistdocs. vercel/front#98090 bumped the snapshot which added the retries after it.
  • Datadog, last 7 days, apps of Vercel which use the snapshot (vercel-docs, vercel-marketing): 100 runtime errors flags: Could not load the public key for the flag values ... (95 in vercel-marketing on Nov 16, 5 in vercel-docs on Nov 17), and 5,403 build-log lines with this error across 63 deployments. It was not checked how many of these builds failed.

Limits

  • A page which is prerendered while the key does not load is built without the flag values, and stays so until it renders again (the next build or revalidation). Before, the build failed. The same holds for a result which the app caches.
  • An app which renders the script tag with data-flag-values itself, and not with FlagValues, now renders "" in this case. The docs say to leave the tag out for an empty value.
  • An app which caught the error of encryptFlagValues no longer gets it. The stack is not released, so this affects only the snapshots.
  • The docs of docs: FLAGS_SECRET is optional on Vercel #596 do not describe this failure, so they need no change. This PR adds the paragraph to api-reference/core/core.mdx and react.mdx.

Tests

packages/flags: pnpm test (20 files, 327 tests passed), pnpm type-check, pnpm check and pnpm build are ok. node scripts/validate-packages.mjs is ok.

New and changed tests:

  • lib/flag-values-platform.test.ts: the key does not load (three timeouts, 404, 503, a key set with a private key, a key set without a key for ECDH-ES) resolves to '' and warns one time per cooldown; it encrypts again when the key loads after the cooldown; no project ID still throws, without a request and without a warning; a secret which is not valid still throws and does not load the key. The test for an error with a digest is unchanged and still rejects with the same error.
  • react/index.test.tsx: FlagValues renders the tag for values, for a token and for {}, and nothing for ''.
  • sveltekit/without-secret.test.ts: the existing test of createHandle for a key which does not load passes unchanged (same HTML, three requests, one warning, same text). Without the new guard it fails with <script ...>""</script> in the HTML. New: encryptFlagValues of flags/sveltekit resolves to ''.
  • tests/next-static-build: the page now uses FlagValues. New case: next build with a key host which answers 503 exits with 0, the page is static, the HTML has no data-flag-values, and the build output has the warning. Both cases pass.

Note for tests/next-static-build: inside an AI coding agent, next build of Next.js 16.4.3 exits with 1 after the build, to print a notice that this version of Next.js has a known security vulnerability. This is so on the base branch too. Without the agent environment variables, as in CI, both cases pass.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 17, 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 12:34pm UTC
flags-sdk-dev Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-flagsmith Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-growthbook Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-launchdarkly Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-openfeature Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-posthog Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-reflag Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-snippets Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-statsig Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
flags-sdk-sveltekit-snippets Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
shirt-shop Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC
shirt-shop-api Ready Ready Preview, v0 Nov 17, 2026 12:34pm UTC

@vercel
vercel Bot temporarily deployed to Preview – flags-sdk-openfeature November 17, 2026 12:29 Inactive
@vercel
vercel Bot temporarily deployed to Preview – flags-sdk-growthbook November 17, 2026 12:29 Inactive
@vercel
vercel Bot temporarily deployed to Preview – flags-sdk-posthog November 17, 2026 12:29 Inactive
@vercel
vercel Bot temporarily deployed to Preview – flags-sdk-statsig November 17, 2026 12:29 Inactive
@vercel
vercel Bot temporarily deployed to Preview – flags-sdk-vercel November 17, 2026 12:29 Inactive
@luismeyer
luismeyer marked this pull request as ready for review November 17, 2026 12:30
luismeyer and others added 2 commits November 17, 2026 13:32
…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>
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>
@luismeyer
luismeyer force-pushed the luismeyer/encrypt-flag-values-degrade branch from 4177469 to 382cc08 Compare November 17, 2026 12:33
@luismeyer
luismeyer changed the base branch from luismeyer/precompute-deployment-key to luismeyer/flag-values-platform-encryption November 17, 2026 12:33
@luismeyer
luismeyer merged commit a24025d into luismeyer/flag-values-platform-encryption Nov 17, 2026
20 checks passed
@luismeyer
luismeyer deleted the luismeyer/encrypt-flag-values-degrade branch November 17, 2026 13:07

This branch was successfully deployed

14 active deployments
Preview – flags-sdk-dev — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – shirt-shop — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-snippets — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-launchdarkly — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-playground — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-sveltekit-snippets — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-openfeature — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-posthog — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-vercel — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-statsig — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-growthbook — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-reflag — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – flags-sdk-flagsmith — 382cc081 Deployed Nov 17, 2026 by vercel[bot]
Preview – shirt-shop-api — 382cc081 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.

1 participant