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

Tab forge: making an app is refused ("not from this forge's own page") #18267

opened this in answer to

Merged 4h 41m ago, live in production

Making an app in the tab forge was refused because its pages told the browser to send no origin. I fixed that and added unit tests for the guard. I did not reproduce it headless on production, add the browser test, or run the "five in five" check.

Notes

opened this

Making an app in the tab forge was refused because its pages told the browser to send no origin. I fixed that and added unit tests for the guard. I did not reproduce it headless on production, add the browser test, or run the "five in five" check.

Cause. The worker in src/tab/sw.ts refuses a form post unless its Origin header equals the worker's own origin. That origin is the forge's own page, https://<forge-host>. But replyOf in src/tab/wire.ts served every tab page with Referrer-Policy: no-referrer. With that policy, browsers send Origin: null on a form post, so the forge's own forms failed its own guard. I found this by reading the code, not by reproducing it in a browser.

Fix.

  • Policy. Tab pages now send Referrer-Policy: same-origin, so their own forms carry the real origin.
  • Guard. The check is now ownPage() in wire.ts. It accepts the worker's origin. It also accepts a null or missing Origin when Sec-Fetch-Site: same-origin is set, which the browser sets and a page cannot forge. Any other origin is refused, and a cross-site write is still refused whatever Sec-Fetch-Site says.
  • Refusal message. It now says the change did not come from the forge's own page, and to go back and try again, or open /tab afresh. I added a short note to docs/features/tab.md.

Writes. Every write in the tab forge goes through that one check. The fix covers new app, edit, issue, pull, merge, settings and Talk, but I did not walk each one in a browser.

Tests. test/tab.test.ts gains tests for ownPage, the referrer policy and the new message. They pass along with test/tab-host-visible.test.ts, and tsc and the gate are clean. I did not run the full suite.

Left out.

  • The headless reproduction on production.
  • The "fresh tab forge makes an app, edits a file and sees it run" browser test in the gate. This sandbox has no browser, so that test is still open.
  • The "five in five on production" check. It can only be done after this is deployed.

There is no terminal side, because the tab forge is browser-only; the commit line says No door:.

Closes #18258

6 earlier comments
commented

Making an app in the tab forge was refused because its pages told the browser to send no origin. I fixed that and added unit tests for the guard. I did not reproduce it headless on production, add the browser test, or run the "five in five" check.

Cause. The worker in src/tab/sw.ts refuses a form post unless its Origin header equals the worker's own origin. That origin is the forge's own page, https://<forge-host>. But replyOf in src/tab/wire.ts served every tab page with Referrer-Policy: no-referrer. With that policy, browsers send Origin: null on a form post, so the forge's own forms failed its own guard. I found this by reading the code, not by reproducing it in a browser.

Fix.

  • Policy. Tab pages now send Referrer-Policy: same-origin, so their own forms carry the real origin.
  • Guard. The check is now ownPage() in wire.ts. It accepts the worker's origin. It also accepts a null or missing Origin when Sec-Fetch-Site: same-origin is set, which the browser sets and a page cannot forge. Any other origin is refused, and a cross-site write is still refused whatever Sec-Fetch-Site says.
  • Refusal message. It now says the change did not come from the forge's own page, and to go back and try again, or open /tab afresh. I added a short note to docs/features/tab.md.

Writes. Every write in the tab forge goes through that one check. The fix covers new app, edit, issue, pull, merge, settings and Talk, but I did not walk each one in a browser.

Tests. test/tab.test.ts gains tests for ownPage, the referrer policy and the new message. They pass along with test/tab-host-visible.test.ts, and tsc and the gate are clean. I did not run the full suite.

Left out.

  • The headless reproduction on production.
  • The "fresh tab forge makes an app, edits a file and sees it run" browser test in the gate. This sandbox has no browser, so that test is still open.
  • The "five in five on production" check. It can only be done after this is deployed.

There is no terminal side, because the tab forge is browser-only; the commit line says No door:.

commented

I fixed the refusal and added a worker-level test, but the browser test, the real-request headers and the browser walk of every write are not done. The browser work is split into #18273, so this pull stays open until that is decided.

What the tab's origin is. The tab forge's origin is the forge's own origin (sw.location.origin, e.g. https://<forge-host>). The service worker is served from it, and /tab and /tab/f/* are on it. A write counts as "this forge's own page" when its Origin equals that.

Why it was refused. Tab pages were served with Referrer-Policy: no-referrer. Browsers then send Origin: null on a form post, so the forge's own forms failed its own guard. That is read from the code, not from a recorded request.

The fix.

  • Tab pages now send Referrer-Policy: same-origin, so their own forms carry the real origin.
  • ownPage() in src/tab/wire.ts accepts the forge's own origin. It also accepts a null or missing Origin when the browser sets Sec-Fetch-Site: same-origin, which a page cannot forge. Any other origin is refused, even with Sec-Fetch-Site: same-origin.
  • A refused write now answers 403 with words that say what to do: go back to the forge in this tab and try again, or open /tab afresh.

Test added (review item 5). test/tab-host-visible.test.ts now posts through the worker's real fetch handler in src/tab/sw.ts. It checks four cases:

  • a foreign origin gets 403 with the new words;
  • Origin: null with Sec-Fetch-Site: cross-site gets 403;
  • the forge's own origin gets 200;
  • Origin: null with Sec-Fetch-Site: same-origin gets 200.

Dropping the ownPage call in sw.ts fails this test. tsc and the gate pass. I ran this file and test/tab.test.ts, not the full suite.

Referrer policy elsewhere. I searched src/tab, src/web/tab-asset.ts and src/web/pages/tab.ts and found no other referrer policy or meta referrer. Every tab reply, including redirects and downloaded files, goes through replyOf. I did not check this in a browser.

Not done.

  • Browser test in the gate (item 1). The repo has no driver that can keep a page and a service worker alive. test/helpers/chrome.ts only loads a page and evaluates it. I opened #18273 for that harness.
  • Recorded Origin, Referer and Sec-Fetch-Site (item 2). I did not record them, because I can't drive a browser from here.
  • Walking each write (item 3). I did not walk new app, edit, commit, issue, pull, merge, settings and Talk. By the code they all pass through the one guard, but that is not a walk. #18273 covers it.
  • "Five in five on production". This can only be checked after deploy.

No door: the tab forge is browser-only.

commented

Making an app in the tab forge failed because the forge's pages sent no real Origin on their forms. The pages now send one, and a real-browser test now walks the forge's writes. I could not run that test here: Chromium cannot start in this sandbox because it cannot make a unix socket. It ran as skipped locally, and the forge's check is its first real run.

What the guard accepts (src/tab/wire.ts, ownPage). The tab forge's own origin is the service worker's origin, sw.location.origin. Its pages run under /tab/f/ on that same origin. A POST passes when its Origin equals that origin.

The pages used to be served with Referrer-Policy: no-referrer, which makes a browser send Origin: null on a form post. That is why the forge refused its own forms. They are now served with same-origin.

A post with Origin: null or no Origin passes only when Sec-Fetch-Site: same-origin. The browser sets that header and a page cannot fake it, so a cross-site write is still refused while a browser that drops the origin still works. Any other origin is always refused, with the new message that says to go back to the forge in this tab.

The service worker may never see Sec-Fetch-Site at all. If so, the Origin header carries every check on its own.

The real-browser test (test/tab-browser.test.ts, walkWithWorker in test/helpers/chrome.ts). This is the smallest version of the harness #18273 asks for, so #18273 does not need to block #18258. A headless Chromium opens /tab and presses Start. The test then connects to the running service worker and adds a listener that only records the Origin, Referer and Sec-Fetch-Site of each POST. Then it walks every write the tab forge has, each as a real form post in the forge's frame:

  1. make an app
  2. add an entry to it
  3. file an issue
  4. download app.json
  5. import that file back
  6. remove the app

It fails if:

  • any page shows the refusal;
  • any post lands somewhere other than expected (each redirect is followed);
  • the download is not an attachment;
  • any recorded post would not pass ownPage against the server's origin.

It also logs the headers as the worker saw them and as the page sent them, so the check's log holds the record box 1 asks for. I have not seen those headers myself; the check is the first run. The waits wait for animation frames and the devtools target list, not fixed delays.

Box 3. The tab forge has no commits, pulls, merges, settings or Talk. Its writes are make, edit an entry, issue, import and remove, its one download is app.json, and its redirects are the 303s after each post. The walk covers all of these. A real-browser cross-site refusal is not here: the worker-level test (test/tab-host-visible.test.ts) still covers it, with the new message.

To try it: run bun test test/tab-browser.test.ts on a machine where Chromium starts, and read the two lines it logs. Or open /tab on the preview, press Start, make an app, then add an entry, file an issue, import and remove the app.

[{"go":"/tab","look":"press Start, then type “Track my water” in the forge's own “Make an app” box and submit","expect":"the new app's page opens; no “did not come from the forge's own page” refusal"},
 {"go":"/tab/f/issues","look":"file an issue from the form","expect":"lands on /tab/f/issues/N showing the title"},
 {"go":"/tab/f/","look":"import the app file, then open the app and remove it by typing its title","expect":"each write lands back on the forge, none refused"}]

🤖 Generated with Claude Code

commented

Making an app in the tab forge failed because the forge's pages sent no real Origin on their forms. The pages now send one, and a real-browser test now walks the forge's writes. I could not run that test here: Chromium cannot start in this sandbox because it cannot make a unix socket. It ran as skipped locally, so it has not yet passed in a real browser. Its headers have not been recorded yet either.

What the guard accepts (src/tab/wire.ts, ownPage). The tab forge's own origin is the service worker's origin, sw.location.origin. Its pages run under /tab/f/ on that same origin. A POST passes when its Origin equals that origin.

The pages used to be served with Referrer-Policy: no-referrer, which makes a browser send Origin: null on a form post. That is why the forge refused its own forms. They are now served with same-origin.

A post with Origin: null or no Origin passes only when Sec-Fetch-Site: same-origin. The browser sets that header and a page cannot fake it, so a cross-site write is still refused while a browser that drops the origin still works. Any other origin is always refused, with the new message that says to go back to the forge in this tab.

The service worker may never see Sec-Fetch-Site at all. If so, the Origin header carries every check on its own.

The real-browser test (test/tab-browser.test.ts, walkWithWorker in test/helpers/chrome.ts). This is the smallest version of the harness #18273 asks for, so #18273 does not need to block #18258. A headless Chromium opens /tab and presses Start. The test then connects to the running service worker and adds a listener that only records the Origin, Referer and Sec-Fetch-Site of each POST. Then it walks every write the tab forge has, each as a real form post in the forge's frame:

  1. make an app
  2. add an entry to it
  3. file an issue
  4. download app.json
  5. import that file back
  6. remove the app

It fails if:

  • any page shows the refusal;
  • any post lands somewhere other than expected (each redirect is followed);
  • the download is not an attachment;
  • any recorded post would not pass ownPage against the server's origin.

It also logs the headers as the worker saw them and as the page sent them, so the check's log holds the record box 1 asks for.

The waits inside the page's script wait for animation frames and the devtools target list, not fixed delays. They are named holds and landed because the wait-naming rule had read the old until as a test helper that does not log what it waits for, which is what failed the last check.

Box 3. The tab forge has no commits, pulls, merges, settings or Talk. Its writes are make, edit an entry, issue, import and remove, its one download is app.json, and its redirects are the 303s after each post. The walk covers all of these. A real-browser cross-site refusal is not here: the worker-level test (test/tab-host-visible.test.ts) still covers it, with the new message.

To try it: run bun test test/tab-browser.test.ts on a machine where Chromium starts, and read the two lines it logs. Or open /tab on the preview, press Start, make an app, then add an entry, file an issue, import and remove the app.

[{"go":"/tab","look":"press Start, then type “Track my water” in the forge's own “Make an app” box and submit","expect":"the new app's page opens; no “did not come from the forge's own page” refusal"},
 {"go":"/tab/f/issues","look":"file an issue from the form","expect":"lands on /tab/f/issues/N showing the title"},
 {"go":"/tab/f/","look":"import the app file, then open the app and remove it by typing its title","expect":"each write lands back on the forge, none refused"}]

🤖 Generated with Claude Code

commented

This fixes the check's failure, walk: TypeError: Failed to fetch, in the browser walk's "download" step. I couldn't run the walk here, because Chromium can't run in my sandbox and test/tab-browser.test.ts skips. tsc and the gate are clean. The forge's check is the first real run.

What changed

  • Cause: the walk called frame.contentWindow.fetch("/tab/f/app.json") from a forge page. Those pages are served with Content-Security-Policy: default-src 'none', so the browser blocks the fetch. The app is fine and the test was wrong.
  • Download: the test now asks the service worker for /tab/f/app.json by dispatching a FetchEvent inside it. A separate test checks the 200 status, the attachment; filename="app.json" header and the spec format. The top /tab page can't fetch it either, because it sits outside the worker's scope.
  • Import: the import step now submits a spec built with makeSpec, since the walk no longer holds the download.
  • Unchanged: the existing tests for the worker's recorded Origin, Referer and Sec-Fetch-Site on each post are untouched, apart from where they read the worker's result.
  • Commits: both commits name #18258. The change is test-only, so I added no terminal side or how-to. It adds no exports and no module-level state.

Left out: nothing changed in src/, so the forge-page CSP stays as it is. The two comment lines over 100 columns in src/tab/sw.ts and test/helpers/chrome.ts are left for the nightly rewrap, as the gate says.

To try it: bun test test/tab-browser.test.ts on a machine where Chromium runs.

commented

The tab forge's worker stops refusing a "make an app" post that comes from its own page. Cross-site writes are still refused. This update merges main, which had fixed the same guard a different way in #18300.

  • The guard (src/tab/wire.ts, src/tab/sw.ts): ownPage(headers, origin, referrer) now accepts a write if either check passes. One is main's fromOwnPage, which looks at the referrer when Origin is null or missing. The other is this branch's Sec-Fetch-Site: same-origin check. An Origin that names another site is refused whatever else the request says. The worker passes request.referrer into the guard.
  • The refusal text: the merge had left two REFUSED_WRITE definitions, so I kept main's wording ("nothing was saved … send it from there", with a link back to /tab). Three tests (test/tab.test.ts, test/tab-browser.test.ts, test/tab-host-visible.test.ts) checked for this branch's old words, so I changed their expected text to main's. The tests were out of date, not the code. docs/features/tab.md now uses the same wording.
  • New test: a null or missing Origin passes when the referrer is the forge's own page, and is refused when the referrer is another site.

bun x tsc --noEmit passes. The tab, refusal, doors and unused-export tests (102 files) pass, with 5 skipped because the sandbox can't bind sockets. bun scripts/gate.ts --explain shows 0 rules failing. The full suite was too big to run here (scripts/fast.ts estimated about 31 minutes), so it is left to the forge's check.

To try it: on the preview, open /tab, make an app, and the post goes through. A form on another site posting to /tab/f/… gets the 403 page with the link back to /tab.

🤖 Generated with Claude Code

commented

The tab forge's worker no longer refuses a "make an app" post from its own page, and cross-site writes are still refused. This update merges main again.

  • The guard (src/tab/wire.ts, src/tab/sw.ts): ownPage(headers, origin, referrer) accepts a write if either check passes. One is main's fromOwnPage, which reads the referrer when Origin is null or missing. The other is this branch's Sec-Fetch-Site: same-origin check. An Origin naming another site is always refused. The 403 page uses main's wording, with a link back to /tab.
  • Browser walk (test/tab-browser.test.ts, test/helpers/chrome.ts): both files are now main's versions, which supersede this branch's. They record each post's headers in the page through DevTools instead of a listener added to the worker, because Chrome never runs a fetch listener added after the worker's script first runs. They also add a check that the scripts sent to the browser parse.
  • Docs (docs/features/tab.md): keeps both sections, this branch's "A change refused in the tab forge" and main's "The whole tab (#18259)".

The type check passes, and the five tab test files pass: 50 tests, 6 skipped. The skipped ones are the real-Chromium walk and others that need what this sandbox lacks: a browser or a socket. The forge's check runs them. bun scripts/gate.ts --explain shows 0 rules failing and one note about a long comment line in src/tab/sw.ts.

To try it: on the preview, open /tab, start the forge and make an app; the post goes through. A form on another site posting to /tab/f/… gets the 403 page with the link back to /tab.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs