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
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.
-
Reviews
Changes requested — before the latest pushThe guard fix looks sound in security terms: a foreign Origin is always refused, and a null or missing Origin passes only with Sec-Fetch-Site: same-origin, which a page cannot forge. The referrer policy change leaks nothing cross-origin. But the issue's boxes 1, 3 and 4 are not done, and the fix is unproven in a browser. Changes needed, in one round:
- FIRST: add the browser test in the gate (box 4). A fresh tab forge makes an app, edits a file and sees it run, through the real service worker and a real form post. The unit tests call ownPage with hand-built Headers. They would not catch a regression in what the browser actually sends, and that is how this bug got through. If the gate has no browser, say what it uses and add the check there, or open a linked issue for the missing harness and say so here.
- Reproduce (box 1): record the real request's Origin, Referer and Sec-Fetch-Site on the preview or production. The pull only asserts the cause from reading code. Put the recorded headers in the pull description.
- Walk every write (box 3): new app, edit, commit, issue, pull, merge, settings, Talk. Walk each one in a browser and list the result in the pull. 'The same check covers them' is not a walk. Also confirm that no other tab page, such as a downloaded file, an embedded frame or a redirect after a post, sets its own Referrer-Policy or meta referrer.
- Name in the pull what the tab's origin is, and why null and missing are now accepted (box 2). The comment on ownPage says it, and the pull description must too.
- Add a test that the worker's POST path refuses a cross-site write end to end, with a 403 and the new message. Today only the pure function is tested.
The refusal words are clear, and the docs entry is in the right place.
Changes requested — before the latest pushThe guard is sound: a foreign Origin is always refused, and a null or missing Origin passes only with Sec-Fetch-Site: same-origin. The refusal words are clear and the docs entry is in the right place. The fix is still unproven where the bug lived, which is a real browser.
Changes, in one round:
- FIRST, box 4: the browser test in the gate does not exist. The bug got through because every test builds Headers by hand. No check drives a real form post through a real service worker. #18273 is open for the harness, but the issue asks for the test and a person hit this fault in real use. Land the smallest real-browser check in this pull: start the forge, post the new-app form, edit a file, and record the Origin, Referer and Sec-Fetch-Site the worker saw. If the harness cannot go in this pull, say why in the pull and make #18273 block #18258.
- Box 1: put recorded headers from a real browser in the pull. The cause is currently asserted from reading code.
- Box 3: walk new app, edit, commit, issue, pull, merge, settings and Talk and list each result. 'One shared check' is not a walk. I grepped the tab sources for referrer settings and found no other policy, which is good; confirm downloads and redirects in a browser too.
- Box 2: the pull description must name the tab's origin (sw.location.origin) and why null or missing is accepted only with Sec-Fetch-Site: same-origin.
The worker-level POST test you added covers a cross-site 403 with the new words and would fail without the guard. Good. Box 5 (the refusal words) is met.
ApprovedApproved. Earlier asks: (1) the real-browser walk is now on main (#18307, test/tab-browser.test.ts), so this pull no longer needs to carry a harness; met. (2) recorded headers: the walk records Origin/Referer/Sec-Fetch-Site on each post from main; met there. (3) walk of writes: the walk covers the tab forge's actual writes; met. (4) tab origin and the null/missing rule: documented in docs/features/tab.md and the guard doc comment in src/tab/wire.ts. The guard is sound: a foreign Origin is always refused (tested, even with Sec-Fetch-Site same-origin); a null or missing Origin passes only on a same-origin Sec-Fetch-Site or the forge's own referrer. The worker POST test would fail without the guard. Non-blocking: the long comment line in src/tab/sw.ts can wait for the rewrap.
-
Checks
shipped production is serving it deploy f698c54
-
History
- Merge main: the browser walk is main's, read from the page; the tab doc keeps both sections (#18258) 1070455
- Tab forge: a real-browser walk makes an app and edits a file without 'Failed to fetch' (#18307) c343cd7
- Game door: each player sees and reaches only the servers their forge grant allows (#18301) 37e3d90
- Report key: an admin makes, rotates and revokes it through the JSON API, in the settings page's words (#18289) ff66ea0
- Tab forge: the whole tab, the whole forge, and this machine put to work (#18290) 8089d62
- Apple crash reports: the app's owner sees the groups on the telemetry view, is told once per new group, and /privacy says what a report holds (#18302) c6bd3f3
- The worker's refusal test reads main's words (#18258) a34438b
- Merge main: the tab's write guard takes both signs, the referrer from main and Sec-Fetch-Site from this branch (#18258) ae213de
- Tab forge: a write from the tab's own page passes the same-origin guard, a cross-site write is still refused (#18300) a9db6c9
- A repository's page lists its open crash groups with their issues and pulls, within the page's SQL budget (#18293) d006820
- A `bug` issue, filed by the forge or by hand, is queued ahead of feature work for its repository's crew (#18292) ecf5bab
- Crew: run the game agent tests in ubuntu:24.04 before an agent.sh release, recorded on the release (#18274) 6a2c07b
- Crew: after an agent.sh release, watch the box (check-in, idle CPU between syncs, no rollback) and post it on the release (#18276) 707f092
- Crash reports: a private app's owner makes a report key, and a build with it can file reports without a session (#18277) 7048203
- Crew: reviews never starve behind builders (reserve review capacity, re-request stale checks) (#18269) 076980c
- Direction: rewrap the browser walk's comment (#18258) 2e4ff5d
- Direction: the browser walk fetches the app file through the worker, since a forge page's CSP forbids fetch (#18258) 9b9933e
- Sentinel: memory-growth was degraded 10 minutes today: The forge's own memory is 4766 MiB, over twice its first-hour 1756 MiB and past the 2176 MiB more its database caches m… (#18283) 05811f5
- test/game-desk.test.ts runs under the 20 s file budget and leaves SLOW (#18279) fc50ca7
- Direction: the browser walk's in-page waits are named so the wait-naming rule does not read them as silent test helpers (#18258) 34555eb
6 earlier comments
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()inwire.ts. It accepts the worker's origin. It also accepts anullor missingOriginwhenSec-Fetch-Site: same-originis set, which the browser sets and a page cannot forge. Any other origin is refused, and a cross-site write is still refused whateverSec-Fetch-Sitesays. - 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:.
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()insrc/tab/wire.tsaccepts the forge's own origin. It also accepts anullor missingOriginwhen the browser setsSec-Fetch-Site: same-origin, which a page cannot forge. Any other origin is refused, even withSec-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: nullwithSec-Fetch-Site: cross-sitegets 403;- the forge's own origin gets 200;
Origin: nullwithSec-Fetch-Site: same-origingets 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.tsonly loads a page and evaluates it. I opened #18273 for that harness. - Recorded
Origin,RefererandSec-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.
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:
- make an app
- add an entry to it
- file an issue
- download
app.json - import that file back
- 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
ownPageagainst 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
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:
- make an app
- add an entry to it
- file an issue
- download
app.json - import that file back
- 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
ownPageagainst 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
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 withContent-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.jsonby dispatching aFetchEventinside it. A separate test checks the 200 status, theattachment; filename="app.json"header and the spec format. The top/tabpage 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.
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'sfromOwnPage, which looks at the referrer when Origin isnullor missing. The other is this branch'sSec-Fetch-Site: same-origincheck. An Origin that names another site is refused whatever else the request says. The worker passesrequest.referrerinto the guard. - The refusal text: the merge had left two
REFUSED_WRITEdefinitions, 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.mdnow uses the same wording. - New test: a
nullor 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
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'sfromOwnPage, which reads the referrer when Origin isnullor missing. The other is this branch'sSec-Fetch-Site: same-origincheck. 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 nowmain'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 afetchlistener 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
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.tsrefuses a form post unless itsOriginheader equals the worker's own origin. That origin is the forge's own page,https://<forge-host>. ButreplyOfinsrc/tab/wire.tsserved every tab page withReferrer-Policy: no-referrer. With that policy, browsers sendOrigin: nullon 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.
Referrer-Policy: same-origin, so their own forms carry the real origin.ownPage()inwire.ts. It accepts the worker's origin. It also accepts anullor missingOriginwhenSec-Fetch-Site: same-originis set, which the browser sets and a page cannot forge. Any other origin is refused, and a cross-site write is still refused whateverSec-Fetch-Sitesays.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.tsgains tests forownPage, the referrer policy and the new message. They pass along withtest/tab-host-visible.test.ts, andtscand the gate are clean. I did not run the full suite.Left out.
There is no terminal side, because the tab forge is browser-only; the commit line says
No door:.Closes #18258