Token Revocation Strategies
What you'll learn: How to revoke stateless JWTs before they naturally expire, balancing security needs with the benefits of token-based authentication.
The Token Revocation Challenge
JWTs are self-contained and stateless—once issued, they remain valid until expiration. But what happens when you need to immediately invalidate a token? Perhaps a user logs out, changes their password, or their account is compromised. Unlike sessions stored in a database that you can simply delete, you can't "recall" a JWT that's already in the wild.
Revocation Approaches
1. Token Blacklist
Maintain a list of revoked tokens (by their unique jti claim). Before accepting any token, check if it's on the blacklist. This reintroduces statefulness but provides immediate revocation. The blacklist only needs to retain entries until tokens naturally expire.
2. Short TTLs Issue tokens that expire quickly (e.g., 5-15 minutes). Pair them with long-lived refresh tokens stored securely. Even if you can't revoke the access token immediately, the damage window is minimal. Revoke the refresh token to prevent getting new access tokens.
3. Token Versioning Include a version number in the token claims that matches a version stored in your user database. When revoking, increment the user's version. Reject any token with an outdated version. This requires one database lookup per request—a hybrid approach.
4. Hybrid Lookup Tables Store minimal token metadata (user ID, issued timestamp) in a fast cache like Redis. Check token validity against this cache while keeping most verification stateless. Provides revocation capability with better performance than full session storage.
Think of it like concert tickets: printed tickets can't be "recalled," but you can maintain a "do not admit" list at the door, print tickets that expire quickly, or add a hologram version number that changes when someone's banned.
Key Takeaway: Token revocation requires reintroducing some state—choose between blacklists for precision, short TTLs for simplicity, versioning for user-level control, or hybrid approaches that balance statelessness with security needs.