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

Every route that changes state refuses a cross-origin request, proven by one table-driven test over the route table #13500

opened this

Merged 18d 17h ago, live in production

A forged browser POST, PUT, PATCH or DELETE that arrives with no Origin header is now refused when the browser's own Sec-Fetch-Site says another site sent it. Before this change, a signed-in cookie request with no Origin passed every mutating route. Most of #13480 was already on main from #10931.

Notes

opened this

A forged browser POST, PUT, PATCH or DELETE that arrives with no Origin header is now refused when the browser's own Sec-Fetch-Site says another site sent it. Before this change, a signed-in cookie request with no Origin passed every mutating route.

Most of #13480 was already on main from #10931. test/origin-every-mutation.test.ts already walks every mutating route in both routers with a foreign Origin. It requires a 403 and no new events, and checks the refusal came from the origin check. Its EXEMPT list (the bearer-only /mcp and /oauth/userinfo) and UNCALLABLE list are checked against the routers. A new mutating route that isn't listed is walked automatically and fails if it has no check. The missing part was "with none from a browser context".

  • crossOrigin (src/http/context.ts): a request with no Origin and Sec-Fetch-Site of cross-site or same-site is now treated as cross-origin, and the log line records origin: "-". A page can't set that header. same-site is included because apps are served on sibling subdomains of the forge. No Origin with same-origin, none or no Sec-Fetch-Site at all (curl, tools) still passes. A cookie can't be used from a non-browser client unless someone already has it.
  • test/origin-every-mutation.test.ts: the route walk now runs over two forged shapes: a foreign Origin, and no Origin with Sec-Fetch-Site: cross-site. With the fix reverted, the second shape fails on real routes (for example POST /api/v1/user/password answers 401 with no origin check).
  • test/consent-origin.test.ts: unit cases for the four Sec-Fetch-Site values with no Origin.

Not done: a Referer fallback for browsers that send neither Origin nor Sec-Fetch-Site. Every current browser sends Origin on cross-site mutations, so it adds rules without closing a real gap. src/http/respond.ts didn't need changes because the gate already calls crossOrigin.

Tests: scripts/fast.ts named 2216 files as too broad, so I picked the 238 test files that mention crossOrigin, sec-fetch-site or evil.example. All pass. bun x tsc --noEmit is clean, and scripts/gate.ts --fix rewrapped comments in three files, which are included. The extra empty commit is the "Try:" line the pre-push hook asks for.

To try it: signed in, POST /api/v1/user/email/verify with header sec-fetch-site: cross-site and no Origin answers 403 forbidden. With sec-fetch-site: same-origin it is not refused.

🤖 Generated with Claude Code

Closes #13480

commented

A forged browser POST, PUT, PATCH or DELETE that arrives with no Origin header is now refused when the browser's own Sec-Fetch-Site says another site sent it. Before this change, a signed-in cookie request with no Origin passed every mutating route.

Most of #13480 was already on main from #10931. test/origin-every-mutation.test.ts already walks every mutating route in both routers with a foreign Origin. It requires a 403 and no new events, and checks the refusal came from the origin check. Its EXEMPT list (the bearer-only /mcp and /oauth/userinfo) and UNCALLABLE list are checked against the routers. A new mutating route that isn't listed is walked automatically and fails if it has no check. The missing part was "with none from a browser context".

  • crossOrigin (src/http/context.ts): a request with no Origin and Sec-Fetch-Site of cross-site or same-site is now treated as cross-origin, and the log line records origin: "-". A page can't set that header. same-site is included because apps are served on sibling subdomains of the forge. No Origin with same-origin, none or no Sec-Fetch-Site at all (curl, tools) still passes. A cookie can't be used from a non-browser client unless someone already has it.
  • test/origin-every-mutation.test.ts: the route walk now runs over two forged shapes: a foreign Origin, and no Origin with Sec-Fetch-Site: cross-site. With the fix reverted, the second shape fails on real routes (for example POST /api/v1/user/password answers 401 with no origin check).
  • test/consent-origin.test.ts: unit cases for the four Sec-Fetch-Site values with no Origin.

Not done: a Referer fallback for browsers that send neither Origin nor Sec-Fetch-Site. Every current browser sends Origin on cross-site mutations, so it adds rules without closing a real gap. src/http/respond.ts didn't need changes because the gate already calls crossOrigin.

Tests: scripts/fast.ts named 2216 files as too broad, so I picked the 238 test files that mention crossOrigin, sec-fetch-site or evil.example. All pass. bun x tsc --noEmit is clean, and scripts/gate.ts --fix rewrapped comments in three files, which are included. The extra empty commit is the "Try:" line the pre-push hook asks for.

To try it: signed in, POST /api/v1/user/email/verify with header sec-fetch-site: cross-site and no Origin answers 403 forbidden. With sec-fetch-site: same-origin it is not refused.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs