Skip to content

fix(browse): close v20 ABE cookie exfiltration window via --remote-debugging-pipe - #1181

Closed
NewCoder3294 wants to merge 5 commits into
garrytan:mainfrom
NewCoder3294:fix/cookie-import-pipe-transport
Closed

NewCoder3294 wants to merge 5 commits into
garrytan:mainfrom
NewCoder3294:fix/cookie-import-pipe-transport

Conversation

@NewCoder3294

Copy link
Copy Markdown

Resolves #1136.

What changes

Swaps the cookie-import Windows v20 ABE fallback from --remote-debugging-port (TCP, bindable by any same-user process during the 1-3s CDP window) to --remote-debugging-pipe (stdio pipes, inherited only by the spawning process). No TCP socket binds and no /json/list HTTP endpoint exists.

  • New CdpPipeTransport class — NUL-delimited JSON framing over Node-style streams (child.stdio[3] write, child.stdio[4] read). Unit-testable via PassThrough mocks.
  • New extractCookiesViaCdpPipe — uses Target.getTargets + Target.attachToTarget(flatten: true) + Network.enable + Network.getAllCookies over a single pipe connection.
  • importCookiesViaCdp rewritten: spawns with --remote-debugging-pipe, routes through the new transport. The TCP port randomizer, retry loop, and WebSocket helper are removed. The Chrome subprocess uses node:child_process.spawn (not Bun.spawn) because Bun returns raw numeric fds for stdio indices ≥ 3 and Node stream↔Web bridges hang in Bun on those sockets — this is the only place in the file that uses Node's child_process.
  • New exported buildCdpSpawnArgs(exePath, userDataDir, profile) helper — pure argv builder, unit-testable without spawning anything.
  • Comment block at the spawn site updated to reflect the new posture; the "KNOWN NON-GOAL" paragraph is gone.
  • chromeProc gets an explicit 'error' listener — without it, an async spawn failure (ENOENT, EACCES, AV interference) would crash the parent via Node's default handler.
  • Defensive guards: CdpPipeTransport flips closed = true on unexpected read-stream end so post-end send() rejects immediately; extractCookiesViaCdpPipe guards cookiesResp.cookies ?? [] and validates `attached.sessionId` is a non-empty string before use.

What does NOT change

The non-CDP cookie import path (SQLite + DPAPI for v10/v11 on macOS/Linux/Windows pre-ABE) is untouched. Tests for that path still pass.

Commits (bisectable)

  1. feat(browse): add CdpPipeTransport for --remote-debugging-pipe CDP — primitive, 9 unit tests
  2. feat(browse): add extractCookiesViaCdpPipe using CDP pipe transport — extractor, 4 unit tests
  3. fix(browse): switch cookie-import CDP from TCP port to stdio pipe — the fix, 4 unit tests for buildCdpSpawnArgs
  4. fix(browse): handle chromeProc spawn error events — hardening
  5. fix(browse): defensive hardening for cookie-import CDP pipe path — defensive guards + 3 tests

Testing

  • 20 new unit tests: CdpPipeTransport framing/error/close/post-end behavior (10), extractCookiesViaCdpPipe target selection, session scoping, domain filtering, missing-sessionId, missing-cookies-field (6), buildCdpSpawnArgs regression tests locking the --remote-debugging-pipe flag set (4).
  • Full bun test suite passes with no new failures vs base main. Four pre-existing failures on main are preserved unchanged: test/brain-sync.test.ts (bearer-json secret scan), test/skill-validation.test.ts (2MB fixture size), test/touchfiles.test.ts (skill selection count), test/model-overlay-opus-4-7.test.ts (pacing phrase). None of these relate to this change.

Windows v20 ABE integration smoke test was not run locally — developer machine is macOS. Happy to iterate on any Windows-specific feedback.

Out of scope (per issue)

  • Restructuring extractCookiesViaCdp[Pipe] for non-Chromium targets.
  • Switching the main browse daemon to pipe transport (separate concern).

Thin wrapper around two Node streams (Writable + Readable) that speaks
CDP with NUL-byte-delimited JSON framing. Handles id-based request/
response correlation and error/close propagation. Not wired into
anything yet; follow-up commits swap cookie-import's TCP CDP path
to use this.

Refs #1136.
Pipe-transport equivalent of extractCookiesViaCdp. Uses Target.getTargets
+ Target.attachToTarget(flatten: true) to acquire a page session over a
single CDP pipe connection, then Network.getAllCookies. Still not wired
into importCookiesViaCdp; next commit swaps the TCP path over.

Refs #1136.
Spawns Chrome with --remote-debugging-pipe instead of
--remote-debugging-port, closing the v20 ABE cookie exfiltration window
where any same-user local process could connect to Chrome's debug port
(in the 1-3s it's listening) and call Network.getAllCookies to read
decrypted v20 cookies.

Pipe transport is inherited by Chrome only; no TCP socket binds, no
/json/list HTTP endpoint exists. Target discovery via Target.getTargets
+ Target.attachToTarget(flatten: true). Browser.getVersion replaces the
old /json/version fetch for diagnostics.

Uses node:child_process.spawn for the Chrome subprocess because Bun.spawn
exposes fds >= 3 as raw numeric fds, not streams, and Node stream-to-Web
bridges hang in Bun on those sockets.

The non-CDP path (direct SQLite + DPAPI on v10/v11 cookies) is
unchanged; this change only affects the Windows v20 ABE fallback.

Closes #1136.
Adds an error listener on the Chrome child process. Without it, async
spawn failures (ENOENT, EACCES, antivirus interference) emit 'error'
with no handler and crash the parent process via Node's default
behavior. Errors surface via the transport's error path or the stdio
null-check guard.

Also tightens type casts at the CdpPipeTransport call site to reuse
the existing NodeWritable/NodeReadable aliases instead of inline
import('node:stream') references.

Refs #1136.
Three narrow robustness fixes flagged during review:

1. CdpPipeTransport.readStream 'end' handler now sets this.closed = true
   before aborting pending. Without this, a send() after end would queue
   a promise forever (the 'closed' guard wouldn't trigger).

2. extractCookiesViaCdpPipe guards cookiesResp.cookies with ?? [] so
   a CDP response missing the cookies field returns an empty array
   instead of throwing TypeError.

3. extractCookiesViaCdpPipe validates attached.sessionId is a non-empty
   string. flatten:true should always return one, but defensive guards
   beat silent fallback to the browser-level session.

Three new tests lock each fix:
- send-after-end rejects with cdp_error/closed
- empty getAllCookies response returns []
- attachToTarget without sessionId throws cdp_error

Refs #1136.
@time-attack

time-attack commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

@NewCoder3294 Rewrite the implementation to bound operations and prevent sends after terminal stream failures while retaining the listener removal.

@capy-ai

capy-ai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

The cookie-import transport implementation is superseded by merged #2964 (v1.90.0.0): the old TCP fallback is removed, and the replacement uses the Node/Playwright private-pipe path with owned-process supervision and bounded cleanup. Closing this alternative implementation without merging its branch. Native Windows encrypted extraction remains disabled by an empty qualification allowlist; #1136 stays open for its still-unmet Windows v20 import/qualification acceptance, not because the old TCP exposure remains.

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.

security: switch cookie-import-browser CDP from TCP port to --remote-debugging-pipe

2 participants