fix(security): allow only http(s) and about:blank on explicit navigation
Merged
OK
2mo ago+210+210+012345678901234567890123456789-57-57-01234567890123456789
Summary
view-source:file:///...slipped past thefile:/data:/javascript:denylist:new URL()reports the protocol asview-source:, and Chromium then renders the wrapped local file.app.open,browser.goto, and the agent/MCPnavigateverb all go throughresolveNavigationUrl(packages/e2e/src/internal/urls.ts), so all three leaked file contents.- Fix:
resolveNavigationUrlnow uses an allowlist and admitshttp:,https:, and the exactabout: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:blankstays 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 nowPOLICY_DENIEDon explicit navigation.setCookiestargets follow the same rule, and anabout:blankcookie URL, which holds no cookie, is alsoPOLICY_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 addsview-source:,blob:, andfilesystem:. It stays a separate check because the web rule is now a different rule (an allowlist). Sharing it would also mean a newe2e/engineexport, which would raise mobile'se2epeer floor. - Docs and rule text:
AGENTS.mdsecurity invariants,SECURITY.md, thepackages/web/src/observation.tsframe comment,security.mdx,reference/{app,web,config,errors,engine,mobile}.mdx,browser.mdx, andskills/e2e/references/debugging.mdnow 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 exactabout:blankcontrols still pass.tests/integration/web-platform.test.ts:app.openwithview-source:(3 spellings),blob:, andabout:srcdoc, plusbrowser.goto('view-source:...'), run against a real marker file in the project. All failPOLICY_DENIEDbefore anything loads.app.openandbrowser.gotostill admitabout:blank.setCookieswithurl: 'about:blank'isPOLICY_DENIED.tests/integration/mcp-server.test.ts: the MCPnavigateverb refusesview-source:file:,VIEW-SOURCE:http:, andabout:srcdoc.- mobile
links,engine, andtoolsunit tests:openLink,openApp, andopen_apprefuse the wrapper schemes. - Reverting
urls.tsto 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-bypasswith a syntheticmarker.txt, the real built CLIe2e runagainst a local http server, and a stdio MCP client that drivese2e mcp --headless.
| Input | main | this 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://…') | leak | POLICY_DENIED (view-source:) |
app.open(' view-source:file://…') | leak | POLICY_DENIED (view-source:) |
app.open('view-source:http://127.0.0.1:4901/') | renders page source | POLICY_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') | passes | passes |
app.open('about:srcdoc') | passes the denylist (not in the main run) | POLICY_DENIED (about:) |
app.open('file://…') | POLICY_DENIED | POLICY_DENIED |
browser.goto('view-source:file://…') | leak | POLICY_DENIED (view-source:) |
control: app.open('/') + browser.goto('http://…') | passes | passes |
MCP navigate view-source:file://… | Navigated to view-source:file://…, observe shows marker | navigate … failed: POLICY_DENIED: forbidden URL scheme: view-source: |
MCP navigate / | passes | passes |
pnpm check, plus thee2e,@e2e-dev/web, and@e2e-dev/mobiletest suites. The testbed (70 passed) and the web-benchmark (90 passed) ran on private ports.