Skip to content

fix: reuse local JWKS resolvers across requests - #211

Open
shoemoney wants to merge 1 commit into
supabase:mainfrom
shoemoney:fix/cache-inline-jwks
Open

shoemoney wants to merge 1 commit into
supabase:mainfrom
shoemoney:fix/cache-inline-jwks

Conversation

@shoemoney

Copy link
Copy Markdown

Inline JWKS verification creates a new local resolver on every call, so jose imports the same public key again for each token. This also affects SUPABASE_JWKS, which is parsed into a fresh object for each request.

Reuse resolvers in a 16-entry LRU cache keyed by the serialized key set. Changing or removing a key changes the cache key, including when the caller edits the existing object. Each resolver keeps a snapshot so later edits cannot change its symmetric-key lookup. Environment reads and parsing still happen on each resolution.

Fixes #199.

The import-reuse regressions fail on the original code. Tests also cover rotation, revocation, reparsed environment values, symmetric-key mutation and eviction with real signed tokens. All 592 tests pass. Tests, build and type checks pass on Node 22.22.3 and 26.13.1; lint, example type checks, dependency checks, package smoke tests, export checks and the JSR publish dry-run pass too. The local-stack E2E suite wasn't run.

@shoemoney
shoemoney requested review from a team as code owners November 28, 2026 04:50

This branch has not been deployed

No deployments
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.

Inline JWKS builds a new createLocalJWKSet per verification (about 40% slower)

1 participant