Skip to content

fix(browser): authenticate sidecar stream and daemon - #784

Open
Zeus-Deus wants to merge 200 commits into
mainfrom
fix/browser-listener-auth
Open

Zeus-Deus wants to merge 200 commits into
mainfrom
fix/browser-listener-auth

Conversation

@Zeus-Deus

@Zeus-Deus Zeus-Deus commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Problem

The bundled browser sidecar accepted unauthenticated local requests on its stream WebSocket, stream HTTP API, and daemon command channel. Direct connections bypassed Codemux's desktop bridge and paired remote proxy. The flaw was confirmed in pinned v0.24.0 source and remained in the v0.44.0 source used by #758, which this PR stacks on.

Change

Build a Codemux-owned sidecar from pinned v0.44.0 source with an in-repo authentication patch. Codemux keeps a random per-launch secret in memory, derives a separate token for each browser session, and supplies it through managed CLI launches, the desktop bridge, and the authenticated remote proxy. The sidecar requires that token for WebSocket handshakes, every stream /api/* request, and Unix socket or Windows loopback daemon commands. Persistent session URLs contain no token; Unix control sockets live in owner-only directories. Previous daemons are used only after process and session identity verification.

The patched sidecar also requires a fresh daemon-owned confirmationId for each parked prompt before consuming a pending confirm or deny request, including prompts produced by replay. Managed browser operations require the patched binary version, have no PATH or package-runner fallback, and fail packaging when the patched binary is absent.

The macOS sidecar benchmark includes the production OS input module, and verified close cleanup retains its session value for the subsequent recovery check. A verified daemon from the previous unauthenticated build can be closed without a listener token only after private-record, process-start, prior-owner, environment, and connected-peer checks. Read-only viewport queries use an existing session and cannot create a pane.

Verification and base

  • Stacked on published fix(browser): require owned stream capabilities #758 head 90287500c825fd3e06a8f312d3eff246fcf7dbf9. Its exact-head CI run passed changes, Iroh/WASM, Ubuntu and Windows web and Rust, and ci-gate without a rerun. This PR is pushed at c2f92494194599dff2f191de75e2eb42ce1a2295.
  • On previous head f45eb07147f70cc4b26eed193e2aa11dfa4ce1be, local cargo check -j 2, close replay 7/7, confirmation 36/36, agent close 8/8, pane close 11/11, screenshot 17/17, authenticated Unix confirm/deny, stream token, and current/prior close token regressions passed. The real sidecar recovery/close and live listener smoke covered missing, wrong, cross-session, and correct tokens plus wrong confirmation IDs preserving the pending command. git diff --check passed.
  • Exact-head CI run 45939793967 failed: macOS sidecar benchmark compilation found a missing OS input module and a moved session value; Ubuntu Rust passed Cargo but an unrelated native provider smoke timed out. Windows Rust/native sidecar/Cargo/installer, both web jobs, changes, and Iroh/WASM passed. The final ci-gate failed with those jobs.
  • Prior head 7ec7df45febbd750a25ce70ef5bda2825ac3873f fixed the macOS compile errors. Local Linux app and benchmark checks, real patched-sidecar prior-launch token recovery/close, live listener smoke, and diff checks passed. Full exact-head CI run 45942173426 finished SUCCESS on attempt 2: macOS sidecar, Windows native/Cargo/installer, both web jobs, Iroh/WASM, changes, Ubuntu Rust, and ci-gate passed. Ubuntu Cargo passed on attempt 1; an unchanged native provider smoke timed out under runner scheduler load and passed on one failed-job rerun.
  • Mario's review of that head identified three blocking cases and one smoke-test gap. Current head c2f92494194599dff2f191de75e2eb42ce1a2295 fixes them. Local cargo check -j 2, the read-only viewport and listener identity Rust regressions, focused optimized sidecar confirmation tests, the rebuilt pinned sidecar, live WS/HTTP/daemon listener smoke, Node syntax, and diff checks passed. The macOS legacy migration fixture awaits full exact-head CI run 45989074051, which is in progress. This PR remains draft pending that run and latest-head review.

Remaining boundary

This is a partial listener fix. Chromium still starts with --remote-debugging-port=0; a local probe reached its unauthenticated /json/version endpoint. On a host where users share a network namespace, another local OS user can reach that CDP port, so this PR does not establish local-user browser isolation. Same-user code may also read the sidecar token from child process environments. The standalone upstream dashboard is outside Codemux's managed browser path and is not wired to the new token.

Implemented by GPT-6 via T3 Code's Codex harness.

…into security/browser-stream-capability

# Conflicts:
#	src-tauri/src/agent_browser.rs
…into security/browser-stream-capability

# Conflicts:
#	src-tauri/src/agent_browser.rs
…/browser-stream-capability

# Conflicts:
#	src-tauri/src/agent_browser.rs
…/browser-stream-capability

# Conflicts:
#	src-tauri/src/agent_browser.rs
…into security/browser-stream-capability

# Conflicts:
#	src-tauri/src/agent_browser.rs
…into security/browser-stream-capability

# Conflicts:
#	src-tauri/src/agent_browser.rs
…into security/browser-stream-capability

# Conflicts:
#	src-tauri/src/agent_browser.rs
@Zeus-Deus

Copy link
Copy Markdown
Owner Author

@mario-reviewer review

@mario-reviewer mario-reviewer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review of 7ec7df45febbd750a25ce70ef5bda2825ac3873f. No prior reviews were present.

  1. src-tauri/src/agent_browser.rs:2804 — Warning (blocking): macOS cannot retire a verified pre-upgrade daemon. browser_listener_token_for_close(record, session) returns no token for a surviving daemon from the unpatched build, so macOS never reaches its only shutdown path and stop_previous_browser_daemon_before_stream refuses to reopen that session while the old daemon lives. Fix: Add a migration-only close for positively identified legacy daemons, retaining the private-record, process-start, and connected-peer PID checks; keep token-based close mandatory for patched daemons. Add a regression test for upgrade from a verified legacy daemon without a secret.
  2. src-tauri/src/control_identity.rs:371 — Warning (blocking): the new read-only viewport action changes app state. Classifying "viewport_status" as Access::Read routes a read-only caller through session allocation and pane creation or live-state updates before control.rs:1867 checks whether there is a stream. Fix: Resolve only an existing session and return its verified viewport before the shared mutation path; test that an empty workspace stays unchanged when queried by a read-only caller.
  3. scripts/patches/agent-browser-v0.44-codemux.patch:229 — Warning (blocking): confirmation IDs are not unique per prompt. confirmation_id: id.clone() uses the command's correlation ID, which the upstream confirmation replay preserves, so a follow-up prompt can accept a stale decision for the preceding prompt. Fix: Generate a fresh daemon-owned ID every time a command is parked, publish it separately from the response correlation ID, and test that the previous ID cannot confirm or deny a follow-up.
  4. scripts/test-agent-browser-listeners.mjs:127 — Suggestion: verify the HTTP relay response body. assert.match(await command(a.token), /^HTTP\/1\.1 200 /) passes even if the daemon rejects the relayed command, because the HTTP handler wraps a daemon JSON error in a 200 response. Fix: Read the full response and assert that the JSON body reports success: true.

CI: The exact-head GitHub Actions run passed all eight checks, including ci-gate and browser-sidecar-macos. No repository code was built or run during this review.

Verdict: REQUEST_CHANGES

🤖 Automated review by Mario (AI). Findings may be wrong; a human makes the final call.

Zeus-Deus added a commit that referenced this pull request Nov 29, 2026
Bring in #784's commits 8897feb and c2f9249 (daemon-owned confirmation
IDs, legacy daemon close, read-only viewport) and every #758 follow-up the
pipe branch lacked. The CDP pipe patch is regenerated over the new auth
patch, and its approved-navigation test now sends the parked confirmation
ID that the auth patch requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Zeus-Deus added a commit that referenced this pull request Nov 29, 2026
#784 changed the close helper to take a credential that distinguishes a
token from a verified legacy daemon; #785's new test still passed a token
string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Zeus-Deus added a commit that referenced this pull request Nov 29, 2026
#784's test for retiring a verified pre-upgrade daemon without a secret
is macOS-only and no CI job ran it. The macOS sidecar job already builds
the benchmark crate, which includes agent_browser.rs, so run it there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Zeus-Deus
Zeus-Deus changed the base branch from security/browser-stream-capability to main November 29, 2026 22:09
@Zeus-Deus
Zeus-Deus marked this pull request as ready for review November 29, 2026 22:09

@mario-reviewer mario-reviewer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed c2f92494194599dff2f191de75e2eb42ce1a2295. No blocking findings remain. The macOS migration close verifies the old daemon and connected peer; viewport status no longer creates a browser session or pane; replayed commands receive fresh prompt IDs. The HTTP relay test now checks the JSON result.

  • Suggestion — .github/workflows/ci.yml:621–623. The macOS job filters its Rust test invocations to failed_mac_open_closes_its_late_published_daemon and real_sidecar_prior_launch_token_recovery_and_close, so it compiles but does not run macos_reclaims_verified_legacy_daemon_without_a_secret. Fix: Add the legacy-reclaim regression to this job so CI exercises the migration path.

CI (exact head): All eight checks passed, including ci-gate and browser-sidecar-macos. Static review only; no repository code was built, installed, or run during this review.

Verdict: APPROVE

🤖 Automated review by Mario (AI). Findings may be wrong; a human makes the final call.

This branch has not been deployed

No deployments
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