From a0d2d773292b823eb29bed034958aebeb996b4d1 Mon Sep 17 00:00:00 2001 From: Quintin Willison Date: Mon, 14 Sep 2026 15:28:44 +0100 Subject: [PATCH] docs(capability-matrix): recommend exponential backoff for forced JWK Set refetches in the `get_claims` spec Step 4 of the get_claims spec mandates a JWK Set refetch on any unknown `kid` with no rate limit, so a storm of attacker-minted key ids can drive one discovery fetch per bogus token against the project's JWKS endpoint. Every SDK implementing the step as written inherits that amplification, and supabase-js currently refetches unconditionally on every miss. The amendment recommends exponential backoff on forced refetches: while consecutive forced fetches fail to resolve the `kid` that forced them, the wait before the next one doubles (for example one second up to a sixteen-second backstop), and a fetch that resolves its `kid` clears the wait. Misses inside the wait resolve as unknown and take the existing server-side verification fallback, so tokens signed by a freshly rotated key keep verifying throughout. Surfaced during review of the Go SDK's implementation in supabase/supabase-go#78. Co-authored-by: Claude --- packages/capability-matrix/specs/auth/session/get_claims.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/capability-matrix/specs/auth/session/get_claims.md b/packages/capability-matrix/specs/auth/session/get_claims.md index 4c770bab..6d7602bd 100644 --- a/packages/capability-matrix/specs/auth/session/get_claims.md +++ b/packages/capability-matrix/specs/auth/session/get_claims.md @@ -18,7 +18,7 @@ Verification proceeds in order, cheapest first: 1. **Decode.** The token must be three base64url segments carrying a JSON header and JSON payload. Malformed input fails here with no network traffic. 2. **Expiry.** The `exp` claim must be present and in the future, judged against the local clock with no skew allowance. (Some SDKs offer an opt-in flag that skips this check for callers that need to inspect expired tokens.) 3. **Route.** If the header declares an asymmetric signing algorithm the SDK can verify locally (for example ES256 or RS256) and names a key id (`kid`), verification is local. Any other token - one signed with the legacy HS256 shared secret, or missing an algorithm or key id - is verified by calling [Get User](auth.session.get_user) instead: a successful response proves the server accepts the token, and the claims from step 1's decode are returned. -4. **Resolve the key.** The `kid` is looked up in the cached JWK Set. An unknown `kid` forces a refetch even when the cache is fresh, so freshly rotated signing keys are usable immediately. If the refetched document still lacks the `kid`, fall back to server-side verification as in step 3. +4. **Resolve the key.** The `kid` is looked up in the cached JWK Set. An unknown `kid` forces a refetch even when the cache is fresh, so freshly rotated signing keys are usable immediately. SDKs should rate-limit these forced refetches with exponential backoff: while consecutive forced fetches fail to resolve the `kid` that forced them, double the wait before the next one (for example one second up to a sixteen-second backstop), and clear the wait once a fetch resolves its `kid`. Misses inside the wait resolve as unknown and take the step 3 fallback, so a storm of attacker-minted `kid`s decays to a bounded fetch rate while a genuine rotation still verifies - immediately when the backoff is clear, via the fallback during a storm. If the refetched document still lacks the `kid`, fall back to server-side verification as in step 3. 5. **Verify.** The signature is checked over the `header.payload` signing input using the matched public key. Success returns the claims, the decoded header and the raw signature bytes. Failure is an invalid-signature error. The JWK Set is cached in the client for ten minutes, matching the `Cache-Control: public, max-age=600` the endpoint serves. The cache is shared across calls, and concurrent misses should coalesce into a single fetch.