flashman
← All posts

JWT JWKS cache bugs: debug stale signing keys safely

Debug JWT signature failures from stale JWKS caches by checking kid values, cache headers, key rotation timing, issuer config, and decoded token claims.

2026-07-06 · 6 min read · Rahul Chitturi

  • jwt
  • jwks
  • auth

A JWT signature failure after key rotation does not always mean the token is forged. It can mean the verifier is holding an old JSON Web Key Set, the issuer changed cache headers, or a deployment split traffic across services with different key caches.

Treat JWKS failures as a cache and configuration investigation before loosening verification. Decode a non-production token, inspect the header, and compare the issuer's current keys with what each verifier is using.

Start with the kid header

The kid value tells a verifier which public key should validate the signature. If the token header references a key that is missing from the cached JWKS, the verifier may reject every request until the cache refreshes or the issuer republishes the key.

  • Decode the header and copy the kid exactly, including case
  • Confirm the issuer URL points to the expected tenant and environment
  • Check whether old keys remain published during the rotation window
  • Compare working and failing tokens for alg, kid, iss, and aud differences

Read cache behavior like production data

JWKS endpoints often include cache-control headers. A verifier that respects a long max-age can keep an old key longer than the identity provider dashboard suggests. A verifier that refreshes on every request can create outages when the provider is slow or rate-limited.

Record when the new key was first published, when the first failing token was issued, and when each service last refreshed its cache. The timeline usually shows whether this is an issuer rollout, a stale verifier, or an environment mismatch.

Avoid unsafe emergency fixes

Do not skip signature verification, accept unexpected algorithms, or fallback to a hard-coded key just to clear the error. Those changes can turn an availability incident into an authorization vulnerability. Prefer a controlled cache purge, key republish, or verifier config fix.

  • Keep RS256 and HS256 verifier configuration separate
  • Do not trust decoded claims until the signature verifies
  • Use synthetic tokens for tickets and documentation
  • Log key IDs and issuer names, not full bearer tokens

A Flashman workflow

Use the JWT tool to inspect the header and claims of a test token, format the JWKS JSON to find the matching key, and diff the old and new issuer metadata. Convert Unix timestamps when comparing exp, iat, and rotation events with deployment logs.

All inspection can stay in the browser. Redact tokens before sharing screenshots, and keep production bearer tokens out of chat, issue trackers, and long-lived log storage.

Try these tools