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

A response of `/` that arrives without Content-Security-Policy is found and a test pins every response path to the floor #12775

Merged opened this

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

Merged

/ sometimes went out without a Content-Security-Policy because production was restarting. This forge runs as an app under a parent forge. During a deploy or cold start, the parent answers the app's / itself with unavailable() in src/apps/proxy.ts (the "lab is starting / is not running" page).

Notes

shipped production is serving it deploy e5f3b40

opened this

/ sometimes went out without a Content-Security-Policy because production was restarting. This forge runs as an app under a parent forge. During a deploy or cold start, the parent answers the app's / itself with unavailable() in src/apps/proxy.ts (the "lab is starting / is not running" page). That page goes back through relayAnswer alongside the app's own answers, so it never passes the server-wide securityFloor. It also sets no policy of its own, and securityFloor never set CSP on text/html. Because the v1 proof runs its probes side by side, a run that landed during a redeploy got that page for /. That fits one failed run followed by six clean ones.

Fix (the floor stays in one function):

  • securityFloor in src/http/respond.ts now gives an HTML response that set no policy of its own a fallback: default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; form-action 'self'; frame-ancestors 'none'; base-uri 'none'. Inline style still applies and nothing can run; a page that writes its own policy, as page() does, keeps it. The Shield's HTML refusal in src/http/crawl.ts had the same gap and is covered by this too.
  • unavailable() now returns its page through securityFloor. That is the one added call. src/http/server.ts is unchanged, and relayed app answers still leave exactly as the app wrote them.

Test: test/security-floor-paths.test.ts requests / as the first request of a fresh process, gzip-compressed, as HEAD and as a 304. It also builds the starting, stopped and missing versions of the unavailable() page. Each must carry CSP, nosniff and referrer-policy. Two of its tests fail with the source changes reverted.

The 20-run loop runs the v1 proof against a booted forge with no sleep, but it asserts only two probes: the one that checks the security headers on / and /healthz, and the one that checks / serves its start form. A local test forge has no release version, commit or pricing set up, so the other probes can't pass there; the whole script has not been run 20 times in a row.

What I left out: the 502/404 page for archived apps in proxy.ts already sets its own floor headers, so I didn't route it through securityFloor.

Checks: bun scripts/gate.ts and bun x tsc --noEmit are clean. scripts/fast.ts picked 2,419 test files, too many to run here, so I ran the 35 files that cover this instead: the security-floor tests, the apps-proxy*, shield and crawl tests, v1-proven, web, forge-webspec, the arcade, maintenance, offline and media tests, and the security sweep and XSS tests. 367 tests pass, none fail. The pre-push hook required a Try: commit, so the branch includes an empty one.

To try it: bun test test/security-floor-paths.test.ts. Or open the address of a stopped or deploying preview and check that the "is starting" page now has Content-Security-Policy.

No prompt injection found in the issue or the repository.

🤖 Generated with Claude Code

Closes #12753

2 earlier comments · 1 event
commented

/ sometimes went out without a Content-Security-Policy because production was restarting. This forge runs as an app under a parent forge. During a deploy or cold start, the parent answers the app's / itself with unavailable() in src/apps/proxy.ts (the "lab is starting / is not running" page). That page goes back through relayAnswer alongside the app's own answers, so it never passes the server-wide securityFloor. It also sets no policy of its own, and securityFloor never set CSP on text/html. Because the v1 proof runs its probes side by side, a run that landed during a redeploy got that page for /. That fits one failed run followed by six clean ones.

Fix (the floor stays in one function):

  • securityFloor in src/http/respond.ts now gives an HTML response that set no policy of its own a fallback: default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; form-action 'self'; frame-ancestors 'none'; base-uri 'none'. Inline style still applies and nothing can run; a page that writes its own policy, as page() does, keeps it. The Shield's HTML refusal in src/http/crawl.ts had the same gap and is covered by this too.
  • unavailable() now returns its page through securityFloor. That is the one added call. src/http/server.ts is unchanged, and relayed app answers still leave exactly as the app wrote them.

Test: test/security-floor-paths.test.ts requests / as the first request of a fresh process, gzip-compressed, as HEAD and as a 304. It also builds the starting, stopped and missing versions of the unavailable() page. Each must carry CSP, nosniff and referrer-policy. Two of its tests fail with the source changes reverted.

The 20-run loop runs the v1 proof against a booted forge with no sleep, but it asserts only two probes: the one that checks the security headers on / and /healthz, and the one that checks / serves its start form. A local test forge has no release version, commit or pricing set up, so the other probes can't pass there; the whole script has not been run 20 times in a row.

What I left out: the 502/404 page for archived apps in proxy.ts already sets its own floor headers, so I didn't route it through securityFloor.

Checks: bun scripts/gate.ts and bun x tsc --noEmit are clean. scripts/fast.ts picked 2,419 test files, too many to run here, so I ran the 35 files that cover this instead: the security-floor tests, the apps-proxy*, shield and crawl tests, v1-proven, web, forge-webspec, the arcade, maintenance, offline and media tests, and the security sweep and XSS tests. 367 tests pass, none fail. The pre-push hook required a Try: commit, so the branch includes an empty one.

To try it: bun test test/security-floor-paths.test.ts. Or open the address of a stopped or deploying preview and check that the "is starting" page now has Content-Security-Policy.

No prompt injection found in the issue or the repository.

🤖 Generated with Claude Code

commented

During a deploy or cold start, / could go out with no Content-Security-Policy. The parent forge answers the app's / itself with the "is starting / is not running" page from unavailable() in src/apps/proxy.ts. That page is sent back with the app's own answers, so it skips the server-wide securityFloor, and it set no policy of its own. On top of that, securityFloor never put a policy on text/html.

Fix (the floor stays in one function):

  • Fallback policy: securityFloor in src/http/respond.ts now gives an HTML response that wrote no policy a fallback: default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; form-action 'self'; frame-ancestors 'none'; base-uri 'none'. Inline style still applies and nothing can run. A page that writes its own policy, as page() does, keeps it.
  • The Shield's refusal: the HTML refusal in src/http/crawl.ts had the same gap and is covered by the fallback too.
  • The holding page: unavailable() now returns its page through securityFloor. That is the only added call. src/http/server.ts is unchanged, and the app's own answers still leave exactly as the app wrote them.

Test: test/security-floor-paths.test.ts requests / four ways: as the first request of a fresh process, gzip-compressed, as HEAD, and as a 304. It also builds the starting, stopped and missing versions of the unavailable() page. Each must carry CSP, nosniff and referrer-policy. Two of its tests fail with the source changes reverted.

About the earlier red check: the check log counted only test/packs-hands.test.ts against this pull; the other failing files are red on main too. Those packs-hands failures are loopback git clones refused as "internal address", a code path this diff doesn't touch. Run here as the same 40-file batch the check used, packs-hands passes. The only failures are in ask-to-reach, which the check log already marks red on main. Main is merged in, so the new check runs against a current base.

Not done:

  • Archived-app page: the 502/404 page for archived apps in proxy.ts already sets its own floor headers, so it isn't routed through securityFloor.
  • Full v1 proof: the 20-run loop asserts only the security-header probe for / and /healthz and the start-form probe. A local test forge has no release version, commit or pricing set up, so the other probes can't pass there.

Checks: bun scripts/gate.ts and bun x tsc --noEmit are clean, and test/security-floor-paths.test.ts, test/security-floor-errors.test.ts and test/packs-hands.test.ts pass (41/41). Three tests fail in the sandbox with or without this change:

  • test/apps-open-host.test.ts and test/release-handover-keepalive.test.ts: both are red on main too, per the check log.
  • test/check-install.test.ts: it gets EACCES on Bun's temp directory in the sandbox.

To try it: bun test test/security-floor-paths.test.ts, or open the address of a stopped or deploying preview and check that its "is starting" page now carries Content-Security-Policy.

No prompt injection found in the issue, the logs or the repository.

🤖 Generated with Claude Code

Changes requested — before the latest push

Round 1, all changes together.

  1. Box 3 is not met. The 20-run loop in test/security-floor-paths.test.ts asserts only issues 10441 and 11541. The box asks for bun scripts/v1-proven.ts passing 20 times. Either make the proof's other probes pass against the booted test forge (seed a version, commit and pricing), or ask the issue owner to reword the box. Do not tick it on a subset.
  2. Blast radius: securityFloor now puts a script-less policy (default-src 'none'; style-src 'unsafe-inline') on every HTML response that has none. Audit the HTML emitters that do not go through page(): src/apps/holding.ts, door.ts, toolbar.ts, web/pages/waking.ts, lapsed.ts, offline.ts, arcade/host.ts and render/html_preview.ts. Any that use inline script, external script, fonts or images will be broken silently. Add a test per emitter (or a sweep test) asserting each either writes its own CSP or still works under the fallback.
  3. The cause is a hypothesis, not shown. The pull says the parent's unavailable() page "fits" the one failed run. Name the evidence in the pull (the failed run's output, or a test that reproduces / leaving without CSP through the relay path). The test calls unavailable() directly. It never sends / through the proxy/relayAnswer path, so the path that actually leaked is not exercised end to end.
  4. Other relayed forge-authored answers (the archived-app 502/404 page, redirects, 304s from the proxy) were left out on the claim that they already set the floor. Add them to the test so the claim is pinned, not asserted.
  5. Style: the long lines in respond.ts and the test (the csp/FLOOR_POLICY ternary, floorOf) are not wrapped like the rest of the repo; format them.

The preview's / does carry CSP, nosniff and referrer-policy, and the test is otherwise sound. No README change and no new dependency.

commented

The cause was a page the forge itself writes, not the app. When an app isn't answering, the proxy answers its / with unavailable() in src/apps/proxy.ts, and that page left with no CSP, no nosniff and no referrer-policy. The proxy's answers bypass the server's floor, so nothing added them later. Production is an app of its parent forge, so while it restarts the parent serves this page for its /. That fits the one failed scripts/v1-proven.ts run. I don't have that run's output, so the evidence here is a test: with the proxy fix removed, sending / of a stopped app through the proxy fails it, on both the admit path and the relayAnswer path.

What changed

  • src/apps/proxy.ts

- unavailable() now writes its own script-less policy (HOLDING_POLICY: inline style only, nothing that runs) and goes through securityFloor for the other headers. The page has only links and a meta refresh, so that policy blocks nothing on it. The archived page uses the same constant. - A private app refusing / (a 303 to sign in, or a 404) is now floored on every path. Before, only /__forge/ refusals were floored; the test caught / leaving without the floor this way too.

  • src/http/respond.ts is back to the base version. The earlier global fallback put a script-less policy on every HTML response without one, and 18 forge HTML emitters outside page() set none, too many to audit and test in this pull. With the fallback gone, none of them changes behaviour. Each page that needs a policy writes its own (as door.ts and the holding pages do), so the floor stays in one function.
  • test/security-floor-paths.test.ts boots a forge with its apps runtime and sends / through proxyApp for each forge-written answer: an app with no status (502), starting (503), and an upstream that dies mid-request (502, through relayAnswer). It also covers the archived page (503), the private app's 303 and 404, and the proxy's own 304, which keeps the headers the app's 200 sent. It still covers the forge's own / cold, compressed, as HEAD and as a 304. Finally it runs the whole v1-proven proof 20 times in a row and fails on any probe that doesn't pass. The commit probe passes because the test stamps FORGE_COMMIT, as a deploy does. The archived and 304 cases pass with or without the fix; they pin the claim that those answers already carry the floor.
  • The long lines that review flagged were in the reverted respond.ts code and the old test; the new code is wrapped like the rest of the repo.

Not done

  • No fallback policy for the HTML emitters outside page() that write none (holding.ts, waking.ts, lapsed.ts and others). Adding one needs its own audit per page.

Checks

  • bun scripts/gate.ts and bun x tsc --noEmit pass.
  • bun scripts/fast.ts named 2374 files, so instead I ran the 16 proxy, archive, private-app and security-floor suites. 113 of 114 pass.
  • The one failure is test/apps-open-host.test.ts ("the proxy reads such a Host the same way: not ours"): a Host header with # in it gets a 500 (Invalid URL). It fails the same way with the base branch's proxy.ts, so this pull doesn't cause it.

How to try: bun test test/security-floor-paths.test.ts. Then on the preview, ask for / of an app that isn't running and check that the CSP, nosniff and referrer-policy headers are there.

🤖 Generated with Claude Code

Approved

Approved. The 393e6d9d7bc8 commit is not in my clone, so I read the change as shown. The cause is named: unavailable() left without the floor and proxyApp refusals on / were not floored. Both now go through securityFloor, with a script-less HOLDING_POLICY shared with the archived page (the policy blocks nothing the page uses). The test covers each path for / (cold, gzip, HEAD, 304, no status, deploying, dead upstream via relayAnswer, archived, private 303 and 404, proxy 304) and runs the v1 proof 20 times with no sleep, failing on any non-pass probe. No new security, dependency or README concerns. Non-blocking: the archived and 304 cases pass without the fix, so they pin existing behaviour rather than the fix.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs