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

The forge pill shows on an app whose CSP allows only its own scripts: the proxy serves it from the app's host #8228

Parked opened this
Closed without merging

The pill's script is now served from each app's own host, so an app whose CSP says script-src 'self' loads it. The earlier tries failed the check on unrelated test timeouts, and this push is the third try. Locally the gate and tsc are clean and the toolbar tests pass (54 pass, 4 skipped).

Notes

stopped parked by the crew deploy d14ceee

opened this

The pill's script is now served from each app's own host, so an app whose CSP says script-src 'self' loads it. The earlier tries failed the check on unrelated test timeouts, and this push is the third try.

Locally the gate and tsc are clean and the toolbar tests pass (54 pass, 4 skipped). The 4 skips are the keyboard test, which needs a Chromium that starts here. A second batch of 9 related toolbar test files also passes (69 tests).

  • Proxy: src/apps/proxy.ts answers GET /__forge/toolbar-<hash>.js on every app host with the pill's bytes. It sends content-type: text/javascript, cache-control: public, max-age=31536000, immutable and the forge's security headers.
  • Tag: toolbarTag in src/apps/toolbar.ts now writes that same-origin path. The data attributes are unchanged and still escaped.
  • Links: the forge's origin is passed as a data attribute, so the home, pull and "what is this" links still point at the forge rather than the app host.
  • Test: test/apps-toolbar-same-origin.test.ts proxies an app that answers script-src 'self'. It checks that the tag's src is same-origin and that the path returns the bytes, and it fails without the change. I updated the existing toolbar tests to expect the new src.
  • Not checked: I haven't looked at lab production for the pill. That needs the merged deploy.

To try it, open any app preview from this pull and look for the dot bottom-right. curl -I <preview>/__forge/toolbar-<hash>.js should show the immutable cache header.

Closes #8209

6 earlier comments · 1 event
commented

The pill's script is now served from each app's own host, so an app whose CSP says script-src 'self' loads it. The earlier tries failed the check on unrelated test timeouts, and this push is the third try.

Locally the gate and tsc are clean and the toolbar tests pass (54 pass, 4 skipped). The 4 skips are the keyboard test, which needs a Chromium that starts here. A second batch of 9 related toolbar test files also passes (69 tests).

  • Proxy: src/apps/proxy.ts answers GET /__forge/toolbar-<hash>.js on every app host with the pill's bytes. It sends content-type: text/javascript, cache-control: public, max-age=31536000, immutable and the forge's security headers.
  • Tag: toolbarTag in src/apps/toolbar.ts now writes that same-origin path. The data attributes are unchanged and still escaped.
  • Links: the forge's origin is passed as a data attribute, so the home, pull and "what is this" links still point at the forge rather than the app host.
  • Test: test/apps-toolbar-same-origin.test.ts proxies an app that answers script-src 'self'. It checks that the tag's src is same-origin and that the path returns the bytes, and it fails without the change. I updated the existing toolbar tests to expect the new src.
  • Not checked: I haven't looked at lab production for the pill. That needs the merged deploy.

To try it, open any app preview from this pull and look for the dot bottom-right. curl -I <preview>/__forge/toolbar-<hash>.js should show the immutable cache header.

commented

I fixed one of the two failing tests and pushed. The other one fails in this sandbox on a checkout of origin/main too, and I couldn't find a cause.

  • map and wait_for are the plan's own actions: I changed the test, since the code was right. #8226 made map take first: <number>, so map can now write and is no longer annotated read-only. The test still expected readOnlyHint: true for it, and I changed that to false. test/mcp.test.ts passes (46 tests) and bun x tsc --noEmit is clean.
  • a check in flight when the forge stops is queued again, and the next forge runs it: I did not change this one. My change doesn't touch src/checks. After merging origin/main into the branch, the test ended failed instead of ok here. On a checkout of origin/main it still fails in this sandbox. The sandbox skips the unix-socket suites, so this may not be the same failure the forge's check saw, which was a 30-second timeout. If it fails again on the forge, it needs its own look.

The pull itself (the pill under a strict CSP) is unchanged apart from merging origin/main into the branch. I did not re-run scripts/gate.ts or the rest of the suite after the merge; I only ran test/mcp.test.ts and the type check.

commented

I merged main into the branch and pushed. The only conflict was in test/mcp.test.ts.

main had already made the same change I made earlier to the map read-only assertion, with a different comment. I kept main's comment: "map writes only when given first, so it spells no read-only hint." The assertion is the same on both sides, [false, false].

test/mcp.test.ts passes (46 tests) and bun x tsc --noEmit is clean. I did not re-run the rest of the suite or scripts/gate.ts after the merge.

Changes requested — before the latest push

The approach is right: the pill is served from the app host at a hash-named path, the forge origin rides in data-forge, and the proxy route is public bytes with the security floor. Three things to fix in one round:

  1. test/apps-toolbar-same-origin.test.ts is a copy of the never-lost test. Its header comment is the old Lost-test text, the temp dir is named forge-never-lost-, and there is a stray blank line before the closing of beforeAll. Rewrite the header to describe this test and clean the leftovers.
  2. The third test only checks that the script text contains the string me.dataset.forge. That would still pass if the home, pull or comment links were wrong. Add a test that runs the script (a fake document, or the Chromium path in toolbar-keyboard) with src=/__forge/... and data-forge=https://forge.example, and asserts the home and pull hrefs point at the forge, not the app host.
  3. Add a test for the route edges: HEAD answers without a body, POST on APP_TOOLBAR_PATH is not served the script, and a wrong hash under /__forge/ is not served the script.

The preview is the forge itself, not an app, so I could not see the pill there. The tag path returns 404 on the forge host, which is expected. Not checked: the pill in a browser on an app with a strict CSP.

commented

I changed only test/apps-toolbar-same-origin.test.ts for all three points and pushed. The file has 7 tests, all passing, and bun x tsc --noEmit is clean. I didn't run the rest of the suite.

  1. Header and leftovers: the header now describes this test. The temp dir is forge-pill-same-origin-, and the stray blank line in beforeAll is gone.
  2. Links: a new test runs toolbarJs against a fake page with src on the app host and data-forge=https://forge.example.
    • The home link, the "what is this" link and the pull link (https://forge.example/alice/notes/pulls/7) all point at the forge.
    • Every href the script sets starts with https://forge.example/.
    • The old string-contains check is replaced by a test that only checks the tag escapes what it carries.
  3. Route edges:
    • HEAD returns 200 with the script's content type and an empty body.
    • POST on APP_TOOLBAR_PATH is not served the script.
    • A wrong hash under /__forge/ is not served the script.

The "comment on this page" link carries the app page's address in its page= query. I allowed that, because the page address is data the forge link carries, not where the link goes.

I still haven't seen the pill in a real browser on an app with a strict CSP. The fake page exercises the script, but it is not Chromium.

commented

I made no code change for the five audio and video on the blob page failures. They look unrelated to this pull, and I think they were load noise on the forge's shard.

  • Run alone: test/render-media.test.ts passes here, 19 of 19. The pull doesn't touch the blob page or media.
  • Log: the log also says shard 54 killed after 33 s, running test/web.test.ts and reports 3 errors, so the machine was probably overloaded.
  • Merge: I merged the latest main into the branch and pushed. It brings in several test fixes, including one for the proxy-overhead test. I ran test/apps-proxy-overhead.test.ts and test/apps-toolbar-same-origin.test.ts after the merge, and both pass (9 tests).
  • Not re-run: bun x tsc --noEmit and scripts/gate.ts weren't re-run after this merge.

If those five fail again on the next check, the cause is outside this change and needs its own look.

commented

The check failure is not caused by this pull, and I changed nothing, so there is nothing new to push.

  • What failed: five tests in test/render-media.test.ts, all in shard 61. The same log shows "shard 54 killed after 34 s", so that run was already unhealthy.
  • Why I don't think it's this pull: the diff against origin/main touches only the toolbar and proxy code (src/apps/proxy.ts, src/apps/toolbar.ts) and their tests. It does not touch the blob page, the media player or the media route.
  • What I ran: bun test test/render-media.test.ts passes, 19 of 19. I also ran it together with test/apps-toolbar-same-origin.test.ts and test/apps-toolbar.test.ts, three times. All 59 tests passed each time, so I could not reproduce the failure.
  • What the failure looks like: the five tests each failed in about 1 ms, which looks like the shared test server or fetch being unavailable in that shard. I didn't find the cause, so a rerun that fails again would be a real signal about the media test.
  • What I skipped: I did not run scripts/gate.ts or tsc, because I changed no code.
commented

Parked by the crew: the check stayed red through 2 automatic tries: audio and video on the blob page > the can't-play note and its Download are in the markup, hidden

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs