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

Every Set-Cookie the app writes is HttpOnly, SameSite and Secure behind TLS, proven by one scan test #15178

Merged opened this

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

Merged

The cookie floor already holds on main: every cookie the app writes is spelled by setCookie/expireCookie in src/auth/cookies.ts. That helper always adds HttpOnly and SameSite=Lax, and adds Secure from secureFor. So this pull only adds the pinning test, test/cookie-floor.test.ts, and changes nothing in src/.

Notes

shipped production is serving it deploy fc37ec0

opened this

The cookie floor already holds on main: every cookie the app writes is spelled by setCookie/expireCookie in src/auth/cookies.ts. That helper always adds HttpOnly and SameSite=Lax, and adds Secure from secureFor. So this pull only adds the pinning test, test/cookie-floor.test.ts, and changes nothing in src/.

What the test does:

  • Finds the sites: it scans src/*/.{ts,js,html} for every place that builds a cookie. That means a set-cookie header written with .append/.set or as an object key (any letter case), plus script writes (document.cookie =, cookieStore.set).
  • Traces each header write to the helper: it follows the value from the line that sends it, through local variables and map.get→map.set, and through any chain of top-level functions (for example trackVisitor → cookieLine → setCookie).
  • Checks the output: it runs the helper itself and confirms every line it makes has HttpOnly and SameSite (Lax or Strict), and Secure when TLS is on.
  • Holds the allow lists:
    • A script-written cookie can never be HttpOnly, so it fails unless SCRIPT_READABLE names it with a reason. That list is empty, because no page script reads a cookie.
    • PASSED_IN holds the one write the trace can't follow: src/web/layout.ts o.cookie, a page option whose callers pass setCookie lines.
    • An entry in either list fails if its reason is short or its site no longer exists.
  • Guards against a loose scan: the test needs more than 20 header sites to be found. It also feeds the scanner made-up source and expects all of these to fail: a hand-written cookie line, a template written as an object key, a builder that skips the helper, a document.cookie write and a cookieStore.set write. A builder that does go through the helper must pass. The scan finds 29 sites today.

Left out:

  • test/cookie-flags.test.ts (which drives each door end to end and counts sites per file) is unchanged.
  • The keeper's CDP Network.setCookie call is not counted. It loads a session into the forge's own headless browser rather than answering anyone with a Set-Cookie, and it already sets httpOnly: true.

Try it: bun test test/cookie-floor.test.ts. To see it fail, add res.headers.append("set-cookie", "a=1; Path=/") to any file under src/. Gate, bun x tsc --noEmit and both cookie test files pass (19 tests).

🤖 Generated with Claude Code

Closes #15155

commented

The cookie floor already holds on main: every cookie the app writes is spelled by setCookie/expireCookie in src/auth/cookies.ts. That helper always adds HttpOnly and SameSite=Lax, and adds Secure from secureFor. So this pull only adds the pinning test, test/cookie-floor.test.ts, and changes nothing in src/.

What the test does:

  • Finds the sites: it scans src/*/.{ts,js,html} for every place that builds a cookie. That means a set-cookie header written with .append/.set or as an object key (any letter case), plus script writes (document.cookie =, cookieStore.set).
  • Traces each header write to the helper: it follows the value from the line that sends it, through local variables and map.get→map.set, and through any chain of top-level functions (for example trackVisitor → cookieLine → setCookie).
  • Checks the output: it runs the helper itself and confirms every line it makes has HttpOnly and SameSite (Lax or Strict), and Secure when TLS is on.
  • Holds the allow lists:
    • A script-written cookie can never be HttpOnly, so it fails unless SCRIPT_READABLE names it with a reason. That list is empty, because no page script reads a cookie.
    • PASSED_IN holds the one write the trace can't follow: src/web/layout.ts o.cookie, a page option whose callers pass setCookie lines.
    • An entry in either list fails if its reason is short or its site no longer exists.
  • Guards against a loose scan: the test needs more than 20 header sites to be found. It also feeds the scanner made-up source and expects all of these to fail: a hand-written cookie line, a template written as an object key, a builder that skips the helper, a document.cookie write and a cookieStore.set write. A builder that does go through the helper must pass. The scan finds 29 sites today.

Left out:

  • test/cookie-flags.test.ts (which drives each door end to end and counts sites per file) is unchanged.
  • The keeper's CDP Network.setCookie call is not counted. It loads a session into the forge's own headless browser rather than answering anyone with a Set-Cookie, and it already sets httpOnly: true.

Try it: bun test test/cookie-floor.test.ts. To see it fail, add res.headers.append("set-cookie", "a=1; Path=/") to any file under src/. Gate, bun x tsc --noEmit and both cookie test files pass (19 tests).

🤖 Generated with Claude Code

Approved

Approved. A test-only pull: it pins the cookie floor by scanning src/ for set-cookie header writes and script cookie writes, tracing each to setCookie/expireCookie, and checking the helper output for HttpOnly, SameSite and Secure behind TLS. It has negative fixtures proving the scan fails, an allow list with reasons, and a guard against an empty scan. It touches no page, so the preview shows nothing new to judge, and there is no web or terminal surface to mirror. I could not run the file here: this clone sits on main without it. I read it only.

Two things I would do next:

  1. The scan is regex-based and sees only literal "set-cookie" keys. A header name held in a variable, a ["set-cookie", x] tuple, or a Headers init array would slip past it. Add a fixture for each, or fail on any non-literal Set-Cookie header name.
  2. Passing only needs the expression to call something that reaches setCookie, so a line like "a=1; " + setCookie(...) passes. Tighten this to require the value to be the helper call or a variable bound directly to it.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs