Skip to content

fix(browser): enforce RPC target/generation auth, track OOPIFs & contextId, fix wait spin, and bound payloads/cancel - #298

Merged
Hona merged 36 commits into
devfrom
browser-tools/fix-rpc-auth-bounds
Nov 20, 2026
Merged

Hona merged 36 commits into
devfrom
browser-tools/fix-rpc-auth-bounds

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes notes/review-rd-tools.md Findings 3, 4, all 3 Round-2 findings, all 4 Round-3 findings, and both Round-4 findings on origin/dev (00d73a6d, incl. #305, #316, #303, #296, #301, #306, #307, #274, #292, #294):

1. Round-4 Fixes (notes/review-rd-tools.md:734-764)

  1. Live Page.getFrameTree verification at execution time (exec/{mod,read,snapshot,capture}.rs):
    • Extracted shared queue_live_frame_refresh / step_live_frame_refresh (refreshes top-level + every active OOPIF session).
    • Added ExecPhase::VerifyFrames (exec/mod.rs) running live Page.getFrameTree BEFORE verify_authorized_state whenever cmd.target.is_some() on frame-touching commands (evaluate, wait, snapshot, find, screenshot, frames, dialog, etc.), matching official chromium.ts:1518. Commands that touch no frame (tabs.*, navigate, navigate.path, back, forward, reload, stop, preview, network.get, files.get) incur 0 extra CDP calls.
    • Updated SnapshotStage::CheckFrame to refresh both top-level and active OOPIFs, and added post-capture live verification (SnapshotStage::VerifyPost and ScreenshotStage::VerifyPost) before returning output/pixels.
    • Per-command cost: 2,020 µs (2.02 ms, median of 10 live Page.getFrameTree round trips; 0 µs on frame-less commands).
  2. Pre-parse > 16 MiB raw byte cap on CDP events (apps/browser-engine/src/cdp_ledger.rs):
    • scan_top_level_cdp early-exits at depth == 1 on "method" (0 bytes allocated) and drops > 16 MiB events UNPARSED before serde_json::from_slice; moves params out of val (val.as_object_mut().and_then(|o| o.remove("params"))) instead of cloning for <= 16 MiB events. Replies continue using the depth-1 scanner (top-level return 0 -> on_dev_tools_method_result; flattened OOPIF rejected pre-parse over max_bytes).
    • Worst-case allocation for one event: 0 B above 16 MiB; at <= 16 MiB, ~16 MiB for a single 16 MiB string (1× move, no params.clone()) and bounded at ~320 MiB for a maximally dense 8.3M-token JSON array (vs unbounded OOM on 100 MiB+ before).

2. Confirmed Prior Round Fixes Preserved

  • Standard url crate (url 2.5.8, idna 1.1.0, idna_adapter 1.2.2, form_urlencoded 1.2.2 — all MIT OR Apache-2.0, matching apps/browser-engine/Cargo.lock): parse_agent_url parses once and passes exact Url::as_str() to both server Wildcard.match policy and Chromium.
  • Frame pruning / overflow recovery / reload generation bump under #274: ingest_frame_tree replaces frames per session, clears per-target overflow_targets on navigation away from >256 frames, and bumps generation on Runtime.executionContextsCleared + top-level loaderId change.
  • Stray duplicate flush_pending_opens() removed (crates/browser-pane/src/client.rs): Single flush remains strictly after SetColorScheme, Emulate, SetAgentDriven, and SetPartitionProxy.
  • Reconnect re-probe (rpc/mod.rs:199): was_connected = ...is_some() invalidates stale LegacyAllowed on StreamDown -> Reconnected.

3. Merge of origin/dev (00d73a6d, #316 + #305) & Verbatim Move

  • Conflict hunks (2 files, 2 hunks):
    1. apps/browser-engine/src/engine.rs:1414-1425: kept #305's impl Drop for EngineManager { self.permissions.shutdown(); } alongside #298's pub(crate) use extensions::{browser_has_extension_surface, tab_is_extension_surface};.
    2. apps/browser-engine/src/handlers.rs:14-34: kept origin/dev's wrapped cef::{ ... } import formatting (both sides added ImplBrowser, ImplBrowserHost).
  • Verbatim move to keep handlers.rs under 1,500: Merging #305 brought handlers.rs to 1,501 lines; moved CdpPending, PendingClear, and wrap_dev_tools_message_observer! { pub struct TabCdpObserver ... } verbatim (zero edits inside moved code) from handlers.rs into apps/browser-engine/src/cdp_ledger.rs with pub use crate::cdp_ledger::{CdpPending, PendingClear, TabCdpObserver}; in handlers.rs.
    • Line counts BEFORE -> AFTER: handlers.rs 1,501 -> 1,181, engine.rs 1,423 -> 1,423, cdp_ledger.rs 407 -> 736, client.rs 1,430 -> 1,430.
  • #305 behavioral audit: #305's per-context PermissionTracker + DEVICE_GUARD_PREFS lockdown and !self.context_ready.load(Ordering::Acquire) readiness gating in TabPermissionHandler / on_before_browse / on_address_change are 100% compatible with #298 and #302 (RemoteServer agent tabs inherit device-guard blocking and per-context permission isolation cleanly; Ready.permission_sync + sync_site_permissions() run ahead of SetPartitionProxy/flush_pending_opens()).

4. Security Scope

  • Actions added: None (hardens existing experimental.browser v4 executors and engine CDP boundary; zero contract.json growth, zero ENGINE_REVISION bump, zero struct App field growth).
  • Who can call / which tab/session touched: Native Rust BrowserRpcFeature only, scoped strictly to session-owned non-extension tabs and verified main-world contextIds.
  • User confirmation required: Server Wildcard.match authorization via inspect: true + live Page.getFrameTree target/generation re-verification at execution and post-capture.

5. Driven Verification (proof/browser-tools/fix-b/summary.json: 35/35 Live PASS on Merged Head)

  • Round-4 Finding 1 (TOCTOU under real #274 extensions_active == true): ext_active_toctou_subframe_nav_to_denied_refused: true (child iframe navigated /allowed-frame -> /denied-frame after authorization; evaluate({frameID}), screenshot, and snapshot all refused with document_changed). Live Page.getFrameTree round trip: ~2.0 ms.
  • Round-4 Finding 2 (100 MB console event pre-parse drop): engine_100mb_console_event_dropped_pre_parse_no_oom: true (console.log("A".repeat(100_000_000)): 0 IPC events > 16 MiB, steady WorkingSet +0.2 MiB / Private +0.1 MiB, extra peak over Runtime.enable-OFF baseline only CEF's single callback slice, 0 B Rust AST, engine alive).
  • All 33 prior checks: All 17 WHATWG/IDNA/percent-decode/empty-segment URL variants + 3 fail-closed rejections + live Chromium agreement, #274 extension-active pruning/overflow recovery/reload generation bump, OOPIF frames/snapshot/eval/wait, TypedCdpCall ledger, pre-parse 1 MiB eval cap, and 1.15 MiB nested-id event delivery: ALL PASS.
  • Checks: Guardrails 5/5, web.ps1 -Check, Apple & Linux browser-policy via tools/cargo.ps1, --workspace --all-targets, desktop + engine builds: ALL PASS (0 warnings).

Held unmerged for READER-10 fourth read.

Hona added 20 commits November 21, 2026 00:00
…hed servers and block check_cdp contextId/userGesture
…& pinned contextId, fix wait deadline spin, and bound payloads/cancel
…te-dual-route-cdp

# Conflicts:
#	apps/desktop/src/surfaces/browser/mod.rs
#	crates/browser-pane/src/protocol.rs
…ow sticky suppression, and harden CdpCall/check_cdp
…ools/fix-rpc-auth-bounds

# Conflicts:
#	crates/opencode-kit/src/client/browser_rpc/machine.rs
…pinned context/256-frame overflow, recheck post-capture auth, and fix OOPIF/cancel/bounds
…te-dual-route-cdp

# Conflicts:
#	apps/browser-engine/src/engine.rs
…ools/fix-rpc-auth-bounds

# Conflicts:
#	apps/browser-engine/src/engine.rs
#	apps/browser-engine/src/handlers.rs
#	apps/browser-engine/src/wire.rs
#	crates/browser-pane/src/client.rs
#	crates/browser-pane/src/machine.rs
#	crates/browser-pane/src/protocol.rs
…te-dual-route-cdp

# Conflicts:
#	apps/desktop/src/surfaces/browser/mod.rs
#	crates/browser-pane/src/client.rs
#	crates/browser-pane/src/protocol.rs
…egacy MCP until Unsupported/Unavailable, and fix #292 merge regressions
…ools/fix-rpc-auth-bounds

# Conflicts:
#	apps/browser-engine/src/downloads.rs
#	apps/browser-engine/src/engine.rs
#	apps/browser-engine/src/main.rs
#	crates/browser-pane/src/find.rs
Hona added a commit that referenced this pull request Nov 20, 2026
- Fold security-confirmed merged PRs #292 (6d7a6ed, WS-1 mandatory
  RemoteServer proxy), #294 (ae3e910, BROWSER-UI file-link/click-to-run
  fix with known symlink/junction root limitation), and #274 (5da6474,
  WS-9 engine MV3 extension host, inert without --extension flags)
- Update browser Reviewed column: #301 in rework (#287 eager-attach
  time_updated regression still live on dev), #296/#298/#302/#303/#305/#306
  in rework, #307 open for pre-merge security review
- Audit upstream anomalyco/opencode fe8def6854..4122af0206 (+2 commits:
  1 skipped #65255 core/codemode, 1 added UP-135 #65215 -> WS-8)
Hona added 8 commits November 21, 2026 05:27
…te-dual-route-cdp

# Conflicts:
#	apps/browser-engine/src/engine.rs
#	crates/browser-policy/src/lib.rs
…ools/fix-rpc-auth-bounds

# Conflicts:
#	apps/browser-engine/src/engine.rs
#	apps/browser-engine/src/handlers.rs
#	apps/browser-engine/src/wire.rs
#	apps/desktop/src/surfaces/browser/rpc/mod.rs
…te-dual-route-cdp

# Conflicts:
#	apps/desktop/src/plugin_host/native/browser/scope.rs
#	crates/browser-pane/src/client.rs
… subframe enumeration, WHATWG target URL, required contextId, bounded CdpResponse IPC)
…ools/fix-rpc-auth-bounds

# Conflicts:
#	apps/desktop/src/surfaces/browser/rpc/exec/nav.rs
#	apps/desktop/src/surfaces/browser/rpc/mod.rs
…e.getFrameTree stubs and fix BrowserRpcState field visibility
Base automatically changed from browser-tools/fix-remote-dual-route-cdp to dev November 20, 2026 21:15
Hona added 3 commits November 21, 2026 07:23
…auth-bounds

# Conflicts:
#	apps/desktop/src/surfaces/browser/rpc/mod.rs
#	crates/opencode-kit/src/client/browser_rpc/machine.rs
…auth-bounds

# Conflicts:
#	apps/desktop/src/surfaces/browser/rpc/exec/nav.rs
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR test build retired — merged into dev. Install or auto-update OpenCode (Rune) from https://anoma.ly/release/opencode/desktop-rune/dev/macos-arm64-dmg.

@Hona
Hona merged commit d6cf865 into dev Nov 20, 2026
7 checks passed
@Hona
Hona deleted the browser-tools/fix-rpc-auth-bounds branch November 20, 2026 23:59
Hona added a commit that referenced this pull request Nov 21, 2026
Hona added a commit that referenced this pull request Nov 21, 2026
…ion (#302)

* fix(browser): refuse local rune_mcp browser tools on remote/RPC-attached servers and block check_cdp contextId/userGesture

* fix(browser): enforce RPC target/generation auth, track OOPIF frames & pinned contextId, fix wait deadline spin, and bound payloads/cancel

* fix(web): gate browser rpc suppression check on wasm32

* fix(browser): exclude ContextKind::Private tabs from experimental.browser agent RPC inventory and tab resolution

* fix(browser): harden TunnelProxy HTTP/1.1 framing, wire remote tunnel proxy to SetPartitionProxy, and add BuiltinPromptGate

* fix(browser): gate native scope.rs on MCP suppression, track per-window sticky suppression, and harden CdpCall/check_cdp

* fix(browser): verify TypedCdpCall ledger in engine, fail closed on unpinned context/256-frame overflow, recheck post-capture auth, and fix OOPIF/cancel/bounds

* fix(browser): expand loopback_host IPv4/IPv6/alternate-encoding detection

* refactor(browser-policy): move loopback_host helpers into agent.rs to stay under 800-line ceiling

* fix(browser): clean FIN shutdown after 503 Service Unavailable on TunnelProxy concurrency cap

* fix(browser): fail closed in engine ContextPool for RemoteServer, atomic tunnel rotation/suspend, host proxy validation, and Luau loopback_host

* refactor(browser-policy): extract check_cdp into cdp.rs to stay under 800-line ceiling

* refactor(browser-engine): extract CdpCall validation helper into cdp_ledger.rs to stay under 1500-line ceiling

* fix(browser): retry tab CDP bootstrap after isolated context finishes initializing

* fix(browser): check suspended state in ConnGuard::track_abort and bidirectional EOF path

* fix(browser): close scope.rs task.spawn/NormalizeUrl escape and keep Blocked::Replaced suppressed

* refactor(browser-pane): move send_cdp into find.rs to stay under 1500-line ceiling

* fix(browser): gate all non-builtin plugins in scope.rs, fail closed legacy MCP until Unsupported/Unavailable, and fix #292 merge regressions

* fix(browser): verify Tier::Bundled on Half and add sticky legacy MCP capability probe

* fix(browser): close #298 Round-2 findings (fail-closed frameID, OOPIF subframe enumeration, WHATWG target URL, required contextId, bounded CdpResponse IPC)

* fix(browser): preserve committed OOPIF child URLs across ancestor Page.getFrameTree stubs and fix BrowserRpcState field visibility

* fix(browser): close #302 tunnel smuggling/DoS/SSE-suspend findings and port complete BuiltinPromptGate

* fix(browser): use url crate for WHATWG URLs, rebuild frames on getFrameTree, remove dup flush, depth-1 CDP scan

* fix(browser): refresh OOPIF frame trees in browser.frames

* fix(browser): split prompt gate out of #302 and add tunnel watchdog + unauth pool isolation

* fix(browser): verify live Page.getFrameTree before/after frame commands and drop >16 MiB CDP events pre-parse

* fix(browser): remove authenticated tunnel idle kills, match 64-slot unauth pool with 3s head deadline + 1s watchdog margin

* chore(browser-engine): remove unused Value import from handlers.rs after verbatim move
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.

1 participant