Skip to main content

Sessions and tokens

A Ward session is two credentials that answer different questions.

Access tokenRefresh token
FormEdDSA-signed JWT32 random bytes, opaque
Stored by Wardnoyes — sha256(token), one row
Lifetime15 minutes30 days, absolute from login
Cookieward_session, Path=/ward-apiward_refresh, Path=/ward-api/refresh
Answers"is this signature genuine?""may this session continue?"
Read byWard's own pages (GET /session, /account/*)/refresh, /refresh/logout and the OIDC login step

Keeping them apart is the whole design. Signature validity is cheap; session liveness is a question only the database can answer. Neither cookie ever reaches an app: an app holds its own session, and learns whether the Ward session behind it is still live from POST /session-status, which asks about the refresh family (ward_sid). See Sign in with Ward.

The access cookie moved on 2026-10-13

Until 2026-10-13 the access cookie sat at Path=/ so that every app received it. It now sits at Path=/ward-api. Every response that sets or clears the session also expires any old Path=/ copy, and Ward's readers try every ward_session value a browser sends and use the first that is a live session.

Signing in​

The person is handed to Ward and back through an OpenID Connect code flow; the app makes its own session from the ID token, and asks Ward about it at most every 30 seconds — open full screen, where search, tracing and the guided views are usable.

An app sends the person to Ward's authorization endpoint. Ward's login step reads the refresh cookie: a live Ward session finishes at once, otherwise the person signs in on /ward/login?oidc=<uid>, which is an ordinary POST /login that starts a refresh family. The app exchanges the code for an ID token carrying the subject, ward_role and ward_sid, and from then on its own session cookie carries the person.

/ward/login used without an OpenID Connect interaction is for Ward's own pages, and its ?next= is allowlisted to paths under /ward.

Every refresh spends one token and mints its successor in the same family. A family is the unit of revocation: the sid claim in the access token and the ward_sid claim in an app's ID token both name it, so revoking a family ends the access tokens and the app sessions that belong to it and nothing else.

The two red states are both lost claims. What separates them is whether the family's live tip is a fresh successor of the token just presented — open full screen, where search, tracing and the guided views are usable.

Why the claim must stay one statement​

The single-use guarantee is the WHERE used_at IS NULL inside the UPDATE, not anything in the surrounding code:

UPDATE refresh_tokens
SET used_at = ...
WHERE token_hash = ? AND used_at IS NULL
RETURNING *

Two concurrent presentations of the same token both run it, exactly one matches a row, and the loser gets nothing back and is reported as a replay. Split into a SELECT then an UPDATE and there is a window where both callers see an unspent token and both succeed — which is precisely the case reuse detection exists to catch. The decomposition does not merely look untidy; it disables the alarm.

better-sqlite3 being synchronous does not save a split statement

The two halves would be two separate synchronous calls, and await-free code still interleaves across requests at every I/O boundary between them.

Why the whole family dies​

The legitimate client and the thief both hold descendants of one root, and nothing anywhere distinguishes them — whoever presented the stale token might be the victim replaying after a lost response, or the thief using a copy. Revoking only the presented token leaves the other party holding a live one, which is the wrong half in exactly the case that matters.

So the family dies, both parties re-authenticate, and only the one who knows the password gets back in. That is the entire value of the mechanism.

The case that is not theft​

"Nothing distinguishes them" turned out to be too strong. Two tabs of one app firing /refresh at the same instant present the same token; one wins the claim and one loses it. The loser used to burn the family down microseconds after the winner had already written the successor into the cookie jar.

It was reproduced: two concurrent refreshes returning 200 and 401, and zero live tokens left for the subject. The 200 had set cookies for a successor that was revoked immediately afterwards, so the client believed it held a fresh 30-day credential and was dead on its next refresh.

The alarm now asks one question before revoking anything: is the family's live tip the direct successor of the token just presented, and was it issued within the grace window? If so it is a race — the family is left alone and a session.refresh_raced row is written. If not — no live tip, or a tip from a later rotation, or one older than the grace window — it is a replay and the family dies.

The 30 days are absolute​

A family expires 30 days from login, not from the most recent rotation.

A sliding window would make a family immortal for as long as anyone keeps rotating it — including a thief who rotates quietly and never triggers the alarm. The alarm only fires when the victim returns, and a victim who has stopped using the app never does. An absolute lifetime puts a hard ceiling on that.

Logout revokes; it does not delete​

POST /logout marks the family revoked. The rows stay. Deleting them would destroy the evidence that the session ever existed, which matters for the audit log, and would make a subsequent replay indistinguishable from an unknown token rather than from a revoked one.