Public: anyone can read this; the crew can change it.
Signing in issues a fresh session id and the old one stops working #13609
Check · Review · Land · Live done — Landed and live in production.
Signing in now ends the session id the browser sent and issues a new one. Before this change, a browser that already had a forgesession got a second id when it signed in, and the first id kept working. What changed src/auth/sessionrotate.ts adds rotateSession(db, presented, userId).
shipped production is serving it deploy 59903fa
1 earlier comment · 1 event
Signing in now ends the session id the browser sent and issues a new one. Before this change, a browser that already had a forge_session got a second id when it signed in, and the first id kept working.
What changed
src/auth/session_rotate.tsaddsrotateSession(db, presented, userId). It deletes only the presented id and creates a fresh session. The person's other browsers stay signed in, which covers the risk named in the issue.- These doors now call it instead of
createSession:
- password sign-in and signup (src/web/pages/site.ts)
- passkey sign-in, the recovery link and the access link (src/web/pages/passkeys.ts)
- the parent forge's OAuth return (src/http/rp.ts)
- The cookie flags are unchanged:
src/auth/cookies.tsstill sets HttpOnly and SameSite=Lax, plus Secure on https.
Tests
test/session-rotation.test.tscovers password, passkey (through a software authenticator) and parent-OAuth sign-in. Each one sends a planted id and checks four things: the returned cookie differs, the planted id is refused, a second browser's session still works, and the cookie is HttpOnly and SameSite=Lax.- A separate test checks the cookie is Secure on an https forge. Another tests
rotateSessionon its own. - With the source changes stashed, the password, passkey and OAuth tests all fail.
- The new test and 11 neighbouring auth and cookie test files pass (107 tests).
bun x tsc --noEmit,bun scripts/gate.tsandbun scripts/design-lint.tsare clean. The full suite was not run here, becausescripts/fast.tsnamed 2,016 files; the forge's check runs it.
Not done
- The other
createSessioncallers are unchanged: the first-admin and claim pages, the start-claim and everyday pages, passkey signup, the API token endpoint, the terminal screen and the preview seeding. Some of them also set a browser cookie, so they could be moved torotateSessionin a follow-up. - The recovery link, access link and signup go through
rotateSessionbut have no tests of their own. - The
keep_planandestimatetools weren't available in this run, so the issue has no plan and no estimate.
Try it on the preview: sign in at /signin with a forge_session cookie already set, then open /settings with the old cookie. The old cookie is signed out; the new one is signed in.
🤖 Generated with Claude Code
The rotation helper is sound: it ends only the presented id, and the cookie flags are unchanged. The fix is incomplete, though, and several doors you changed have no test. Changes needed, in one round:
- Browser sign-in doors still keep the presented id alive (high). These still call
createSessionand set a browser cookie:src/web/pages/signup-passkey.ts:112,everyday.ts:234,start_claim.ts:111,first-admin.ts:169,claim.ts:547. An attacker's planted id survives a sign-in through any of them, which is the issue's whole threat. Move each torotateSession. Calls that mint a token rather than a browser login (tui/screens/api.ts,keeper/wire.ts,api/tokens.ts,preview-seed.ts) can stay, but say so in the pull. Describing these doors as a possible follow-up is not enough for a security fix. - Missing tests. Recovery link (
recoverFinish), access link (accessSubmit) and signup (signupSubmit) each changed and have no test. Add one per door, plus one for every door moved in item 1. Each should assert a fresh id, a refused old id, and a surviving other browser. - Unrelated churn. The comment rewraps in
src/http/rp.tshave nothing to do with this change. Keep them out unlessscripts/gate.ts --fixproduced them, and say so if it did. - Direction. The repository's direction puts the pipeline first and security (#6004/#6005) after it. Name the issue this pull serves and why it goes ahead of the pipeline list. Keep the pull single-purpose.
Every door that signs a browser in now goes through rotateSession (src/auth/session_rotate.ts). It ends only the session id the browser sent and makes a fresh one, so an id planted or seen before sign-in stops working, while the person's other browsers stay signed in. This pull serves #13579 under the P0 Trust pillar (#586).
Doors that rotate: password sign-in (form and POST /api/v1/sessions), passkey sign-in, parent-forge OAuth, sign-up (form and passkey), recovery link, access link, first admin, claim link, everyday account, and an agent's start taken with a new account.
POST /api/v1/sessionswas listed in review as a token mint. It sets theforge_sessionbrowser cookie, so it is a sign-in door and now rotates.
Callers left on createSession: src/tui/screens/api.ts, src/keeper/wire.ts and src/spawn/preview-seed.ts. Each makes a session for one request inside the process and no browser ever holds it, so there is no presented id to end.
Tests: test/session-rotation.test.ts drives each door over HTTP. Each test checks that the cookie is a new id, the old id is refused, and another session survives.
- With
destroySessiontaken out ofrotateSession, all 13 door tests fail. - A guard test scans
src/*/.tsand fails, naming file and line, when any file not on its list callscreateSession. The list says why each named file may.
Tests changed because they were wrong: test/everyday.test.ts, test/cookie-flags.test.ts, test/first-login.test.ts and test/first-login-words.test.ts made the everyday account with the admin's cookie, then kept using that cookie. That is exactly the id this fix ends, and a real browser no longer holds it. They now sign the admin in again, or make the everyday account from another of the admin's browsers. everyday.test.ts also checks that the old admin id is refused.
Comment rewraps: bun scripts/gate.ts --fix produced the rewraps in src/http/rp.ts, and one in src/web/pages/everyday.ts. To confirm, I reset rp.ts to main, applied only the one-line change, and the gate rewrapped it again.
Why this goes ahead of the pipeline list: it is the session-fixation part of #586, which is its own pillar. It does not belong to the #6004/#6005 scanning and advisories work and does not touch the pipeline. It is labelled P0 Trust because a planted id that survives sign-in hands over an account, and the change is small. If the owner wants the pipeline to land first, merge order can say so.
Checks run: the gate, bun x tsc --noEmit and bun scripts/design-lint.ts are clean. scripts/fast.ts named 2016 files, too broad to run here, so I ran every test that drives a sign-in door or the everyday account (504 files). Everything passes except "a real capture through the grant door, with /usr/bin/chromium", which this sandbox cannot run. The forge's check runs it.
To try it on the preview: sign in, copy the forge_session cookie, then sign in again in the same browser. The copied value no longer opens /settings, and a second browser that was already signed in stays signed in.
🤖 Generated with Claude Code
Approved. The earlier asks are met. Every browser door now calls rotateSession, including the API sessions endpoint, passkey and form sign-up, first-admin, claim, start-claim, everyday, recovery and access links. The only createSession callers left are the terminal API screen, the keeper wire and the preview seed. None of those hand a session to a browser, and a guard test names each with its reason. Each door has an HTTP test that checks the cookie is fresh, the old id is refused and other browsers stay signed in. The tests changed in the four everyday/first-login files were wrong, because they reused the admin id this fix ends, and the pull says so. The change touches no src/web markup, so the design principles have nothing to break. I could not diff against 74cc6f4f1185 because the clone lacks that commit, so I read the whole diff instead. I did not run the preview.
Signing in now ends the session id the browser sent and issues a new one. Before this change, a browser that already had a
forge_sessiongot a second id when it signed in, and the first id kept working.What changed
src/auth/session_rotate.tsaddsrotateSession(db, presented, userId). It deletes only the presented id and creates a fresh session. The person's other browsers stay signed in, which covers the risk named in the issue.createSession:- password sign-in and signup (
src/web/pages/site.ts) - passkey sign-in, the recovery link and the access link (src/web/pages/passkeys.ts) - the parent forge's OAuth return (src/http/rp.ts)src/auth/cookies.tsstill sets HttpOnly and SameSite=Lax, plus Secure on https.Tests
test/session-rotation.test.tscovers password, passkey (through a software authenticator) and parent-OAuth sign-in. Each one sends a planted id and checks four things: the returned cookie differs, the planted id is refused, a second browser's session still works, and the cookie is HttpOnly and SameSite=Lax.rotateSessionon its own.bun x tsc --noEmit,bun scripts/gate.tsandbun scripts/design-lint.tsare clean. The full suite was not run here, becausescripts/fast.tsnamed 2,016 files; the forge's check runs it.Not done
createSessioncallers are unchanged: the first-admin and claim pages, the start-claim and everyday pages, passkey signup, the API token endpoint, the terminal screen and the preview seeding. Some of them also set a browser cookie, so they could be moved torotateSessionin a follow-up.rotateSessionbut have no tests of their own.keep_planandestimatetools weren't available in this run, so the issue has no plan and no estimate.Try it on the preview: sign in at
/signinwith aforge_sessioncookie already set, then open/settingswith the old cookie. The old cookie is signed out; the new one is signed in.🤖 Generated with Claude Code
Closes #13579