Token Revocation List
Keep a bounded revocation list of jti values to force logout before expiry, prune expired entries, and check it on every verify without a session table.
On this page
Introduction
This guide covers a bounded token revocation list, a recurring concern in the auth-jwt scenario. Stateless JWTs cannot be recalled, so a forced logout before expiry needs a revocation list of jti values. The list is bounded by the token lifetime, since expired tokens are already dead, and a bloom filter or a small cache keeps the check cheap on every request.
Revoke by jti
Every token carries a unique jti, so revoking that id forces logout for that one token without touching others, which is the granularity you want.
The trade-off worth naming is that every token carries a unique jti, so revoking that id forces logout for that one token without touching others, which is the granularity you want adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
async function revoke(jti, exp) {
await redis.set('rev:' + jti, '1', 'EX', Math.max(0, exp - Date.now()/1000));
}
Check on verify
After signature and expiry pass, look up the jti in the revocation store and reject if present, so a revoked token is dead even before its expiry.
The trade-off worth naming is that after signature and expiry pass, look up the jti in the revocation store and reject if present, so a revoked token is dead even before its expiry adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
async function verify(t) {
const claims = await jwtVerify(t, secret);
if (await redis.get('rev:' + claims.jti)) throw new Error('revoked');
return claims;
}
Prune by expiry
Set a TTL on each revocation entry equal to the remaining token lifetime, so the store self-prunes and stays bounded by the expiry window.
The trade-off worth naming is that set a ttl on each revocation entry equal to the remaining token lifetime, so the store self-prunes and stays bounded by the expiry window adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Bloom for scale
If the list is hot, front it with a bloom filter so the common case is a constant-time no, and only confirm positives against the store, which keeps verify cheap.
The trade-off worth naming is that if the list is hot, front it with a bloom filter so the common case is a constant-time no, and only confirm positives against the store, which keeps verify cheap adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Cascade on family
On reuse detection, revoke every jti in the family at once, which is how rotation and revocation compose to handle theft.
The trade-off worth naming is that on reuse detection, revoke every jti in the family at once, which is how rotation and revocation compose to handle theft adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Test revoke and prune
Revoke a token, assert verify rejects it, wait past expiry, and assert the entry is gone, so the list is correct and bounded.
The trade-off worth naming is that revoke a token, assert verify rejects it, wait past expiry, and assert the entry is gone, so the list is correct and bounded adds a measurable step to the hot path, so measure it before assuming it is free. A reasonable approach is to validate once at the edge, fail closed with a structured error, and log the rejection reason so a spike in bad input is visible on a dashboard rather than silent. Pair the implementation with a test that asserts a valid payload passes and at least one representative violation is rejected with the expected message; this is the cheapest way to keep the guarantee honest as the schema evolves.
Sources
Sources: JWT RFC 7519, Bloom filter.
FAQ
- Does a revocation list undo stateless?
- Only partially; the list is bounded by the token lifetime and pruned constantly, so it is a small cache, not a full session table that grows with active users.
- Bloom filter or a set?
- A bloom filter is smaller and constant-time but has false positives, so use it only to deny, with a fallback set for confirmation if a positive matters; for small lists a plain set is simpler.
Report a problem with this articleOpens a pre-filled issue on GitHub.