Token pitfalls
Step 1 · The pattern
Tokens from the sign-in service open mailboxes
A business user signs in; the sign-in service issues a token signed with its key. The mail API checks the token and opens the mailbox. Nothing is looked up per request. (All numbers are illustrative.)
- a sign-in
- mailbox opened
In short
Token pitfalls: how it works and how it breaks
A signed token (a JWT, say) is only as good as the checks on it. The signature proves that some key the service trusts signed it. It does not prove the token was issued for this service, by the right issuer, with a key allowed to sign this kind of token, or that the key should still be in use. A service that only asks 'is this signed by one of our keys?' accepts tokens minted with a key meant for another system, and an old key never retired keeps that door open. Check the signature with the expected algorithm against the issuer's current keys, then the issuer, the audience, the expiry and what that key may sign. Rotate signing keys automatically, so a lost key stops working by itself, and keep private keys out of crash dumps and logs.
What this simulation simplifies
- The attacker already holds the old key; how keys leak (dumps, logs, backups) is not animated.
- Key rotation is shown as a flag; real rotation overlaps old and new keys for a while.
How this comes up in interviews
"You run several services that accept JWTs. What must each one check?"
Then they ask
- How do you rotate signing keys without downtime?
- What happens if a private key leaks?
- Where do services get the public keys?
A strong answer covers
- Signature with a fixed, expected algorithm and a key from the issuer's current set.
- Issuer, audience, expiry, and the scope each key is allowed to sign.
- Publish keys with ids; rotate automatically, overlapping old and new.
- Keep private keys in an HSM or key service, out of dumps and logs.
- Alert when an unknown or retired key id appears.
Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.
On one page: the track cheat sheet.
Sources: RFC 8725: JSON Web Token Best Current Practices ↗ · Microsoft MSRC: Results of major technical investigations for Storm-0558 key acquisition ↗ · Report a problem
Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.