Public: anyone can read this; the crew can change it.

Every Set-Cookie and every error response carries the security floor, proven by one table-driven test #13470

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This adds test/security-floor-kinds.test.ts, one table of response kinds that runs against a forge on plain http and against one declared https. Every row must come back with Content-Security-Policy, X-Content-Type-Options (nosniff) and Referrer-Policy.

Notes

shipped production is serving it deploy 59903fa

opened this

This adds test/security-floor-kinds.test.ts, one table of response kinds that runs against a forge on plain http and against one declared https. Every row must come back with Content-Security-Policy, X-Content-Type-Options (nosniff) and Referrer-Policy. Every Set-Cookie on a row must be HttpOnly and SameSite=Lax or Strict, and also Secure on the https forge.

The rows are:

  • a page, signed out and signed in
  • a 404 page and a 404 from the API
  • API errors: a 401, and a 403 from the origin gate
  • a 201 API sign-in that sets a cookie
  • 303 redirects that set or clear cookies: form sign-in, sign-out and the mode switch
  • a 500 on a page and on the API, caused by making the database throw under the handler
  • a 429 from the API sign-in and from the form sign-in, after the account's sign-in limit is filled

Rows that must set a cookie fail if they set none, so the flag check can't pass on an empty list. Two short extra tests keep the check honest: one fails if the table stops covering a kind the issue names, and one shows the cookie check rejects a cookie missing HttpOnly or Secure.

src/http/respond.ts is unchanged: every row already met the floor, so nothing needed fixing. The existing tests covered most kinds and every cookie, but none sent a real 429 or a cookie-setting redirect over the wire. To prove the new test can fail, I briefly removed Referrer-Policy from securityFloor: every row then failed, naming the missing header. Restoring it made all four tests pass again.

bun x tsc --noEmit and bun scripts/gate.ts --fix are clean, and the new file passes (4 tests, about 2.4 s, no network). I ran only this file, not the full suite. The 500 rows print four "unhandled request error" log lines while the test runs; that's expected.

Not done: the full source walk of every cookie stays in test/cookie-flags.test.ts. This table only checks the cookies its rows actually set.

To try it: bun test test/security-floor-kinds.test.ts

🤖 Generated with Claude Code

Closes #13441

commented

This adds test/security-floor-kinds.test.ts, one table of response kinds that runs against a forge on plain http and against one declared https. Every row must come back with Content-Security-Policy, X-Content-Type-Options (nosniff) and Referrer-Policy. Every Set-Cookie on a row must be HttpOnly and SameSite=Lax or Strict, and also Secure on the https forge.

The rows are:

  • a page, signed out and signed in
  • a 404 page and a 404 from the API
  • API errors: a 401, and a 403 from the origin gate
  • a 201 API sign-in that sets a cookie
  • 303 redirects that set or clear cookies: form sign-in, sign-out and the mode switch
  • a 500 on a page and on the API, caused by making the database throw under the handler
  • a 429 from the API sign-in and from the form sign-in, after the account's sign-in limit is filled

Rows that must set a cookie fail if they set none, so the flag check can't pass on an empty list. Two short extra tests keep the check honest: one fails if the table stops covering a kind the issue names, and one shows the cookie check rejects a cookie missing HttpOnly or Secure.

src/http/respond.ts is unchanged: every row already met the floor, so nothing needed fixing. The existing tests covered most kinds and every cookie, but none sent a real 429 or a cookie-setting redirect over the wire. To prove the new test can fail, I briefly removed Referrer-Policy from securityFloor: every row then failed, naming the missing header. Restoring it made all four tests pass again.

bun x tsc --noEmit and bun scripts/gate.ts --fix are clean, and the new file passes (4 tests, about 2.4 s, no network). I ran only this file, not the full suite. The 500 rows print four "unhandled request error" log lines while the test runs; that's expected.

Not done: the full source walk of every cookie stays in test/cookie-flags.test.ts. This table only checks the cookies its rows actually set.

To try it: bun test test/security-floor-kinds.test.ts

🤖 Generated with Claude Code

Approved

Clean, test-only change: one table-driven file covering page, 404, 401, 403, 429 (API and form), 500 (page and API), 201 and 303 cookie-setting answers, run on plain http and on a forge declared https. It asserts the three floor headers plus HttpOnly, SameSite and Secure-over-https on every cookie, and rows that must set a cookie fail if none arrives. A self-test shows the cookie check rejects a cookie missing a flag. No dependency, no README edit, no secret, nothing built from user text. respond.ts needed no fix because every row already met the floor. Not run here; judged by reading. Full cookie source walk stays in cookie-flags.test.ts.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs