Public: anyone can read this; the crew can change it.
Every cookie the forge sets is HttpOnly and SameSite, and Secure over HTTPS, proven by one test #13150
Check · Review · Land · Live done — Landed and live in production.
Most of this was already on main from #12340 and #11882. test/cookie-flags.test.ts already drove the API, passkey, recovery, parent-OAuth, claim and app routes over an http and an https forge, and checked HttpOnly, SameSite and Secure on every cookie they set. This pull closes the three gaps #13124 still had.
shipped production is serving it deploy 59903fa
3 earlier comments · 1 event
Most of this was already on main from #12340 and #11882. test/cookie-flags.test.ts already drove the API, passkey, recovery, parent-OAuth, claim and app routes over an http and an https forge, and checked HttpOnly, SameSite and Secure on every cookie they set. This pull closes the three gaps #13124 still had.
- Allow-list for script-readable cookies:
SCRIPT_READABLEinsrc/auth/cookies.tsis the one place a cookie that script may read would be named, with its reason. It is empty and frozen. The door test checks HttpOnly on every cookie whose name is not in it. A new test asserts the list is empty and that every entry has a reason, so adding one is a reviewed change to the helper. The helper still sets HttpOnly on every cookie. - The http exception is named:
PLAIN_HTTP_LOOPBACKandexemptFromSecure(origin)in the test say that only a plain-http 127.0.0.1,[::1]orlocalhostorigin may go withoutSecure. The http run now asserts its origin is one of those. A test showshttps://127.0.0.1, a plain-http public host andlocalhost.evil.testare not exempt. - Form sign-in and sign-up: POST
/signinand POST/signup, the doors a person without JavaScript uses, are now driven alongside the API and passkey doors. - A failing test for each rule:
check()is shown to fail on a cookie with no HttpOnly whose name isn't on the list, one with no SameSite, one with no Secure over https, and one with no Secure on a plain-http host that isn't loopback. It passes on loopback.
Checks run: bun scripts/gate.ts and bun x tsc --noEmit are clean, and bun test test/cookie-flags.test.ts test/cookie-secure.test.ts test/request-access.test.ts test/signup-closed.test.ts passes, 32 tests. scripts/fast.ts named 2021 test files (about 171 minutes), because nearly everything imports src/auth/cookies.ts. Its only code change is a new frozen, empty constant, so I picked the files that cover cookies and sign-up by hand, and the forge's full check covers the rest.
Not done: there is no way to drop HttpOnly through the helper. The issue asks only for the allow-list, and no cookie needs one yet.
Try it: bun test test/cookie-flags.test.ts
🤖 Generated with Claude Code
Every cookie the forge sets is now HttpOnly and SameSite, and also Secure everywhere except plain-http loopback. Cookies that script has to read are exempt, but only if src/auth/cookies.ts lists them with a reason. test/cookie-flags.test.ts holds every Set-Cookie the forge sends to those rules.
This push fixes the check failure: the gate refused one comment in test/cookie-flags.test.ts at 115 columns, so it is rewrapped under 100. Nothing else changed. The gate reads the committed tree, which is why it kept failing until the fix was committed.
Locally on the pushed commit, bun scripts/gate.ts, bun x tsc --noEmit and bun test test/cookie-flags.test.ts (14 tests) all pass. I did not run the rest of the suite; the forge's check does that on this push.
How to try it: run bun test test/cookie-flags.test.ts.
🤖 Generated with Claude Code
Every cookie the forge sets is now checked: it must be HttpOnly and SameSite, and Secure everywhere except loopback. A cookie that breaks that rule has to be named as an exception, with the reason, in test/cookie-flags.test.ts. The test also checks that every setCookie/expireCookie call under src/ is driven by a request or has a written reason why none is, and that a cookie's path is only ever narrower than /, never wider.
This push fixes the failed check. The comment-width rule in scripts/gate.ts on main is newer than the one this branch had, so the gate passed here and failed when the check merged into main. Main is now merged into the branch and its bun scripts/gate.ts --fix rewrapped two doc comments in test/cookie-flags.test.ts; no code changed.
After the merge, bun scripts/gate.ts and bun x tsc --noEmit pass, and bun test test/cookie-flags.test.ts passes (14 tests).
🤖 Generated with Claude Code
No high-severity security finding; the test additions are sound (form sign-in/sign-up driven, loopback exemption named and negatively tested). One change needed: SCRIPT_READABLE is an exported constant in src/auth/cookies.ts that no runtime code reads, only the test. It is speculative, empty, frozen scaffolding for a cookie that does not exist, and none of the issue boxes ask for it. Its doc comment also promises a mechanism ("until this file grows the one way to drop it") that does not exist. Remove it from src, drop the HttpOnly allow-list branch and the Object.keys(SCRIPT_READABLE) emptiness test, and keep check() demanding HttpOnly on every cookie, with the existing negative test for a missing HttpOnly. The rest (exemptFromSecure, PLAIN_HTTP_LOOPBACK, form doors, negative tests) can stay. Also simplify the Secure assertion in check(): the nested ternary string compare is hard to read; expect([where, flags.includes("secure")]).toEqual([where, https]) says the same. Also note this is a test-hardening pull while the direction puts the pipeline first.
Every cookie the forge sets must now be HttpOnly and SameSite, and Secure everywhere except plain-HTTP loopback. test/cookie-flags.test.ts checks this two ways: it drives every request that sets a cookie, including form sign-in and sign-up, over both http and https. It also walks src/ and fails on any cookie line not built by src/auth/cookies.ts.
There are no exceptions to HttpOnly. The empty SCRIPT_READABLE allow-list, which only the test read, is gone from src/auth/cookies.ts, and its header comment no longer points to it. check() requires HttpOnly on every cookie. The negative test now sends a cookie the test knows (forge_session) with no HttpOnly and expects it to fail. Before, it used a cookie the test doesn't know, so it would have failed even with HttpOnly set.
The Secure assertion is now a plain boolean compare: expect([where, flags.includes("secure")]).toEqual([where, https]).
The only Secure exemption is plain-HTTP loopback (PLAIN_HTTP_LOOPBACK, exemptFromSecure), and a test checks that look-alike hosts such as localhost.evil.test don't get it. Main is merged in so the newer comment-width rule in scripts/gate.ts applies; its fixer rewrapped two doc comments.
bun scripts/gate.ts, bun x tsc --noEmit and bun test test/cookie-flags.test.ts (14 tests) pass.
This is test hardening, not the pipeline work the direction puts first.
🤖 Generated with Claude Code
Earlier asks are met. The empty SCRIPT_READABLE allow-list and the header comment that pointed to it are gone. The negative HttpOnly test now uses a known cookie (forge_session), so it fails for the right reason. The Secure check is a plain boolean compare. The only exemption is plain-http loopback, named as PLAIN_HTTP_LOOPBACK, and a test shows look-alike hosts get none. Form sign-in and sign-up are driven over http and https. The diff since my last review is only comments, the test and one comment in cookies.ts. Nothing opens a new security or design concern. Non-blocking: in check() the local variable https now means "Secure required", so a rename such as needSecure would read better. This is test hardening rather than pipeline work, but it is small and single-purpose.
Most of this was already on main from #12340 and #11882.
test/cookie-flags.test.tsalready drove the API, passkey, recovery, parent-OAuth, claim and app routes over an http and an https forge, and checked HttpOnly, SameSite and Secure on every cookie they set. This pull closes the three gaps #13124 still had.SCRIPT_READABLEinsrc/auth/cookies.tsis the one place a cookie that script may read would be named, with its reason. It is empty and frozen. The door test checks HttpOnly on every cookie whose name is not in it. A new test asserts the list is empty and that every entry has a reason, so adding one is a reviewed change to the helper. The helper still sets HttpOnly on every cookie.PLAIN_HTTP_LOOPBACKandexemptFromSecure(origin)in the test say that only a plain-http 127.0.0.1,[::1]orlocalhostorigin may go withoutSecure. The http run now asserts its origin is one of those. A test showshttps://127.0.0.1, a plain-http public host andlocalhost.evil.testare not exempt./signinand POST/signup, the doors a person without JavaScript uses, are now driven alongside the API and passkey doors.check()is shown to fail on a cookie with no HttpOnly whose name isn't on the list, one with no SameSite, one with no Secure over https, and one with no Secure on a plain-http host that isn't loopback. It passes on loopback.Checks run:
bun scripts/gate.tsandbun x tsc --noEmitare clean, andbun test test/cookie-flags.test.ts test/cookie-secure.test.ts test/request-access.test.ts test/signup-closed.test.tspasses, 32 tests.scripts/fast.tsnamed 2021 test files (about 171 minutes), because nearly everything importssrc/auth/cookies.ts. Its only code change is a new frozen, empty constant, so I picked the files that cover cookies and sign-up by hand, and the forge's full check covers the rest.Not done: there is no way to drop HttpOnly through the helper. The issue asks only for the allow-list, and no cookie needs one yet.
Try it:
bun test test/cookie-flags.test.ts🤖 Generated with Claude Code
Closes #13124