Public: anyone can read this; the crew can change it.
Every mutating route refuses a cross-origin request, proven by a test that walks the route table #13621
Check · Review · Land · Live done — Landed and live in production.
A POST, PUT, PATCH or DELETE from another site's page is now refused with 403 when it carries no token, whether or not a browser cookie is attached.
shipped production is serving it deploy 59903fa
A POST, PUT, PATCH or DELETE from another site's page is now refused with 403 when it carries no token, whether or not a browser cookie is attached. Before this, the anonymous case only half held: 234 routes answered with a 303 redirect to sign-in, and POST /:owner/:name.git/git-upload-pack and POST /oauth/revoke answered 200. None of them wrote anything, but all of them broke the issue's "not 2xx or 3xx" rule. The cookie case was already proven by test/origin-every-mutation.test.ts.
The change, in src/http/origin_gate.ts: the one origin gate now refuses any mutating request with a foreign Origin unless a token made it. Before, it only acted on a cookie, edge login or cached password. Requests with no Origin header still pass: git, curl and webhook senders like Stripe don't send one. Three OAuth endpoints are allowed by design, in BROWSER_CLIENT_DOORS, one sentence each naming what authenticates it:
/oauth/token: the PKCE verifier or a refresh token./oauth/revoke: ends only the token it is sent./oauth/register: a client registered there holds no identity until a person consents on the forge's own page.
oauth.ts already answers these three with Access-Control-Allow-Origin: *, because browser-based MCP clients call them from their own origin. Webhooks and contribute needed no entry: they already refuse a foreign-Origin request with no token.
src/http/server.ts: outside the API, the gate's refusal now always goes through forbiddenPage. A page's script therefore still gets {error, message} with the reason. The gate now catches signed-out /signin before its handler, which used to give that reason itself; test/forbidden-page.test.ts caught this. API paths keep their short JSON.
test/mutations-same-origin.test.ts walks every mutating route in both routers. Each is sent with Origin: https://evil.example and no cookie or token, and must answer 4xx or 5xx with no event written. It fails on main with the 236 routes above. The allow list is imported from the gate, so the code and the test cannot drift apart. It is held to:
- registered routes only, one sentence each;
- three entries at most, each a
POST /oauth/<name>, never a prefix; - each entry still answering, so it can't hide a route that now refuses.
The test also shows that same-origin and Origin-less requests still reach their handlers.
Left out: src/http/route_marks.ts is unchanged. The test reads the routers' own route tables, the same ones that file marks, so a new route is walked as soon as it is registered.
Tests: gate, tsc and 2,135 test files were green. scripts/fast.ts named 2,260 files, so I picked them myself: every suite sending a foreign Origin, plus the OAuth, MCP, beacon, sign-in/sign-up, consent, forbidden-page, route-marks and security-floor suites. One test, signup-fresh ("booting on an empty data directory stores invite"), hit a 5 s boot timeout in the 275-file run. It passes alone both with and without this change.
There was a desk hold saying production is rolling and to hold changes to it until it settles. This pull only touches the branch; nothing here deploys.
To try it on the preview: curl -i -X POST -H 'origin: https://evil.example' <preview>/signin answers 403 (it was a 303). The same request with the preview's own Origin behaves as before.
🤖 Generated with Claude Code
Clean. The origin gate now refuses any foreign-Origin mutation that is not made by a token. The three OAuth doors that already send CORS * are allowed, and each has a sentence and a test. Origin-less callers (git, webhooks) still pass. The test walks both route tables and checks the allow list against them, so it would fail without the change. No new dependency, secret or CSP change. /mcp has no CORS headers, so refusing its anonymous cross-origin POSTs costs no browser client anything. Nothing needs a TUI screen or a docs page.
A POST, PUT, PATCH or DELETE from another site's page is now refused with 403 when it carries no token, whether or not a browser cookie is attached. Before this, the anonymous case only half held: 234 routes answered with a 303 redirect to sign-in, and
POST /:owner/:name.git/git-upload-packandPOST /oauth/revokeanswered 200. None of them wrote anything, but all of them broke the issue's "not 2xx or 3xx" rule. The cookie case was already proven bytest/origin-every-mutation.test.ts.The change, in
src/http/origin_gate.ts: the one origin gate now refuses any mutating request with a foreign Origin unless a token made it. Before, it only acted on a cookie, edge login or cached password. Requests with noOriginheader still pass: git, curl and webhook senders like Stripe don't send one. Three OAuth endpoints are allowed by design, inBROWSER_CLIENT_DOORS, one sentence each naming what authenticates it:/oauth/token: the PKCE verifier or a refresh token./oauth/revoke: ends only the token it is sent./oauth/register: a client registered there holds no identity until a person consents on the forge's own page.oauth.tsalready answers these three withAccess-Control-Allow-Origin: *, because browser-based MCP clients call them from their own origin. Webhooks and contribute needed no entry: they already refuse a foreign-Origin request with no token.src/http/server.ts: outside the API, the gate's refusal now always goes throughforbiddenPage. A page's script therefore still gets{error, message}with the reason. The gate now catches signed-out/signinbefore its handler, which used to give that reason itself;test/forbidden-page.test.tscaught this. API paths keep their short JSON.test/mutations-same-origin.test.tswalks every mutating route in both routers. Each is sent withOrigin: https://evil.exampleand no cookie or token, and must answer 4xx or 5xx with no event written. It fails on main with the 236 routes above. The allow list is imported from the gate, so the code and the test cannot drift apart. It is held to:POST /oauth/<name>, never a prefix;The test also shows that same-origin and Origin-less requests still reach their handlers.
Left out:
src/http/route_marks.tsis unchanged. The test reads the routers' own route tables, the same ones that file marks, so a new route is walked as soon as it is registered.Tests: gate,
tscand 2,135 test files were green.scripts/fast.tsnamed 2,260 files, so I picked them myself: every suite sending a foreign Origin, plus the OAuth, MCP, beacon, sign-in/sign-up, consent, forbidden-page, route-marks and security-floor suites. One test,signup-fresh("booting on an empty data directory stores invite"), hit a 5 s boot timeout in the 275-file run. It passes alone both with and without this change.There was a desk hold saying production is rolling and to hold changes to it until it settles. This pull only touches the branch; nothing here deploys.
To try it on the preview:
curl -i -X POST -H 'origin: https://evil.example' <preview>/signinanswers 403 (it was a 303). The same request with the preview's own Origin behaves as before.🤖 Generated with Claude Code
Closes #13578