StoicBuilder

HandbookXIV the VallumTokens and sessions

XIVthe Vallum, Defend it

Tokens and sessions

1 min readUpdated 28 November

In plain words

A server-side session is a sign-in your server remembers and can delete at any time; a JWT is a signed token that carries the sign-in with it, valid until it expires unless you check something revocable.

Where you see it

A Harbor customer reports a stolen laptop and asks you to sign them out everywhere. With sessions in the database you delete their rows and it's done. With 30-day JWTs and nothing else, every copied token keeps working for up to a month.

Harbor's sign-in designserver
Set-Cookie: hb_refresh=<random>; HttpOnly; Secure; SameSite=Lax; Path=/api/auth; Max-Age=1209600 access token JWT, 10 minutes, checked by signaturerefresh token random, 14 days, stored hashed in the database, replaced on every use; reuse of an old one revokes the whole family
Short access tokens keep checks fast. The refresh token is the part you can revoke, and scripts on the page can't read it.

What goes wrong

  1. Long-lived JWTs with no way to revoke them

    A token that lasts 30 days stays valid after a password change, a sign-out or a stolen laptop. Keep access tokens short, and keep the revocable part, a session or refresh token, on the server.

  2. Tokens in localStorage

    Any script running on the page, including injected code or a compromised package, can read localStorage and send the token away. An HttpOnly cookie can't be read by scripts, which limits what an XSS bug can steal.

  3. Letting the token choose how it's checked

    Libraries that trusted the token's own algorithm header have accepted unsigned or wrongly signed tokens in the past. Pin the algorithm, and check issuer, audience and expiry on every request.

    jwt.verify(token, publicKey, { algorithms: ["RS256"], issuer: "https://auth.harbor.example", audience: "harbor-api" });

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Explain how sign-in works in this app today: what token is issued, where the browser keeps it, how long it lasts, and how sign-out and sign-out-everywhere revoke it. Then move it to an HttpOnly, Secure, SameSite cookie, keep access tokens under 15 minutes with rotating refresh tokens stored hashed on the server, and pin the JWT algorithm, issuer and audience when verifying.

Quick check

Sign in to earn +10 XP for it

Harbor issues 30-day JWTs and checks only their signature. A customer changes their password after a phishing scare. What happens to the stolen token?

Got a prompt that touches tokens and sessions?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.