Replaying rotated refresh tokens against a SaaS login flow

After a refresh token was rotated, the old session cookie kept working for 41 minutes. How we found it, a repro, and what the vendor changed.

Published
Reading
12 min
Tags
oauth, sessions, disclosure

We were testing a client’s single sign-on setup and noticed something odd in a HAR file. A browser tab that had been idle over lunch was still loading the dashboard, even though the refresh token behind it had been rotated twice by another tab.

Refresh token rotation is supposed to make a stolen token short-lived. Each refresh returns a new refresh token and the old one stops working. If anyone presents a used token, the server should treat it as theft and kill the whole token family. The vendor’s docs said they did exactly this.

They did, for the refresh token. The session cookie was a separate thing, and nobody had tied the two together.

The setup

The app is a single-page client in front of an API. Login goes through the vendor’s hosted page, which sets two things:

  • __Host-sid, an opaque session cookie the API accepts directly.
  • A refresh token kept in memory by the SPA, used to mint short access tokens.

The SPA refreshes every 10 minutes. The cookie had a Max-Age of 3600.

What we saw

Here is the trimmed timeline from two tabs, A and B, logged in as the same user. Times are minutes after login.

t+00  A  POST /oauth/token  grant=authorization_code       -> 200  rt_1, sid_1
t+10  A  POST /oauth/token  grant=refresh_token rt_1       -> 200  rt_2
t+19  B  POST /oauth/token  grant=refresh_token rt_1       -> 400  invalid_grant
t+19  B  (vendor revokes token family rt_*)
t+20  A  POST /oauth/token  grant=refresh_token rt_2       -> 400  invalid_grant
t+21  A  GET  /api/me       Cookie: __Host-sid=sid_1       -> 200
t+45  A  GET  /api/projects Cookie: __Host-sid=sid_1       -> 200
t+60  A  GET  /api/me       Cookie: __Host-sid=sid_1       -> 401

At t+19 the server did the right thing with the refresh token. Reuse was detected and the family was revoked. But sid_1 kept working until its own expiry. The SPA falls back to cookie auth when the access token is missing, so tab A never noticed.

That gap was 41 minutes in our run. It depends on when the reuse happens relative to the cookie’s Max-Age, so the worst case is close to the full hour.

Reproducing it

You need a captured session cookie and any way to trigger reuse. In practice, an attacker who steals both from a compromised browser can trigger the revocation themselves and keep using the cookie. The legitimate user gets logged out. The attacker does not.

POST /oauth/token HTTP/1.1
Host: auth.vendor.example
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=rt_1&client_id=spa-prod
HTTP/1.1 400 Bad Request
Content-Type: application/json
Cache-Control: no-store

{"error":"invalid_grant","error_description":"refresh token reused; family revoked"}

Then, with the old cookie:

GET /api/me HTTP/1.1
Host: app.vendor.example
Cookie: __Host-sid=s%3A7f3c...e91a
HTTP/1.1 200 OK
Content-Type: application/json

{"id":"usr_0f2a","email":"test-user@client.example","roles":["admin"]}

We scripted this with curl and ran it 20 times across different reuse offsets. Every run left the cookie valid until its expiry.

Why it happened

The session store and the token store were two services. The token service published a family.revoked event. The session service subscribed to user.logout and user.password_changed, but not to family.revoked. Nothing in either codebase was wrong in isolation.

What the vendor changed

We reported it on 2026-09-30. The vendor acknowledged it in two days and shipped a fix in 19:

  • The session service now subscribes to family.revoked and deletes every session minted from that family.
  • Sessions carry the token family ID, so the lookup is one indexed query.
  • Cookie Max-Age dropped from 3600 to 900.

We retested on 2026-11-04. After reuse, sid_1 returned 401 within about two seconds, which matches their event bus latency.

If you run something similar

Check every credential that a login produces, not just the one your rotation logic covers. Write down what revokes each one, then test that revoking one revokes the rest. Our test is a 40-line script, and it would have caught this before a customer did.