# JWT Token Lifecycle and Revocation > The structural weakness of stateless JWTs: a signed token is valid until it expires regardless of logout, password reset, or theft — so lifetime, storage, and revocation design decide the blast radius. ## The core problem A JWT is a bearer token (RFC 6750): possession is the whole proof, and a resource server that verifies a signature and `exp` asks the auth server nothing. So the server has nothing to "forget" on logout. Deleting the client's copy, ending the auth-server session, or resetting the password does not reach a token already issued — it keeps working until `exp`. With a 24h token, a secret copied at 09:00 and noticed at 09:05 still works until ~08:55 next day. The right question is not "does logout work?" but "how long can a token I no longer trust keep working?" ## Expiration and refresh - **Short access tokens** (5–15 min) cap the window; Keycloak defaults access tokens to 5 minutes. The cost is refresh traffic: a 15-min token = 96 refreshes/user/day (~111 req/s at 100k always-on users). - **Absolute vs sliding expiry**: absolute ends the session at a fixed point; sliding extends on activity but needs an upper bound (Keycloak: `SSO Session Idle` sliding window, `SSO Session Max` absolute ceiling; refresh-token life is derived from the session, there is no standalone refresh-lifetime knob). - **Refresh-token rotation (RFC 9700 §4.14.2)**: each use returns a new refresh token and invalidates the old one. Seeing an invalidated refresh token return means two parties hold the family — revoke the whole family and force re-auth. This gives theft detection "for free". Rotation is a realm-level control in Keycloak (Realm settings > Tokens), not per-client Advanced. - **Failure to invalidate on reset**: JWT Auth WordPress plugin ≤ 3.0.2 (CVE-2026-106466) kept refresh tokens valid after password reset or device removal, so a previously stolen refresh token still minted access tokens. ## Revocation faster than expiry Three ways, each reintroducing some state (the line from "no state, slow revocation" to "some state, fast revocation"): - **Denylist of `jti`** until its `exp` passes, checked in a fast cache; stays small because access tokens are short-lived. - **Per-user token version / `nbf` timestamp**: store a counter or timestamp on the user, embed/compare against `iat`, bump on "log out everywhere" / password reset to invalidate all outstanding tokens at once. - **Opaque tokens + introspection (RFC 7662)**: random string, resource server asks the auth server if it is active — instant revocation, but restores the lookup JWTs removed. `scip.ch` notes revocation is the inherent JWT trade-off; many teams use opaque access tokens externally and JWTs internally. ## Theft, storage and binding - **Stolen tokens**: the signature proves genuineness, not that the sender is the subject. A copy replays exactly. Vectors: token in URL (leaks via logs/history/Referer), XSS reading `localStorage`, MITM on plaintext, device malware, debug logs/crash reports/support tickets. - **Storage**: `localStorage` is XSS-reachable — "sign in once, get hacked everywhere" across micro-frontends sharing a token. Prefer access token in memory + refresh token in `HttpOnly`, `Secure`, `SameSite` cookie. Never read/trust claims client-side for access control, and never paste real tokens into third-party decoder sites. - **Reducing reuse**: short expiry + rotation; sender-constrained tokens (DPoP / mTLS) bind the token to a client key; IP binding helps against a remote thief but logs out roaming users and misses same-device XSS/malware — use coarse signals (country/ASN) as a risk cue rather than hard logout. - **AI agents** are now heavy bearer-token holders (MCP authorization builds on OAuth); an agent-reachable token sits where injection or tool misuse can exfiltrate it, sharpening the lifetime argument. ## Operational pitfalls - A signing key regenerated per process start (`os.urandom(32)` each boot) invalidates every session on restart — logs everyone out. - **Key rotation with JWKS**: publish the new key before signing with it and keep the old key until its tokens expire — that overlap is why `kid` exists; verifiers cache the set and refresh once on an unknown `kid` ([[raw/medium.com/jwks-and-kid-explained-how-to-find-the-key-that-signed-your-token-and-15966|JWKS and kid]]). - **Rotation after compromise** must also invalidate live sessions: Intel/CBSE rotated a cracked HS256 key and killed all active sessions so old forged tokens stopped working ([[raw/infosecwriteups.com/intel-inside-how-a-cracked-jwt-key-led-to-full-account-takeover-15877|Intel Inside]]). - Client-side JWT minting leaks the signing secret (see [[JWT Secret Cracking]]). - Simple-JWT-Login WordPress CSRF (plugin action) — token-issuing endpoints need CSRF defence like any state-changing endpoint; see [[Cross-Site Request Forgery]]. ## Defenses (summary) - Short-lived access tokens; rotating, revocable refresh tokens; invalidate refresh tokens on password reset and device removal. - A revocation mechanism sized to what a stolen token can do (denylist, token-version, or introspection). - `HttpOnly`/`Secure`/`SameSite` cookie or in-memory storage; no tokens in URLs; TLS always. - Stable signing keys with rotation; consider sender-constrained tokens for high-value sessions. ## Related - [[JSON Web Tokens]] - [[JWT Claim Validation Failures]] - [[JWT Secret Cracking]] - [[OAuth 2.0 Vulnerabilities]] - [[Session Management]] - [[Cross-Site Request Forgery]] ## Sources - [[raw/medium.com/why-your-logout-button-doesn-t-log-out-a-jwt-15144|Why Your Logout Button Doesn't Log Out a JWT]] - [[raw/medium.com/jwts-don-t-log-users-out-by-magic-14176|JWTs Don't Log Users Out by Magic]] - [[raw/skycloak.io/jwt-token-lifecycle-expiration-refresh-and-revocation-4545|JWT Token Lifecycle: Expiration, Refresh, and Revocation]] - [[raw/medium.com/stolen-access-tokens-stopping-someone-else-from-using-a-token-12589|Stolen Access Tokens: Stopping Someone Else From Using a Token]] - [[raw/github.com/jwt-auth-wordpress-plugin-does-not-invalidate-refresh-tokens-on-passwo-14613|JWT Auth WordPress plugin does not invalidate refresh tokens on password reset (CVE-2026-106466)]] - [[raw/medium.com/stop-storing-jwts-in-localstorage-react-auth-with-refresh-tokens-and-h-12588|Stop Storing JWTs in localStorage: refresh tokens and httpOnly cookies]] - [[raw/medium.com/sign-in-once-get-hacked-everywhere-the-hidden-cost-of-jwts-in-local-st-15444|Sign In Once, Get Hacked Everywhere: JWTs in Local Storage]] - [[raw/scip.ch/these-are-the-security-issues-with-jwt-6974|These are the security issues with JWT]] - [[raw/medium.com/a-signing-key-that-changes-on-every-restart-logs-everyone-out-14187|A Signing Key That Changes on Every Restart Logs Everyone Out]] - [[raw/github.com/simple-jwt-login-wordpress-plugin-csrf-14388|Simple JWT Login WordPress plugin CSRF]] - [[raw/medium.com/securing-the-edge-implementing-jwt-blacklisting-and-resilient-authenti-13491|Securing the Edge: JWT Blacklisting and Resilient Authentication]] - [[raw/medium.com/jwks-and-kid-explained-how-to-find-the-key-that-signed-your-token-and-15966|JWKS and kid Explained: How to Find the Key That Signed Your Token (and Spot a Leaked Private Key)]] - [[raw/infosecwriteups.com/intel-inside-how-a-cracked-jwt-key-led-to-full-account-takeover-15877|Intel Inside: How a Cracked JWT Key led to Full Account Takeover]]