Skip to content

fix(browser): bind the DevTools relay to its own session Chrome - #452

Merged
ElbertePlinio merged 9 commits into
mainfrom
fix/444-devtools-relay-session
Oct 29, 2026
Merged

ElbertePlinio merged 9 commits into
mainfrom
fix/444-devtools-relay-session

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Closes #444

The Chrome DevTools MCP relay for a browser session could reach another Chrome after its own session ended. On origin/main, a relay kept open after session destroy still forwarded calls, and its chrome-devtools-mcp child reconnects to the --browser-url it was given. When a second Chrome later listened on the same loopback port, list_pages and take_snapshot through the relay returned that browser's pages and content.

The relay now has two layers:

  1. The child gets --wsEndpoint ws://127.0.0.1:<port>/devtools/browser/<guid> instead of --browser-url. The relay reads the endpoint in memory from the session Chrome's own private profile (DevToolsActivePort, no-follow, bounded) or, for a named profile, through the existing pinned profile path. Chrome makes a new GUID at each launch, so a new Chrome on the same port answers 404 on every connect and reconnect.
  2. Before each tools/call, the relay checks that the session record exists and is running, its input is open, and its Chrome is the same live process (pid and start ticks). After a check fails, every later call gets error -32051 with a fixed message that holds no ids, ports or content. A check that cannot read the session refuses only that call with -32052 and checks again next time. tools/list, notifications and the human lease check work as before.

The GUID is now on the child's command line. Local processes can already read it from the loopback /json/version endpoint, and nothing persists it; SECURITY.md says so.

Traceability

Requirement Verification Scenario and edge cases Result Evidence
Check whether the relay stops when its session ends Scripted run of the built CLI relay with a real session in a temporary PICKFORGE_HOME Destroy the session while the relay stays open; call list_pages; start a second headless Chrome with a private profile on the same port; call list_pages and take_snapshot On origin/main: the relay and child kept running and returned the second Chrome's page and content. On the fix: both calls fail with -32051 and contain nothing from the second Chrome ~/.pickforge/investigations/444/step1-repro.mjs, step1-result-origin-main.json, step1-result-fixed.json
Never attach to another Chrome on the old port devtools-real.test.ts with real Chrome, end to end through the CLI relay; pinned child test with the gate not applied After destroy with a second Chrome on the port; the relay's own Chrome killed and replaced on the same port Both calls refused with -32051; the pinned child gets 404 and reads nothing. Both real tests fail on origin/main showing the other Chrome's content failing-before-devtools-real.log, pinned-child-error.json, after-cli-tests.log
Verify the session before each forwarded call createSessionEndedIntercept unit tests Live session passes; record destroyed; input closed before the record is removed; status leaves running and stays refused if it returns; Chrome identity changed or dead; tools/list and notifications pass; a check that cannot read the record refuses only that call (-32052) Pass. Eight unit tests fail on origin/main; the -32052 test fails on the first revision of this fix failing-before-devtools-mcp-unit.log, r2/before-latch.log, r2/browser-tests.log
Endpoint resolution fails closed Resolver and session tests with fake Chrome Ephemeral and named profiles; unreadable or mismatched DevToolsActivePort Pinned endpoint, or a refusal after-browser-tests.log
Docs SECURITY.md and README describe the pinned endpoint, the gate, the GUID on the child's command line, and the window that remains Done this diff
Browser, CLI and security tests PICKFORGE_REQUIRE_BROWSER=1 bunx vitest run packages/browser/test; CLI relay files; test/security 233, 18 and 166 passed r2/browser-tests.log, r2/cli-tests.log, r2/security-tests.log
Full suite full-suite.sh build, lint, typecheck, viewer build, vitest coverage, cargo Pass at 5841308 (f1d6061 with main merged): 3513 passed, 4 skipped; cargo 351 passed ~/.pickforge/investigations/444/full/
PickCheck and secret scan pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits 60 files checked 0 new or worsened violations (resolveLiveBrowserSession bool_ops is unchanged from main); no leaks pickcheck.json

Evidence paths are under ~/.pickforge/investigations/444/.

Known limit: a call that passed the check just before the session ended can still connect after its Chrome exits. A local process that binds the freed port in that moment could answer the call or forward it to another browser. SECURITY.md already states that any local process can drive every session's browser over loopback CDP, so this gives such a process nothing new. Moving CDP to --remote-debugging-pipe, which SECURITY.md lists as planned hardening, would remove the port.

Review

Council, three seats per round.

Round Revision Sol Fable Kimi
1 073a78b 3 9 not run (usage limit)
2 15c9828 9 9 not run

Round 1, Sol: a call already forwarded before teardown can connect after Chrome exits, and a hostile listener on the freed port can redirect it to another Chrome (the bundled WebSocket client follows redirects). Declined as out of the threat model above and documented in SECURITY.md. Round 1, Fable: a transient read error during the check ended the relay for good; fixed in 20228d4. Its nits, the SECURITY.md wording and a root-only test assumption, are fixed in 15c9828. Accepted without change: profileBrowserEndpoint does not run the named-profile privacy check on the ephemeral profile directory, which the session creates with mode 0700.

ff03fac splits isRelaySessionCurrent into steps to meet PickCheck's boolean operator limit. Sol checked it and found one difference: it skipped the record read when the pinned leg was missing, which turned a retryable read error into the session-ended latch. f1d6061 restores the old read order. Sol rechecked f1d6061 against 15c9828: 10/10, no findings.

The relay passed --browser-url http://127.0.0.1:<port> to the upstream
child. After the session was destroyed, the child reconnected to that URL
on the next tool call and attached to any other Chrome that later listened
on the same port.

Pin the child to the session Chrome's per-launch websocket endpoint, read
from the session's own profile, so a later Chrome on the port is
unreachable. Before each tool call, recheck that the session is running,
its input is open and its Chrome is the same live process; once that
fails, every tool call returns a stable session-ended error.

Closes #444
A failed read during the session check ended the relay for good. It
now refuses only that call with its own error and checks again on the
next call. SECURITY.md names the window left for a call that passed
the check just before the session ended.
Root reads a record whose mode denies reading, so the test cannot make
the check fail there. Also point the SECURITY.md relay window at the
list below it.
@ElbertePlinio
ElbertePlinio merged commit 82b6869 into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/444-devtools-relay-session branch October 29, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

browser: check that the DevTools relay cannot reach another Chrome on its old CDP port

1 participant