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

Tab forge: a write from the tab's own page passes the same-origin guard, a cross-site write is still refused #18300

opened this

Merged 5h 38m ago, live in production

Fixes #18294. The tab forge no longer refuses its own writes with "not from this forge's own page", and a write from another site is still refused. Cause.

Notes

opened this

Fixes #18294. The tab forge no longer refuses its own writes with "not from this forge's own page", and a write from another site is still refused.

Cause. The refusal came from one line in src/tab/sw.ts: request.headers.get("origin") !== sw.location.origin. A service worker gets a form's request before the browser adds its Origin header, so a post from the tab's own page arrives without one. On top of that, replyOf in src/tab/wire.ts served every tab page with referrer-policy: no-referrer, so any Origin the browser did send would have been "null". Every form post from a tab page failed that check.

Fix. A new pure function, fromOwnPage(origin, referrer, own) in src/tab/wire.ts, now decides whether a write is allowed:

  • Origin equal to the tab's origin: accepted.
  • Any other Origin that is present and not "null": refused, whatever the referrer says.
  • No Origin, or "null": the request's referrer decides. It is accepted only if its origin is the tab's own.

The tab's origin is the forge's own origin, the one the worker runs on (sw.location.origin). Its pages live under /tab/f/. That referrer is accepted because the browser sets it and a page on another site cannot make it name this origin. To make the referrer reach the worker, tab pages now send referrer-policy: same-origin. That is the same policy the hosted forge sets in securityFloor, so nothing is sent to other sites. The hosted forge's own guard is not touched.

Refusal words. These now say what happened and what to do: "this change was sent from a page outside this tab forge, so nothing was saved. Go back to the tab forge, open the page again and send it from there", with a link to /tab.

Tests (test/tab-own-page.test.ts):

  • Two request shapes the old line refused now pass: no Origin with a same-origin referrer, and Origin: null with one.
  • Cross-site writes are still refused: a foreign Origin, a foreign Origin with our referrer, a foreign referrer, no referrer at all, about:client, and a look-alike host.
  • The tab pages' referrer policy is same-origin.
  • The refusal text says what to do.
  • The worker answers a foreign post with 403 and that text.

The 159 tests scripts/fast.ts names passed except one: scripts-fast.test.ts "a clean tree and a docs-only diff exit 3" hits its 5-second timeout in this sandbox. It times out the same way on main's code, so it is not caused by this change. The type check, gate and design lint are clean. Nothing reused: similar.ts was not run, and no existing helper checked a referrer inside the worker.

Left out: the browser walk, and checking each tab-forge write in a real browser, are the next issue. The change has no terminal side, which the commit records as No door.

[{"go":"/tab","look":"start the tab forge, then make a new app from its page","expect":"the app is made; no 'Refused' page"},{"go":"/tab","look":"edit a file of that app and save","expect":"the save goes through"}]

🤖 Generated with Claude Code

Closes #18294

commented

Fixes #18294. The tab forge no longer refuses its own writes with "not from this forge's own page", and a write from another site is still refused.

Cause. The refusal came from one line in src/tab/sw.ts: request.headers.get("origin") !== sw.location.origin. A service worker gets a form's request before the browser adds its Origin header, so a post from the tab's own page arrives without one. On top of that, replyOf in src/tab/wire.ts served every tab page with referrer-policy: no-referrer, so any Origin the browser did send would have been "null". Every form post from a tab page failed that check.

Fix. A new pure function, fromOwnPage(origin, referrer, own) in src/tab/wire.ts, now decides whether a write is allowed:

  • Origin equal to the tab's origin: accepted.
  • Any other Origin that is present and not "null": refused, whatever the referrer says.
  • No Origin, or "null": the request's referrer decides. It is accepted only if its origin is the tab's own.

The tab's origin is the forge's own origin, the one the worker runs on (sw.location.origin). Its pages live under /tab/f/. That referrer is accepted because the browser sets it and a page on another site cannot make it name this origin. To make the referrer reach the worker, tab pages now send referrer-policy: same-origin. That is the same policy the hosted forge sets in securityFloor, so nothing is sent to other sites. The hosted forge's own guard is not touched.

Refusal words. These now say what happened and what to do: "this change was sent from a page outside this tab forge, so nothing was saved. Go back to the tab forge, open the page again and send it from there", with a link to /tab.

Tests (test/tab-own-page.test.ts):

  • Two request shapes the old line refused now pass: no Origin with a same-origin referrer, and Origin: null with one.
  • Cross-site writes are still refused: a foreign Origin, a foreign Origin with our referrer, a foreign referrer, no referrer at all, about:client, and a look-alike host.
  • The tab pages' referrer policy is same-origin.
  • The refusal text says what to do.
  • The worker answers a foreign post with 403 and that text.

The 159 tests scripts/fast.ts names passed except one: scripts-fast.test.ts "a clean tree and a docs-only diff exit 3" hits its 5-second timeout in this sandbox. It times out the same way on main's code, so it is not caused by this change. The type check, gate and design lint are clean. Nothing reused: similar.ts was not run, and no existing helper checked a referrer inside the worker.

Left out: the browser walk, and checking each tab-forge write in a real browser, are the next issue. The change has no terminal side, which the commit records as No door.

[{"go":"/tab","look":"start the tab forge, then make a new app from its page","expect":"the app is made; no 'Refused' page"},{"go":"/tab","look":"edit a file of that app and save","expect":"the save goes through"}]

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs