Stateless Token Revocation: Short-Lived Access Tokens, Redis Blacklists & Bloom Filters
Because JWTs are self-contained and validated statelessly, revoking an access token before its natural expiration requires hybrid revocation architectures: extremely short lifetimes (5–15 min), distributed Redis denylists indexed by JWT ID (jti), user-level token versioning, or probabilistic Bloom filters.
jti: "uuid_99" and 15m expiration. Verified locally with 0 DB latency.SETEX blacklist:uuid_99 900 "revoked". Gateway drops token immediately.Step 1: Auth server embeds a unique UUID ('jti') and a 'ver' (token version) claim in each issued JWT.
If an employee is fired, an account is breached, or a smartphone is lost, an active 24-hour JWT allows unauthorized access until it expires. True statelessness and instant revocation are fundamentally in tension; applications require a performant revocation tier.
The Stolen Wristband Bulletin: A music festival issues printed wristbands valid for 2 hours. If a thief steals a wristband, the security guards keep a small whiteboard of stolen wristband numbers (jti blacklist) at the gate for the remaining 2 hours until the stolen band naturally expires.
[ Client ] ──(Authorization: Bearer <token>)──► [ API Gateway ]
│
├── Step 1: Verify RS256 Signature & Claims (Stateless)
│
├── Step 2: Check Redis Blacklist:
│ EXISTS blacklist:{jti}
│ ├── Found ──► 401 Unauthorized (Revoked Token!)
│ └── Not Found ──►
│
├── Step 3: Check User Token Version:
│ token.ver >= user.min_token_ver
│ ├── False ──► 401 Unauthorized (All Tokens Revoked!)
│ └── True ──► 200 OK (Allowed)CosmosApp gives users a 'Log out of all devices' button. When clicked, CosmosApp increments Alice's token_version counter in Redis and PostgreSQL from 1 to 2. When microservices validate Alice's access token, they verify that the token's ver claim matches or exceeds the user's active version, immediately invalidating all older tokens across all devices.
Step 1: Auth server embeds a unique UUID ('jti') and a 'ver' (token version) claim in each issued JWT.
Step 2: Access token lifetimes are configured to a strict maximum of 15 minutes.
Step 3: To revoke an individual token, its 'jti' is inserted into a Redis set with a TTL equal to the token's remaining lifetime.
Step 4: To revoke all sessions for a user, the user's minimum valid token version is incremented in Redis.
Step 5: API gateways verify the cryptographic signature and then check Redis for 'jti' or token version validity in sub-milliseconds.
Step 6: When the token's original 'exp' timestamp passes, Redis automatically purges the blacklist entry via key expiration.
import Redis from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);
// CosmosApp Hybrid Token Revocation Validator:
export async function isTokenRevoked(jti: string, userId: string, tokenVer: number): Promise<boolean> {
// 1. Check if specific token JTI is blacklisted:
const isBlacklisted = await redis.exists(`revoked_jti:${jti}`);
if (isBlacklisted) return true;
// 2. Check if user performed a global session revocation:
const minVer = await redis.get(`user_min_ver:${userId}`);
if (minVer && tokenVer < parseInt(minVer, 10)) {
return true; // All tokens before this version are revoked
}
return false;
}
export async function revokeIndividualToken(jti: string, remainingSeconds: number) {
// Key auto-deletes when token reaches its natural expiration:
await redis.set(`revoked_jti:${jti}`, '1', 'EX', remainingSeconds);
}- ✕You don't need revocation if you use JWTs (Real-world security compliance requires the ability to instantly terminate compromised user access).
- ✕Blacklists in Redis grow infinitely large (Blacklist entries only need a TTL matching the token's remaining lifetime, after which they expire automatically).
Key Architectural Takeaways
- ✓Keep access token lifetimes short (10–15 minutes) to minimize the active revocation window.
- ✓Use 'jti' blacklist entries in Redis configured with automatic TTL expiration.
- ✓Use user-level 'token_version' or 'issued_at' timestamps for instant multi-device account logouts.
Issuing 7-day access tokens statelessly without any revocation mechanism.
Issue 15-minute access tokens paired with rotating refresh tokens and a Redis-backed 'jti' denylist.
Why is the memory footprint of a Redis JWT blacklist bounded and manageable, even for applications with millions of users?