Skip to content

[Fable] security(browser): authenticate CDP proxy + restrict cookie-import staging perms - #5035

Closed
nwparker wants to merge 2 commits into
mainfrom
nwparker/security-cdp-cookie-hardening
Closed

nwparker wants to merge 2 commits into
mainfrom
nwparker/security-cdp-cookie-hardening

Conversation

@nwparker

@nwparker nwparker commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Security scan + hardening (browser/CDP surface)

Ran a multi-agent security scan of Orca across 12 attack-surface dimensions
(Electron process model, IPC validation, command injection, path traversal,
network/socket auth, web+mobile pairing & RPC allowlist, secrets/credentials,
browser/CDP automation, web-content XSS/SSRF, SSH transport/relay deploy,
auto-updater/supply-chain, and protocol deserialization). Each candidate finding
was adversarially verified by two independent skeptics — a reachability lens
(can an untrusted party actually reach it?) and an exploit-correctness lens
(does the code really do the unsafe thing?) — calibrated for an ADE threat model
where local privileged execution (running shells, spawning agents) is by design.

Net result: the codebase is well-hardened (sandboxed renderer, fail-closed guest
webviews, token-authed sockets, E2EE + per-device-token pairing). This PR fixes
the confirmed real issue plus one adjacent local-secrets hardening gap.


Fix 1 — Authenticate the CDP debugger proxy (primary)

CdpWsProxy (one per browser tab, drives agent-browser) bound
127.0.0.1:<random> and accepted any WebSocket connection with no auth,
forwarding arbitrary CDP commands (Runtime.evaluate, cookie reads, navigation,
screenshots) straight to the tab's webContents.debugger. The HTTP /json
discovery endpoints disclosed the debugger URL unauthenticated.

Threat: attacker-controlled web content in the built-in browser is explicitly
untrusted. It could discover the proxy port and open a WebSocket to it, gaining
full control of the tab's DOM/JS — a privilege crossing.

Fix (mirrors how Chrome's own CDP endpoint defends itself):

  • Embed a 144-bit random token in the debugger URL path; reject WS upgrades
    with a missing/wrong token (timing-safe compare).
  • Reject any WS upgrade carrying a browser Origin header — the local
    agent-browser client (native, non-browser) never sends one; page JS always does.
  • Gate /json discovery behind a loopback Host check (DNS-rebinding defense)
    and reject Origin-bearing requests, so it can't serve as a port oracle.

Transparent to agent-browser: it discovers the tokenized webSocketDebuggerUrl
via /json/version as a non-browser client (verified the bundled binary uses
/json discovery), then connects with the token in the path.

Fix 2 — Restrict cookie-import staging file permissions

The cookie-import staging dir under userData held a full copy of the browser
cookie database (session tokens), created with the default umask
(world-readable dir + 0644 file). In the post-restart import handoff path it
persists across a restart. On a shared/multi-user machine, another local
account could read the staged cookies.

Fix: create the staging dir 0700 (and chmod it, since recursive mkdir
leaves an existing dir's mode untouched) and the copied DB 0600.


Found but intentionally NOT fixed here (recommended follow-ups)

  • SSH host-key verification is absent (buildConnectConfig in
    ssh-connection-utils.ts): the in-process ssh2 transport sets no
    hostVerifier, so it accepts any host key (MITM-able on untrusted networks).
    A correct fix is a TOFU + key-mismatch UX feature (read known_hosts,
    prompt on first connect / on mismatch, persist decisions) — too large and
    product/UX-laden to land in a security patch. Worth a dedicated issue. (Note:
    Orca also has a system-ssh fallback transport which uses the OS
    known_hosts; the gap is specific to the in-process ssh2 path.)
  • WebAuthn/HID auto-grant for any https origin
    (browser-webauthn-access.ts): isSecureBrowserOrigin() returns true for
    any https:// origin, so a FIDO HID device is auto-selected without a user
    picker for arbitrary sites. Real-world impact is bounded by WebAuthn's
    user-presence (physical touch) and RP-ID binding, and tightening it risks
    breaking legitimate security-key login in the embedded browser — so it needs a
    deliberate decision (account/device picker UX) rather than a blind behavior
    change. Flagged for review.

Verified and dismissed (sample)

0.0.0.0 pairing bind (gated by E2EE + 192-bit per-device tokens), pre-auth WS
DoS (sockets reaped at 10s), grab-guest-script pre-poisoning, updater SSRF, and
relay-deploy MITM were all checked and found gated behind the trusted boundary or
existing crypto — not exploitable by an untrusted party.


Testing

  • vitest run on cdp-ws-proxy.test.ts (added 7 auth tests: token-gated WS,
    wrong/absent token, Origin rejection, loopback-Host and Origin gating on
    /json, happy path) + browser-cookie-import.test.ts — 38 passing.
  • Related browser suites (agent-browser-bridge, cdp-bridge-integration,
    cdp-screenshot) — 86 passing.
  • tsgo typecheck (node project) and oxlint on changed files — clean.
  • Recommended final gate: an /electron smoke test of live browser automation.

🤖 Generated with Claude Code

Made with Orca 🐋

nwparker and others added 2 commits June 9, 2026 11:36
The per-tab CDP proxy bound 127.0.0.1:<random> and accepted any WebSocket
connection, forwarding arbitrary CDP commands (Runtime.evaluate, cookie
reads, navigation) to the tab's webContents. The HTTP /json discovery
endpoints disclosed the debugger URL with no auth. Attacker-controlled web
content in the built-in browser could discover the port and drive the
debugger — full control of the tab's DOM/JS.

Defense, matching Chrome's own CDP endpoint design:
- Embed a 144-bit random token in the debugger URL path; reject WS upgrades
  that present the wrong/no token (timing-safe compare).
- Reject any WS upgrade carrying a browser Origin header (the local
  agent-browser client never sends one; page JS always does).
- Gate /json discovery behind a loopback Host check (DNS-rebinding defense)
  and reject Origin-bearing requests so it can't be used as a port oracle.

Transparent to agent-browser, which discovers the tokenized URL via
/json/version as a non-browser client (no Origin).

Co-authored-by: Orca <[email protected]>
The cookie-import staging directory under userData held a full copy of the
browser cookie database (session tokens). It was created with the default
umask (world-readable dir + 0644 file) and, in the post-restart import
handoff path, persists on disk across a restart. On a shared/multi-user
machine another local account could read the staged cookies.

Create the staging dir 0700 (and chmod it, since recursive mkdir leaves an
existing dir's mode untouched) and the copied DB 0600.

Co-authored-by: Orca <[email protected]>
@nwparker nwparker changed the title security(browser): authenticate CDP proxy + restrict cookie-import staging perms [Fable] security(browser): authenticate CDP proxy + restrict cookie-import staging perms Jun 9, 2026
@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks for flagging the unauthenticated CDP proxy. The web-page path is now closed on main by #27415, which refuses handshakes and discovery requests that carry an Origin or a non-loopback Host, the same policy Chrome uses for its debugging port.

@nwparker

nwparker commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded: the CDP proxy now rejects browser-origin and non-loopback requests (#27415) and requires a per-session token (#37938); cookie staging folders are already owner-only on main.

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.

2 participants