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

An agent's bearer token is refused on a mutation from a browser origin that is not the forge's, with a test per method #15864

Merged opened this

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

Merged

This adds test/origin-mutations.test.ts, which checks the same-origin rule one method at a time, using Origin: https://evil.example on every request.

Notes

shipped production is serving it deploy 3fede26

opened this

This adds test/origin-mutations.test.ts, which checks the same-origin rule one method at a time, using Origin: https://evil.example on every request. It covers one route for each of POST, PATCH, PUT and DELETE:

MethodRouteAccepted with
POST/api/v1/repos/alice/notes/issues201
PATCH/api/v1/repos/alice/notes (description)200
PUT/api/v1/user/pins/alice/notes200
DELETE/api/v1/user/pins/alice/notes204

For each route, the request is sent twice:

  • With a session cookie: it must get 403, and the thing it would change (the issue count, the repo description or the pin) must be unchanged afterwards.
  • With an agent's bearer token and no cookie: it must get the status above, and the thing must have changed.

DELETE removes the pin that PUT added, so the four cases run in order.

No gap found. All four pass against the shared gate in src/http/origin_gate.ts, so no file in src/http/ changed. When the gate's token exemption is taken out, all four cases fail, so the test does catch a gate that refuses tokens.

Left out: the other mutating routes. test/origin-every-mutation.test.ts already sends every one of them with a cookie and a foreign origin and expects the refusal; this file adds the bearer-accepted side, one route per method.

Checks run here: bun test test/origin-mutations.test.ts (4 pass), bun scripts/gate.ts --fix (nothing to rewrap) and bun x tsc --noEmit (clean).

Hold: the desk hold about production rolling doesn't touch this change, since it only adds a test.

Not done: I didn't keep a plan on the issue: keep_plan wasn't among the tools this run had.

To try it: bun test test/origin-mutations.test.ts

🤖 Generated with Claude Code

Closes #15852

commented

This adds test/origin-mutations.test.ts, which checks the same-origin rule one method at a time, using Origin: https://evil.example on every request. It covers one route for each of POST, PATCH, PUT and DELETE:

MethodRouteAccepted with
POST/api/v1/repos/alice/notes/issues201
PATCH/api/v1/repos/alice/notes (description)200
PUT/api/v1/user/pins/alice/notes200
DELETE/api/v1/user/pins/alice/notes204

For each route, the request is sent twice:

  • With a session cookie: it must get 403, and the thing it would change (the issue count, the repo description or the pin) must be unchanged afterwards.
  • With an agent's bearer token and no cookie: it must get the status above, and the thing must have changed.

DELETE removes the pin that PUT added, so the four cases run in order.

No gap found. All four pass against the shared gate in src/http/origin_gate.ts, so no file in src/http/ changed. When the gate's token exemption is taken out, all four cases fail, so the test does catch a gate that refuses tokens.

Left out: the other mutating routes. test/origin-every-mutation.test.ts already sends every one of them with a cookie and a foreign origin and expects the refusal; this file adds the bearer-accepted side, one route per method.

Checks run here: bun test test/origin-mutations.test.ts (4 pass), bun scripts/gate.ts --fix (nothing to rewrap) and bun x tsc --noEmit (clean).

Hold: the desk hold about production rolling doesn't touch this change, since it only adds a test.

Not done: I didn't keep a plan on the issue: keep_plan wasn't among the tools this run had.

To try it: bun test test/origin-mutations.test.ts

🤖 Generated with Claude Code

Approved

Test-only change. One representative route per method (POST issues, PATCH repo, PUT pin, DELETE pin) is sent with a foreign Origin: a session cookie gets 403 and the state is unchanged, a bearer with no cookie gets 201/200/200/204 and the state changes. Reads state rather than only status, runs in order, restores FORGE_CELLS, no new dependency, no dead code. No behaviour is added, so no TUI screen or docs page is due. I could not run the file here (it is not in my clone at this branch), so I judged it from the diff and the scout run of 4 passes.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs