Yellow Theme

Next start · November 2026

Notes / Engineering note

How we deliver · methodology

2026-09-15

An HttpOnly cookie cannot help if the API returns the refresh token

Keep refresh tokens behind the server boundary. If the session endpoint echoes one into JSON, browser script—and any successful XSS—can still steal the long-lived credential and own the session.

Thesis: An HttpOnly cookie only hides what never returns to script. If a session endpoint reads the cookie and echoes the refresh token in the body, XSS that can call that endpoint still owns the session.

What we checked

The browser stopped writing tokens into sessionStorage on the happy path. Refresh lived in an HttpOnly cookie. A hard reload called GET /auth/session with credentials included. The green path restored the user.

The response body still included refresh_token. Script that could issue that fetch recovered the long-lived credential. Scoping the cookie to the apex domain widened who might send it. A legacy storage branch waited if the cookie path was ever turned off.

Stakes: one XSS that can call the session endpoint turns a “cookie-only” story into a stolen refresh — the attacker renews access after you thought the browser was locked down.

The working shape

Keep refresh on the server side of the cookie jar. Exchange it for short-lived access and id tokens without putting refresh in JSON. Prefer a host-only cookie. Delete the storage fallback on the production path.

# Wrong green: cookie is HttpOnly, JSON still leaks refresh
GET /auth/session  →  { "tokens": { "refresh_token": "…" } }

# Working shape: cookie stays opaque to JS
POST /auth/session/refresh  →  { "tokens": { "access_token": "…", "id_token": "…" } }
# refresh_token never leaves the HttpOnly cookie

Checklist

Try the lab

Curl the session, see what XSS can still steal, patch the BFF, prove refresh never returns in JSON. New here? help. Stuck? help next.

Full page: Open this lab · All labs

Next in this series: the password form is ours · hosted login cannot carry the full legal footer. How we deliver: methodology.

Engineering commentary only — not audit, legal, or certification advice.