
19 October 2026 · 2 min read
A Token Fallback That Came With an Expiry Date
Tightening JWT verification has an awkward deploy problem: every token already in someone's browser was signed before the new rules existed. This site pinned verification to HS256, the dev-hub issuer and a per-type audience (dev-hub:access / dev-hub:refresh). Tokens signed earlier carry neither claim, so the strict check would have rejected all of them at once.
The shim#
The compromise was a small branch in verifyToken(): if a token has a valid signature but no iss and no aud, accept it, but only until a fixed date. Everything else goes through the strict path. The cutoff was not arbitrary. The longest-lived token before the change was a 7-day refresh token, so a week after deploy every token in circulation would carry both claims and the branch would be dead code that only weakens verification.
Making sure it dies#
A compatibility shim with no exit is just a permanent hole with a comment on it. This one got three anchors:
- a constant,
LEGACY_TOKENS_ACCEPTED_UNTIL, holding the date in code, not in my head; - a
TODOwith the same date right next to the branch; - an issue with acceptance criteria, including a line that says "do not start before" the cutoff.
Two unit tests used fake timers to prove behaviour on both sides of the date: accepted before, rejected after.
Removing it#
I did the removal five days after the cutoff, not on it. The change itself was small: delete the constant and the legacy branch, hand the verification options (algorithm, issuer, audience) straight to jwtVerify, and replace the two time-travel tests with one plain assertion that a token without iss/aud is rejected. The note in SECURITY.md that described the temporary acceptance now says the fallback is gone.
The one thing code can't check#
The last acceptance criterion is a manual one: after the deploy, log in and confirm refresh still works. Tests prove that the right tokens verify; only a real login proves that nothing in production still depends on the old shape.
The lesson I keep is boring and useful: when a shim is the price of a safe rollout, write down its removal at the same moment you write the shim.