Public: anyone can read this; the crew can change it.
Every route that changes state refuses a request from another origin, proven by a test that walks the route table #14494
Check · Review · Land · Live done — Landed and live in production.
All of the cross-origin exemptions now live in one small file, src/http/originexempt.ts. The origin gate and both tests that walk the route table read it, so they can't drift apart. No new route was missing a check, so no route was fixed.
shipped production is serving it deploy bbac9a7
2 earlier comments
All of the cross-origin exemptions now live in one small file, src/http/origin_exempt.ts. The origin gate and both tests that walk the route table read it, so they can't drift apart. No new route was missing a check, so no route was fixed.
Most of #14478 was already on main:
- Test that walks the route table: 7d318b3ac and 20676a0a8 added
test/origin-every-mutation.test.ts. It sends every POST, PUT, PATCH and DELETE in both routers a signed-in request with a foreign Origin, and one with no Origin butSec-Fetch-Site: cross-site. Each must answer 403, write no event and be refused by the origin check itself.test/mutations-same-origin.test.tsdoes the same with no cookie or token. - Exemptions: each route is named exactly, with a reason, and checked against the registered routes. A cookie alone gets 401 or 405 on the bearer-only ones.
The one thing missing was that the exemptions were split between an inline EXEMPT table in the test and BROWSER_CLIENT_DOORS in origin_gate.ts. The new file holds:
BEARER_ONLY_ROUTES:POST /mcp,DELETE /mcpandPOST /oauth/userinfo. They read only a bearer token, never a cookie.BROWSER_CLIENT_DOORS:/oauth/token,/oauth/revokeand/oauth/register. Browser OAuth clients call these from their own origin by design, and PKCE, the token itself or a person's consent authenticates them.
origin_gate.ts now imports the doors from there, and the gate's behaviour is unchanged.
I kept the existing test file names rather than creating the test/same-origin-routes.test.ts the issue suggests, because the two existing tests already cover it. I also didn't record a plan on the issue: the keep_plan tool isn't available in this run.
bun x tsc --noEmit, bun scripts/gate.ts --fix and the tests below pass. scripts/fast.ts named 2181 test files, far over its time budget, so I ran the ones that cover this change myself.
To try it: bun test test/origin-every-mutation.test.ts test/mutations-same-origin.test.ts. Then add a line to src/http/origin_exempt.ts naming a route that doesn't exist and watch it fail.
🤖 Generated with Claude Code
All of the cross-origin exemptions now live in one small file, src/http/origin_exempt.ts, which the origin gate and both route-walking tests read. Before, they were split between an inline EXEMPT table in test/origin-every-mutation.test.ts and BROWSER_CLIENT_DOORS in src/http/origin_gate.ts. The gate behaves exactly as before, and no route was missing a check.
The new file names each exempt route exactly, with what authenticates it instead:
- Bearer-only routes:
POST /mcp,DELETE /mcpandPOST /oauth/userinfo. They read only a bearer token, never a cookie, so a cookie alone gets 401 or 405. - Browser OAuth client routes:
POST /oauth/token,/oauth/revokeand/oauth/register. They are called from other origins by design and are authenticated by PKCE, by the token itself, or by a person's consent on the forge's own page.
The rest of #14478 was already on main in 7d318b3ac and 20676a0a8: test/origin-every-mutation.test.ts sends every POST, PUT, PATCH and DELETE in both routers a forged signed-in request (403, no events written, refused by the origin check). test/mutations-same-origin.test.ts covers the anonymous case. Each exemption is checked against the registered routes. I kept those test file names rather than adding the test/same-origin-routes.test.ts the issue suggests.
The earlier check failed on the gate's "pipeline first" rule. An empty commit now carries a Direction: line naming #14478, because this moves existing lists and touches no pipeline. bun scripts/gate.ts and bun x tsc --noEmit pass, and so do both tests (16 pass, 0 fail).
To try it: run bun test test/origin-every-mutation.test.ts test/mutations-same-origin.test.ts, then add a line to src/http/origin_exempt.ts naming a route that doesn't exist and watch it fail.
🤖 Generated with Claude Code
All of the cross-origin exemptions now live in one small file, src/http/origin_exempt.ts, exported as CROSS_ORIGIN_EXEMPT. Both route-walking tests read it, and originGate reads its browserClientDoors list. The gate behaves exactly as before, and no route was missing a check.
The file names each route exactly, never by pattern, with what authenticates it instead:
bearerOnly:POST /mcp,DELETE /mcpandPOST /oauth/userinfo. They read only a bearer token, so a cookie alone gets 401 or 405.browserClientDoors:/oauth/token,/oauth/revokeand/oauth/register. Browser OAuth clients call these from other origins by design, and PKCE, the token itself, or a person's consent on the forge's own page authenticates them.
The rest of #14478 was already on main in 7d318b3ac and 20676a0a8. test/origin-every-mutation.test.ts covers signed-in forged requests: each must answer 403, write no event, and be refused by the origin check. test/mutations-same-origin.test.ts covers anonymous ones. I kept those file names rather than adding test/same-origin-routes.test.ts.
Changes since the last failed check:
- Dead-code failure:
BEARER_ONLY_ROUTEShad no caller undersrc/. Both lists now hang off the one export the gate uses. - Over-budget anonymous walk: it rebuilt the server and its routers on every request, which took 2.4 s for 692 routes. One server per test file brings that to about 150 ms;
origin-every-mutation.test.tsgets the same fix. - Stricter anonymous check: it now accepts only 403 or 401, as the issue asks, instead of any status of 400 or above. With one shared server, its rate limiter could otherwise let a 429 pass as a refusal; in the run, every route answered 403.
- "Pipeline first" gate rule: satisfied by a
Direction:line naming #14478 in an empty commit, since this touches no pipeline.
bun scripts/gate.ts --fix, bun x tsc --noEmit and five test files pass (29 tests): the two route walks, unused-exports, security-citations, and take-expect. take-expect ("a fast-forward applies the previewed id") passes here; it looks like a flake on the runner, since nothing in it touches this code.
To try it: run bun test test/origin-every-mutation.test.ts test/mutations-same-origin.test.ts, then add an entry to src/http/origin_exempt.ts naming a route that doesn't exist and watch it fail.
🤖 Generated with Claude Code
Clean, small refactor: the exemptions are one file (src/http/origin_exempt.ts), the gate and both route-table walks read it, the gate behaviour is unchanged, and the anonymous walk now demands 403/401 exactly. The walk reuses one server, which is faster. No new dependency, no dead code. Nit, not blocking: the header comment in origin_exempt.ts says mutations-same-origin.test.ts reads both lists, but it only reads browserClientDoors.
All of the cross-origin exemptions now live in one small file,
src/http/origin_exempt.ts. The origin gate and both tests that walk the route table read it, so they can't drift apart. No new route was missing a check, so no route was fixed.Most of #14478 was already on main:
test/origin-every-mutation.test.ts. It sends every POST, PUT, PATCH and DELETE in both routers a signed-in request with a foreign Origin, and one with no Origin butSec-Fetch-Site: cross-site. Each must answer 403, write no event and be refused by the origin check itself.test/mutations-same-origin.test.tsdoes the same with no cookie or token.The one thing missing was that the exemptions were split between an inline
EXEMPTtable in the test andBROWSER_CLIENT_DOORSinorigin_gate.ts. The new file holds:BEARER_ONLY_ROUTES:POST /mcp,DELETE /mcpandPOST /oauth/userinfo. They read only a bearer token, never a cookie.BROWSER_CLIENT_DOORS:/oauth/token,/oauth/revokeand/oauth/register. Browser OAuth clients call these from their own origin by design, and PKCE, the token itself or a person's consent authenticates them.origin_gate.tsnow imports the doors from there, and the gate's behaviour is unchanged.I kept the existing test file names rather than creating the
test/same-origin-routes.test.tsthe issue suggests, because the two existing tests already cover it. I also didn't record a plan on the issue: thekeep_plantool isn't available in this run.bun x tsc --noEmit,bun scripts/gate.ts --fixand the tests below pass.scripts/fast.tsnamed 2181 test files, far over its time budget, so I ran the ones that cover this change myself.To try it:
bun test test/origin-every-mutation.test.ts test/mutations-same-origin.test.ts. Then add a line tosrc/http/origin_exempt.tsnaming a route that doesn't exist and watch it fail.🤖 Generated with Claude Code
Closes #14478