Srikanth Bandaru

Your auth token is a cache

You’ve banned a user, so why do her requests still work?

Contents3 sections
  1. The token is a cache
  2. Which way does each scheme fail?
  3. Picking a scheme

Mallory is scraping your API at 1 request a second and you have to ban her. Her client holds a JWT, a signed token saying who she is and when it expires. It has 11 minutes left. To ban her, you add her token’s ID (the token’s jti field) to a denylist that every API server checks. The list is written in us-east and copied to eu-west, where Mallory’s requests land.

How many of Mallory’s requests get through after the ban?

Model: assumed network numbers, 1 request/s

Your guess

Where the ban travels

  1. us-east denylistban written at 0 sthe ban is here
  2. eu-west replicathe region’s copythe ban is here
  3. eu-west servereach request checks thisthe ban is here

Mallory’s requests after the ban

Healthy link

Her requests appear here, 1 tick per second.

Link cut. The check times out and lets her through.

Opens after the first ban.

No ban yet. Mallory’s token has 11 minutes left.

The 3 s replication lag, the 30 s refresh interval and the 1 request per second are the model’s assumptions, not measurements.

She got 23 requests in! The new entry took 3 seconds to cross to eu-west, and it was 20 more before that server refreshed its copy. Every server checked the denylist, but each one checked its own copy.

Now cut the link between regions. The check times out and fails open, which means it lets the request through. You set it that way on purpose, because a denylist outage shouldn’t log everyone out. So Mallory gets all 660 requests her token has left, as if there were no denylist.

The token is a cache

What you just watched is a stale cache. The token is a saved copy of the server’s decision to let her in, and the ban is a write to the origin that hasn’t reached the copy yet. A JWT carries that copy inside each request, and its TTL (time to live) is its expiry minus its issue time. A session ID is only a key. The decision stays in a session store.

I did not come up with this. joepie91 said it in 2016 and Thomas Ptacek in 2021. Each common fix is a cache pattern with a known way to fail.

Scheme Cache pattern Fails when
Session lookup on every request No cache Every request pays a store read, and a network split locks everyone out
Short-lived token, renewed often Short TTL, then ask the origin again You need revocation faster than the TTL
Token plus a per-user “valid after” time Version check You need to kill 1 leaked token and keep the others
Token plus jti denylist Negative cache (a cache of “no” answers) Entries are evicted early, or lag lets a banned user through
Long token plus pushed revocations Long TTL plus purge (copies deleted on demand) A holder misses an event

Which way does each scheme fail?

Here is the ban against 4 schemes, with fail-open checks. “Other users” means everyone else on eu-west.

Scheme Mallory, healthy link Other users, link cut
Token only 660 Served
Token + denylist 23 Served
Session lookup 0 All rejected
Long token + push 3 Served

Session lookup scores 0, but it pays with a read to the store in us-east on every request. Long token plus push lets 3 through, because the model assumes a push takes 3 seconds to arrive.

Now cut the link. Every scheme except session lookup lets Mallory use her whole token. And guess what? Session lookup, the one that scored 0, stops her by rejecting everyone on eu-west, since a session ID carries nothing to fall back on.

Working through a network split is the main benefit of a stateless token. Add a revocation check and you have given that benefit away.

A session store is an allowlist, so a request passes only if its session is found. A denylist is the reverse. A session that hasn’t replicated yet gives a real user a 401. They have to sign in again, and some will write to support. A ban that has not replicated yet gives Mallory a 200, and nothing tells you.

A full cache drops old entries. When the entry it drops is a session, someone gets logged out. But if it is Mallory’s denylist entry, her token works again! So keep each denylist entry until its token expires.

Picking a scheme

Entra ID, Microsoft’s identity service, lets its tokens last up to 28 hours! It can afford that because it pushes revocation events to its own services, and it can list every one of them. That is a long TTL plus purge. Do the same for the holders you can list, and keep TTLs short for the rest.

Most reads can live with 30 seconds of staleness, so a token plus a denylist is fine. Privileged writes and payments can’t, and they are rare enough to afford a session lookup. Mallory’s scraper still gets its 23 reads, but her first privileged write hits the store, which already says no.