Lion Cipher Lab

Rotate JWT signing keys with a JWKS endpoint

Why it matters

Every modern login hands your app a JWT, and every JWT is trusted only because its signature checks out against a key your app fetched from the identity provider's JWKS endpoint. That one cryptographic key is a single point of failure: if it leaks, an attacker can mint tokens that impersonate anyone until the key is retired. So keys must rotate — on a schedule for hygiene, and immediately on compromise. But you cannot just swap the key, because tokens already signed with the old key are still valid until they expire; yank the key and you log out the entire internet at once. The professional…

What you'll learn

Steps in this lab

  1. The words first: JWT, claims, RS256, kid, JWK, JWKS
  2. Why signing keys must rotate — and why you cannot just swap them
  3. Install the tools and confirm the versions
  4. Open one Python session and set up the helpers
  5. Generate the first key, mint a token, and publish a JWKS file
  6. Verify a token CORRECTLY: select the key by kid, pin the algorithm
  7. Rotate with an overlap window: add kid2, prove BOTH keys work
  8. Retire kid1: prove old tokens now fail and new ones still work
  9. Footgun A: alg:none and the RS256->HS256 confusion attack
  10. Footgun B: expiry must be enforced (and the leeway subtlety)
  11. Optional: serve the JWKS over HTTP like a real IdP
  12. Judgment: when to rotate, how long to overlap, and how a pro consumes a JWKS

Open the full interactive lab →