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

A cross-origin write is refused in words that name the cause, not 'your credentials lack the scope' #14427

Merged opened this

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

Merged

A write that comes from a foreign Origin now answers 403 crossorigin, with a message and hint that name the real cause. I ran tsc and four test files (mutations-same-origin, origin-every-mutation, openapi-served, api-errors: 29 pass, 0 fail).

Notes

shipped production is serving it deploy 2f48880

opened this

A write that comes from a foreign Origin now answers 403 cross_origin, with a message and hint that name the real cause. I ran tsc and four test files (mutations-same-origin, origin-every-mutation, openapi-served, api-errors: 29 pass, 0 fail). I did not run the full suite, because scripts/fast.ts named 2653 test files for this diff.

What changed

  • Gate answer: originGate in src/http/origin_gate.ts now refuses with cross_origin. The message is "a browser page on another origin may not write here: this forge accepts writes from pages of <this forge's origin> only". The hint is "send the request without an Origin header, or with a token". The request's Origin value is never echoed, and the status is still 403.
  • Who gets JSON: /api/* and any request that sends Content-Type: application/json (or +json) or ranks JSON above HTML in Accept (refusesInJson, called from src/http/server.ts). Browser form posts still get the forbidden page, same status.
  • Gate logic: untouched. Token callers are still exempt, and BROWSER_CLIENT_DOORS is unchanged.
  • Error code list: cross_origin is listed among the refusals of every non-GET route in the OpenAPI document (src/contract/openapi.ts).
  • Tests: four new tests in test/mutations-same-origin.test.ts:
    • The JSON paths say cross_origin, with the hint, no evil.example and no "scope".
    • A form post keeps its HTML answer.
    • A token caller is not refused.
    • The OpenAPI document lists the code.

Left out

  • The forbidden hint in HINTS is unchanged. It still describes the scope refusal, which is correct for that code.
  • The code is listed on every non-GET route, including the three OAuth doors the gate lets through.

Try it: curl -X POST $FORGE_URL/api/v1/user/email/verify -H 'content-type: application/json' -H 'origin: https://evil.example' -d '{}' and read error: "cross_origin".

🤖 Generated with Claude Code

Closes #14419

commented

A write that comes from a foreign Origin now answers 403 cross_origin, with a message and hint that name the real cause. I ran tsc and four test files (mutations-same-origin, origin-every-mutation, openapi-served, api-errors: 29 pass, 0 fail). I did not run the full suite, because scripts/fast.ts named 2653 test files for this diff.

What changed

  • Gate answer: originGate in src/http/origin_gate.ts now refuses with cross_origin. The message is "a browser page on another origin may not write here: this forge accepts writes from pages of <this forge's origin> only". The hint is "send the request without an Origin header, or with a token". The request's Origin value is never echoed, and the status is still 403.
  • Who gets JSON: /api/* and any request that sends Content-Type: application/json (or +json) or ranks JSON above HTML in Accept (refusesInJson, called from src/http/server.ts). Browser form posts still get the forbidden page, same status.
  • Gate logic: untouched. Token callers are still exempt, and BROWSER_CLIENT_DOORS is unchanged.
  • Error code list: cross_origin is listed among the refusals of every non-GET route in the OpenAPI document (src/contract/openapi.ts).
  • Tests: four new tests in test/mutations-same-origin.test.ts:
    • The JSON paths say cross_origin, with the hint, no evil.example and no "scope".
    • A form post keeps its HTML answer.
    • A token caller is not refused.
    • The OpenAPI document lists the code.

Left out

  • The forbidden hint in HINTS is unchanged. It still describes the scope refusal, which is correct for that code.
  • The code is listed on every non-GET route, including the three OAuth doors the gate lets through.

Try it: curl -X POST $FORGE_URL/api/v1/user/email/verify -H 'content-type: application/json' -H 'origin: https://evil.example' -d '{}' and read error: "cross_origin".

🤖 Generated with Claude Code

commented

A cross-origin write now comes back as cross_origin, and I've updated the two 403-page tests that still expected the old forbidden code. This push fixes the failing test/forbidden-page.test.ts tests; I did not rerun the forge's full check.

  • What changed: both tests in test/forbidden-page.test.ts (the signed-in cross-origin form, and the script's cross-site post) now expect error: "cross_origin". I also dropped an import that had become unused.
  • Why the tests were wrong: the origin gate was deliberately changed to answer cross_origin with a message and hint that name the cause, so tests asserting forbidden were out of date.
  • Not touched: the /llms.txt byte-budget test is red on main at 5ed51fb too, so it isn't this pull's doing. Of the four failures in the check log, I fixed only the two in test/forbidden-page.test.ts. I didn't look at "the screen shows the share, the budgets that refused and the agent refused".
  • Verified locally: test/forbidden-page.test.ts and test/mutations-same-origin.test.ts pass, and tsc --noEmit is clean. scripts/gate.ts --fix ran and changed nothing.
  • To try it: curl -X POST $FORGE_URL/api/v1/user/email/verify -H 'content-type: application/json' -H 'origin: https://evil.example' -d '{}' should return cross_origin.
Approved

Clean, small change. Foreign-origin JSON/API writes now answer 403 cross_origin with a cause-naming message and hint, never echoing Origin. Form posts keep the page. Gate logic and BROWSER_CLIENT_DOORS untouched. Minor, non-blocking: cross_origin is listed on the three OAuth doors the gate exempts, and the token-exempt test only asserts the code is not cross_origin.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs