Skip to content

fix(browser): stop exposing DevTools on a loopback TCP port - #482

Merged
ElbertePlinio merged 10 commits into
mainfrom
fix/459-cdp-pipe
Oct 30, 2026
Merged

ElbertePlinio merged 10 commits into
mainfrom
fix/459-cdp-pipe

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

A browser session's Chrome served DevTools on a loopback TCP port. Any local process could find and drive it, and after teardown another process could take the freed port.

Chrome now runs with --remote-debugging-pipe. The browser supervisor owns the pipe and serves it on a 0600 Unix socket, with a 0600 endpoint file. The DevTools relay connects with a ws+unix: endpoint and holds the session's one client slot. Each client gets its own browser session, so state it sets up ends when it leaves.

Proof: the full suite, real-Chrome tests, and QA journeys through the built CLI. Council review: Sol and Fable ran over 6 rounds. The Kimi seat did not run, because its Go usage limit was reached.

Closes #459

Rollback: revert the merge commit. Browser sessions made by this version then lose the relay and must be recreated. Sessions made by older versions work again.

Requirement Verification Scenario and edge cases Result Evidence
Chrome serves CDP only on the pipe, no TCP port Real-Chrome tests, QA journeys ss -ltnp for the session's processes before and after relay use; /json/version probed on every port Chrome owns No listener, no answer ~/.pickforge/investigations/459/qa/d373c23/results.json, .../owned-session/real-chrome-r4.log
Socket and endpoint file are private QA journeys, unit tests Modes of socket, its directory and endpoint file; symlinked, group-readable and foreign-socket endpoint files 0600, 0700, 0600; bad files refused with the reason .../qa/d373c23/results.json, .../owned-session/focused-r4.log
Status and DevTools helpers use the socket Unit tests, QA journeys Status of a live session, version read, named-profile close through POST /close Status works, cookie survives destroy and create .../qa/d373c23/status.txt, .../owned-session/real-chrome-r4.log
cdpPort removed from records and output Unit tests, QA journeys Create and status, text and --json, MCP results No cdpPort anywhere .../qa/d373c23/create.json, .../qa/d373c23/status.json
One relay per session Real-Chrome tests, QA journeys Second relay while one runs; reconnect after the first ends; stuck relay that stopped reading "already attached"; reconnect sees the page; slot freed at once .../qa/d373c23/results.json, .../owned-session/focused-r4.log
Legacy TCP sessions refused by the relay, destroy works QA journeys against a session made by main Status, relay, destroy of a session with cdpPort Status works, relay says destroy and recreate, all 15 processes end .../qa/legacy-b73c45a/
Next client starts clean Unit tests, real Chrome disposeOnDetach context, root tracing, download behavior, auto-attach, late attach reply, commands for sessions the client did not attach All end with the client; foreign sessions refused before Chrome .../worker-fix/probe1.log to probe3.log, .../owned-session/focused-r4.log
Bounded buffers Unit tests 1024 commands Chrome never answers; refusals a client does not read; session ids over 128 characters Client closed with 1008; the refusal and session id tests fail without their fixes .../owned-session/before-refusals-r5.log, .../owned-session/before-long-id.log, .../owned-session/supervisor-r5-*.log
Supervisor death leaves no browser Real Chrome SIGKILL of the supervisor Chrome exits on its own; destroy ends the group .../worker/supervisor-kill.log
Remote debugging flags stay refused Unit tests User-supplied --remote-debugging-port and --remote-debugging-pipe Refused .../owned-session/focused-r4.log
SECURITY.md and READMEs accurate Review Pipe, socket modes, same-user limit, per-client session, supervisor death Updated This PR
Full suite full-suite.sh on d373c23 Build, lint, typecheck, viewer build, vitest, cargo 3564 passed; 2 desktop-linux viewer tests failed and also fail on main (#480, #481); cargo 355 passed .../full-r7/

Reviews:

Round Revision Sol Fable
1 b875dda 7, findings fixed in a3a770b and b73c45a 8, findings fixed in a3a770b and b73c45a
2 b73c45a 9, no findings 8, should-fix fixed in 092d3f7
3 5de4163 refactor 10, no findings not run
4 092d3f7 8, should-fix fixed in f73188f 7, same should-fix
5 a029390 10, no findings 9, nit fixed in d373c23
6 d373c23 10, no findings 9, test margin nit fixed in a814a80

Evidence paths are under ~/.pickforge/investigations/459/ on the author's machine. Follow-ups found during validation: #480, #481.

Chrome now runs with --remote-debugging-pipe. The browser supervisor owns
the pipe, caches Browser.getVersion, and serves /json/version, one
websocket client and POST /close on a 0600 Unix socket in the session
temp directory. It publishes the socket in a 0600 cdp-endpoint file.
No TCP port exists, so cdpPort leaves records, status and CLI output.

The DevTools relay holds the session's one client slot and passes a
ws+unix: endpoint to chrome-devtools-mcp. A second relay fails with an
"already attached" error. Sessions from an older version still show in
status and destroy, but the relay refuses them.

Closes #459
The supervisor now opens a browser-target session for each websocket
client and runs the client's top-level commands there. Replies and
events of that session reach the client without its session id. Root
events and events of other sessions stay out. When the client leaves,
the supervisor detaches the session, and Chrome ends its tracing,
download behavior, auto-attach and contexts made with disposeOnDetach.

An attach reply that arrives after its client left is detached. A
client can have at most 1024 commands pending, and the commands of a
client that leaves are dropped. Ending a relay lease terminates its
websocket, so a relay that stopped reading frees the slot at once.
The relay reported an unsafe endpoint file, or one that names a socket
outside its session, as "No live browser session". It now says that the
session's DevTools endpoint file is unsafe and gives the reason. Session
create keeps polling such a file, and its timeout or exit diagnostics
now include the reason from the last read.
A client could name a session it never attached, such as one left by an earlier client, and the bridge forwarded the command to Chrome. The bridge now answers with the error Chrome gives for an unknown session. An endpoint file the relay refuses is now reported as one that cannot be used, since the reason is not always its permissions.
A client sees its own browser session as the root session, so a command that names it by id is refused like any other session the client did not attach.
The bridge answers a command for an unknown session itself, so pipe backpressure does not hold those replies back. A client that sends such commands faster than it reads is now closed at the same cap as one with too many commands pending.
A refusal echoes the session id the client sent, so the count cap alone did not bound the bytes it buffers. Chrome's session ids are 32 hex digits, so an id over 128 characters now makes the message invalid.
The refusal cap test relies on the kernel holding fewer refusals than it sends. Sending 50 times the cap keeps that true on hosts with large socket buffers.
@ElbertePlinio
ElbertePlinio merged commit 637be7b into main Oct 30, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/459-cdp-pipe branch October 30, 2026 02:24
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: move CDP off a TCP port onto --remote-debugging-pipe

1 participant