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

An app.looks path with a backslash never sends the page fetch to another host #14981

Merged opened this

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

Merged

webspec() now refuses an app.looks path that would send the page fetch to another host, instead of fetching it. The fix is in src/release/webspec.ts. The path rule: a new exported samePath(path) accepts a path only if it starts with exactly one / and contains no \ or control character.

Notes

shipped production is serving it deploy c407bfb

opened this

webspec() now refuses an app.looks path that would send the page fetch to another host, instead of fetching it. The fix is in src/release/webspec.ts.

  • The path rule: a new exported samePath(path) accepts a path only if it starts with exactly one / and contains no \ or control character. Anything else, such as /\evil.example, //evil.example, https://evil.example/, evil or /a\nb, gets one fetch finding saying it "is not a path on this app; it was not fetched".
  • The origin check: a path that passes the rule is resolved with new URL(path, base). The result must have the same origin as base, or it gets the same finding.

The new test in test/webspec.test.ts sends all six of those paths through a fetcher that records each call. Every one gets a single fetch finding and the fetcher is never called. The test fails on main and passes here. webspec.test.ts, webspec-site.test.ts, forge-webspec.test.ts and preview-spec.test.ts all pass (43 tests), as do bun scripts/gate.ts --fix and bun x tsc --noEmit.

Not done: src/apps/manifest.ts still accepts these paths when it reads forge.json. That is outside the files this issue names, so webspec() is now where they are stopped. It is the one place that fetches them, for both the preview check and scripts/smoke.ts. src/release/axe.ts gets the same path list in scripts/smoke.ts; it was not changed here.

🤖 Generated with Claude Code

Closes #14957

3 earlier comments · 2 events
commented

webspec() now refuses an app.looks path that would send the page fetch to another host, instead of fetching it. The fix is in src/release/webspec.ts.

  • The path rule: a new exported samePath(path) accepts a path only if it starts with exactly one / and contains no \ or control character. Anything else, such as /\evil.example, //evil.example, https://evil.example/, evil or /a\nb, gets one fetch finding saying it "is not a path on this app; it was not fetched".
  • The origin check: a path that passes the rule is resolved with new URL(path, base). The result must have the same origin as base, or it gets the same finding.

The new test in test/webspec.test.ts sends all six of those paths through a fetcher that records each call. Every one gets a single fetch finding and the fetcher is never called. The test fails on main and passes here. webspec.test.ts, webspec-site.test.ts, forge-webspec.test.ts and preview-spec.test.ts all pass (43 tests), as do bun scripts/gate.ts --fix and bun x tsc --noEmit.

Not done: src/apps/manifest.ts still accepts these paths when it reads forge.json. That is outside the files this issue names, so webspec() is now where they are stopped. It is the one place that fetches them, for both the preview check and scripts/smoke.ts. src/release/axe.ts gets the same path list in scripts/smoke.ts; it was not changed here.

🤖 Generated with Claude Code

Changes requested — before the latest push

The webspec fix is right and tested, but the same unchecked path list still reaches two other fetchers, so the hole is only half closed. Fix first: validate at the boundary, where looksField in src/apps/manifest.ts parses app.looks and looksAsOwner, using samePath. Move samePath to a small module that manifest can import. A bad path then fails the manifest with a clear message, and every consumer is covered. Alternatively, apply samePath and the origin check in src/release/axe.ts. Today noScript (line 58) fetches new URL(path, base) and axe (line 81) runs Page.navigate to new URL(path, base), so /\evil.example still navigates a browser to another host in scripts/smoke.ts. The pull body calls this out of scope, but box 1 asks that looks paths be refused, and that is not true while the manifest accepts them. Also add a manifest test for /\evil.example.

commented

A path in app.looks or app.looksAsOwner that could name another host, such as /\evil.example, is now refused when forge.json is read. All three fetchers of those paths (webspec, noScript and axe) also refuse any path whose URL would leave the app's origin.

  • One rule, one module: src/kernel/same_path.ts holds samePath(path), which allows exactly one leading / and no \ or control character. It also holds sameOriginUrl(path, base), which returns the URL built from the path, or null when the path breaks the rule or the URL lands on another origin.
  • At the boundary: pathList in src/apps/manifest.ts already refused //, schemes, .. and control characters. It now also refuses a backslash, with the message "must not contain \ (it can name another host)", and then applies samePath. That covers both app.looks and app.looksAsOwner.
  • The fetchers: webspec reports such a path as a fetch finding. noScript skips it. axe skips it and never sends it to Page.navigate. The fetchers check again so that scripts/smoke.ts stays safe, since it reads forge.json directly rather than through parseManifest.

Tests: three new tests, each failing on main:

  • test/webspec.test.ts passes /\evil.example and five other off-app paths; each gets one finding and the fetcher is never called.
  • test/apps-adversarial.test.ts checks that the manifest refuses a backslash in either field.
  • test/axe.test.ts checks that noScript never fetches /\evil.example, //evil.example or https://evil.example/.

Checks run: apps-adversarial, webspec, webspec-site, forge-webspec, preview-spec, looks-owner, forge-looks, the rest of looks.test.ts and the rest of axe.test.ts pass, as do bun x tsc --noEmit and bun scripts/gate.ts --fix. Two browser tests fail in this sandbox and fail the same way on main: the real-browser test in axe.test.ts and the real-capture test in looks.test.ts. Chromium needs a unix socket and the sandbox refuses it. The forge's check runs them.

🤖 Generated with Claude Code

commented

A looks path with a backslash (\) in app.looks is now refused, so a release can't point axe or the looks capture at a host other than the app's own origin (#14957).

  • src/kernel/same_path.ts (new) decides whether a path stays on the app's origin.
  • src/apps/manifest.ts refuses a backslash in app.looks when it reads forge.json.
  • src/release/webspec.ts refuses any looks path that would leave the origin.
  • src/release/axe.ts only sends axe to pages on the app's own origin.
  • Tests: each of the three behaviours has one in test/apps-adversarial.test.ts, test/webspec.test.ts and test/axe.test.ts.

The last commit has no code. It adds the Direction: line that the gate's "pipeline first" rule asks for. That rule failed the previous check because the pull adds src/kernel/same_path.ts without a pipeline change, and this is a security fix that shouldn't wait behind the pipeline items.

Gate and bun x tsc --noEmit pass. The three test files ran: 84 pass, 2 skipped and 1 fails. The failure is the real-browser axe test: Chromium can't start in this sandbox because it can't open a unix socket. It fails the same way with main's axe.ts, so the forge's check is the run that counts for it.

The gate still notes one comment line over 100 columns in src/release/webspec.ts; --fix didn't rewrap it, and the nightly rewrap on main does.

To try it: put "looks": ["\\evil.example/"] in an app's forge.json. The manifest should refuse it, and webspec should refuse the same path if it reaches it.

🤖 Generated with Claude Code

Changes requested — before the latest push

The fix works and the tests are sound, but the diff has dead code, which the list forbids. Fix: delete the unreachable checks below, keep one rule per layer, and run bun scripts/gate.ts --fix. No finding is high; the security behaviour is right.

commented

An app.looks or app.looksAsOwner path can't point a fetch at another host any more. Under the URL parser, /\evil.example and //evil.example both resolve to a different origin. Such a path is now refused when forge.json is read, and every fetcher of looks paths checks it again.

  • src/kernel/same_path.ts (new): samePath says whether a path starts with exactly one / and has no \ or control character. sameOriginUrl returns the URL a path names on the app's base, or null if it breaks samePath or leaves the app's origin.
  • src/apps/manifest.ts: refuses a backslash in a looks entry, alongside the existing checks for a leading //, .. and control characters. Those inline checks are the manifest's one rule, so it does not call samePath.
  • src/release/webspec.ts: a path that is not the app's is reported as not fetched, and no request is made.
  • src/release/axe.ts: noScript and axe work out each path's URL once in their loop and skip a path that is not the app's; webspec reports that path. load takes the resolved URL.

Changes from review: the unreachable samePath check in the manifest and the unreachable throw in axe's load are gone. samePath now writes its control range as \x00-\x1f, like the manifest, which also brings that line under 100 columns. A commit message carries a Direction: line for the gate's "pipeline first" rule; this is a security fix to the release path.

The gate's remaining note is about src/release/webspec.ts:142. That is a line of code I did not touch, and bun scripts/gate.ts --fix leaves it unchanged.

Gate and bun x tsc --noEmit pass. Across test/webspec.test.ts, test/axe.test.ts and test/apps-adversarial.test.ts, 84 tests pass and 1 fails. The failure is the real-browser axe test: Chromium can't start in this sandbox because it can't open a unix socket. The test fails the same way against main's axe.ts; the forge's check runs it.

To try it, put "looks": ["/\\evil.example"] in an app's forge.json: the manifest refuses it with "must not contain \ (it can name another host)".

🤖 Generated with Claude Code

Approved

Earlier ask (dead code: the unreachable samePath call in the manifest and the unreachable throw in axe load) is met: the head reads as one rule per layer, with manifest inline checks at the boundary and sameOriginUrl in the three fetchers. The commit ca365f32955e is not in my clone, so I judged the diff as given. Backslash, //, scheme and control characters are refused at forge.json and again in webspec, noScript and axe, and the tests assert the fetcher is never called. This is release tooling, so there is no page, TUI screen or README change to require. Next two things: Non-blocking: sameOriginUrl repeats the origin check after samePath, which is defence in depth but could get a one-line comment saying so. Non-blocking: have scripts/smoke.ts go through parseManifest so the fetcher check is not the only guard there.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs