Authentication is a server-held session (ADR-0575/0576/0577) #920

Merged
nelsong6 merged 9 commits from auth-session-hardening into main 2026-08-11 20:22:10 -07:00
nelsong6 commented 2026-08-11 19:33:23 -07:00 (Migrated from github.com)

Presenting symptom: sessions died on the hour. That turned out to be one of ten findings, recorded
in full in docs/auth-security-audit.md and measured against
RFC 9700 and the BFF pattern in
draft-ietf-oauth-browser-based-apps-26 §6.1.

The hourly sign-out (F1). The authorization request omitted offline_access, so the provider
never returned a refresh token and the refresh path had never once executed in production.
Confirmed against the provider database: 73 of 73 tokens ever issued to this client carry scopes
openid profile email.

The reboot was a red herring (F2). The backend held no session state, so a restart had nothing
to lose. The session owner settled once and never re-read, so the shell presented a signed-in
account over a session that had ended — and a restart forces a reload, which was the only thing
that ever re-asked.

The structure underneath (F3). The access and refresh tokens were the browser's cookies,
which is the inverse of what a BFF does. That one choice produced nothing to revoke, no identity
to cache so every request called the identity provider, a session lifetime that was a cookie's
Max-Age, and a pending sign-in in a process Map.

What changed

  • Migration 77 adds auth_sessions and auth_login_attempts. Only the SHA-256 of a session token
    is stored. Claims are cached on the row, so an ordinary authenticated request is one local read.
  • Three deadlines: idle slides to 30 days, absolute is fixed at 90, authenticated_at is what the
    8-hour admin window reads. Re-authenticating re-arms the row in place — minting a new one would
    reset the absolute clock every 8 hours and the cap would never fire.
  • Confidential client, offline_access, server-side refresh. A refresh refused 4xx ends the
    session; a 5xx is an outage and changes nothing.
  • Sign-out deletes the row and revokes upstream.
  • SameSite=Strict is the named CSRF defence; the login-state cookie stays Lax deliberately.
  • The .tank.dev.romaine.life session bypass is deleted (F7).
  • Admin writes need an authentication under 8 hours old, answered as RFC 9470
    insufficient_user_authentication so the browser can tell a step-up from a sign-out.

Testing

The smoke tests authenticated by handing the backend a cookie containing a token, so the sign-in
path — state binding, PKCE, nonce, one-shot code exchange — was never exercised outside unit tests.
Both now complete the real flow against a mock provider that runs it. The DB-free netplay lane gets
an in-memory store gated on NODE_ENV=test and an explicit opt-in, matching the existing
DB-free lobby seam.

Verified locally: frontend/npm run check green (365 files, 3487 tests), backend auth suites 23/23,
netplay-smoke-test.js green. smoke-test.js needs Postgres and runs here in CI — it matters this
time, because this change carries a schema migration and rewrites how every DB-backed endpoint
authenticates.

Not in this PR

Stage 3, the identity provider migration for F5 and F11, is in romaine-life/auth on
oauth-provider-migration. Its dependency groundwork is landed and verified; the plugin swap is
designed and not written, because it cannot complete a single real login from a machine with no
Postgres, and it lands on the service that gates Grafana and Argo CD. Details in
docs/auth-security-audit.md §6.

Every existing session is invalidated on deploy, and sign-in stays broken until migration 77
rolls out.

Presenting symptom: sessions died on the hour. That turned out to be one of ten findings, recorded in full in [`docs/auth-security-audit.md`](docs/auth-security-audit.md) and measured against [RFC 9700](https://www.rfc-editor.org/info/rfc9700/) and the BFF pattern in draft-ietf-oauth-browser-based-apps-26 §6.1. **The hourly sign-out (F1).** The authorization request omitted `offline_access`, so the provider never returned a refresh token and the refresh path had never once executed in production. Confirmed against the provider database: 73 of 73 tokens ever issued to this client carry scopes `openid profile email`. **The reboot was a red herring (F2).** The backend held no session state, so a restart had nothing to lose. The session owner settled once and never re-read, so the shell presented a signed-in account over a session that had ended — and a restart forces a reload, which was the only thing that ever re-asked. **The structure underneath (F3).** The access and refresh tokens *were* the browser's cookies, which is the inverse of what a BFF does. That one choice produced nothing to revoke, no identity to cache so every request called the identity provider, a session lifetime that was a cookie's `Max-Age`, and a pending sign-in in a process `Map`. ## What changed - Migration 77 adds `auth_sessions` and `auth_login_attempts`. Only the SHA-256 of a session token is stored. Claims are cached on the row, so an ordinary authenticated request is one local read. - Three deadlines: idle slides to 30 days, absolute is fixed at 90, `authenticated_at` is what the 8-hour admin window reads. Re-authenticating re-arms the row in place — minting a new one would reset the absolute clock every 8 hours and the cap would never fire. - Confidential client, `offline_access`, server-side refresh. A refresh refused 4xx ends the session; a 5xx is an outage and changes nothing. - Sign-out deletes the row and revokes upstream. - `SameSite=Strict` is the named CSRF defence; the login-state cookie stays `Lax` deliberately. - The `.tank.dev.romaine.life` session bypass is deleted (F7). - Admin writes need an authentication under 8 hours old, answered as RFC 9470 `insufficient_user_authentication` so the browser can tell a step-up from a sign-out. ## Testing The smoke tests authenticated by handing the backend a cookie containing a token, so the sign-in path — state binding, PKCE, nonce, one-shot code exchange — was never exercised outside unit tests. Both now complete the real flow against a mock provider that runs it. The DB-free netplay lane gets an in-memory store gated on `NODE_ENV=test` **and** an explicit opt-in, matching the existing DB-free lobby seam. Verified locally: `frontend/npm run check` green (365 files, 3487 tests), backend auth suites 23/23, `netplay-smoke-test.js` green. `smoke-test.js` needs Postgres and runs here in CI — it matters this time, because this change carries a schema migration and rewrites how every DB-backed endpoint authenticates. ## Not in this PR Stage 3, the identity provider migration for F5 and F11, is in `romaine-life/auth` on `oauth-provider-migration`. Its dependency groundwork is landed and verified; the plugin swap is designed and not written, because it cannot complete a single real login from a machine with no Postgres, and it lands on the service that gates Grafana and Argo CD. Details in `docs/auth-security-audit.md` §6. **Every existing session is invalidated on deploy**, and sign-in stays broken until migration 77 rolls out.
Sign in to join this conversation.
No description provided.