fix(security): allow only http(s) and about:blank on explicit navigation

Merged
OK
2mo ago
+210-57

Summary

  • view-source:file:///... slipped past the file: / data: / javascript: denylist: new URL() reports the protocol as view-source:, and Chromium then renders the wrapped local file. app.open, browser.goto, and the agent/MCP navigate verb all go through resolveNavigationUrl (packages/e2e/src/internal/urls.ts), so all three leaked file contents.
  • Fix: resolveNavigationUrl now uses an allowlist and admits http:, https:, and the exact about:blank. A denylist can't cover browser wrapper and nested schemes (view-source:, blob:, filesystem:, chrome:, ...). WHATWG parsing already lowercases the scheme and strips whitespace and tabs, so case and padding tricks resolve to the denied scheme. A percent-encoded scheme is read as a relative path on the base.
  • about:blank stays allowed because it loads no local or inline content and migrated suites use it. about:blank#x, about:srcdoc, and every other non-http(s) scheme are now POLICY_DENIED on explicit navigation. setCookies targets follow the same rule, and an about:blank cookie URL, which holds no cookie, is also POLICY_DENIED (packages/web/src/browser.ts).
  • Mobile (packages/mobile/src/links.ts): device links legitimately use custom app schemes (myapp://), so it keeps a denylist, which now adds view-source:, blob:, and filesystem:. It stays a separate check because the web rule is now a different rule (an allowlist). Sharing it would also mean a new e2e/engine export, which would raise mobile's e2e peer floor.
  • Docs and rule text: AGENTS.md security invariants, SECURITY.md, the packages/web/src/observation.ts frame comment, security.mdx, reference/{app,web,config,errors,engine,mobile}.mdx, browser.mdx, and skills/e2e/references/debugging.md now describe the http(s)-only rule.
await app.open('view-source:file:///etc/passwd');
// main:   page renders /etc/passwd
// branch: POLICY_DENIED: forbidden URL scheme: view-source:

Tests

  • tests/unit/urls.test.ts: each variant (view-source: file/http, upper case, leading spaces, tab/newline inside the scheme, blob:, filesystem:, chrome:, chrome-extension:, devtools:, about:blank#x, about:blank?x, about:srcdoc, about:version, ftp:, ws:, custom scheme) is denied with and without a base URL. Percent-encoded schemes stay paths. http(s) and exact about:blank controls still pass.
  • tests/integration/web-platform.test.ts: app.open with view-source: (3 spellings), blob:, and about:srcdoc, plus browser.goto('view-source:...'), run against a real marker file in the project. All fail POLICY_DENIED before anything loads. app.open and browser.goto still admit about:blank. setCookies with url: 'about:blank' is POLICY_DENIED.
  • tests/integration/mcp-server.test.ts: the MCP navigate verb refuses view-source:file:, VIEW-SOURCE:http:, and about:srcdoc.
  • mobile links, engine, and tools unit tests: openLink, openApp, and open_app refuse the wrapper schemes.
  • Reverting urls.ts to main fails 15 unit cases, the web-platform scheme test, and the MCP navigate tests.

Verified

Ran it locally: yes

  • Scratch project /tmp/oskar-fix-nav-scheme-bypass with a synthetic marker.txt, the real built CLI e2e run against a local http server, and a stdio MCP client that drives e2e mcp --headless.
Inputmainthis branch
app.open('view-source:file://…/marker.txt')page shows marker-B63-SECRET-local-file (leak)POLICY_DENIED: forbidden URL scheme: view-source:
app.open('VIEW-SOURCE:file://…')leakPOLICY_DENIED (view-source:)
app.open(' view-source:file://…')leakPOLICY_DENIED (view-source:)
app.open('view-source:http://127.0.0.1:4901/')renders page sourcePOLICY_DENIED (view-source:)
app.open('blob:http://…')ENGINE_FAILURE net::ERR_FILE_NOT_FOUND (navigated)POLICY_DENIED (blob:)
app.open('filesystem:http://…')ENGINE_FAILURE (navigated)POLICY_DENIED (filesystem:)
app.open('chrome://version')ENGINE_FAILURE net::ERR_INVALID_URL (navigated)POLICY_DENIED (chrome:)
app.open('about:blank')passespasses
app.open('about:srcdoc')passes the denylist (not in the main run)POLICY_DENIED (about:)
app.open('file://…')POLICY_DENIEDPOLICY_DENIED
browser.goto('view-source:file://…')leakPOLICY_DENIED (view-source:)
control: app.open('/') + browser.goto('http://…')passespasses
MCP navigate view-source:file://…Navigated to view-source:file://…, observe shows markernavigate … failed: POLICY_DENIED: forbidden URL scheme: view-source:
MCP navigate /passespasses
  • pnpm check, plus the e2e, @e2e-dev/web, and @e2e-dev/mobile test suites. The testbed (70 passed) and the web-benchmark (90 passed) ran on private ports.