Skip to content

fix(browser): require loopback proxy on RemoteServer, gate Navigate on proxy init, close tabs on proxy drop/failure, and block remote loopback external handoff - #292

Merged
Hona merged 7 commits into
devfrom
ws1-fix1-remote-proxy
Nov 20, 2026
Merged

Hona merged 7 commits into
devfrom
ws1-fix1-remote-proxy

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes notes/review-rd-engine.md Finding 1 (remote-server proxy fail-closed enforcement, pre-init gating, preference read-back verification, and external loopback handoff blocking) plus all round-1 (0a539feb) and round-2 (5785b7f5) READER-9 findings — and explicitly folds in the Finding 2 context-inheritance and persistence-exclusion fixes (TabSnapshot.context, session/opener context derivation across pop-ups / blocked-popup Open / context-menu Open link & image, TabClosed pending_opens/session_tabs/strip pruning, and excluding isolated tabs from savedTabs, closedTab, and site_zoom) per orchestrator approval.

Reconciled with origin/dev 5d50c6f7 (#299 NoopCompletion + #281 oc-preview:// readiness gate): keeps #281's exact fail-closed readiness gate (ContextPool::is_tab_ready, default_tabs, generation tokens, PreInitBlockResourceHandler, shared context_ready across TabRequestHandler/TabResourceRequestHandler/TabLifeSpanHandler/TabDownloadHandler, ContextHooks::on_initialized, clear_pending_load) and makes RemoteServer tabs use it (ready = initialized && prefs_ok && !suspended, so a remote tab is ready ONLY when initialized, preferences are verified via read-back, AND its loopback proxy is live).

Round-2 Delta Response (5785b7f5 -> 5badf27a)

READER-9 Round-2 Finding Fix in 5badf27a
1. Closed opener escapes proxy into direct-network Private Changed browser_context_for_opener (apps/desktop/src/surfaces/browser/mod.rs) to return Option<(bool, ContextKind)> (None when opener is gone — never downgrades to direct Private); poll_browser (PopupOpen) and prompts/view.rs (blocked pop-up Open) drop/refuse when None. context_menu.rs captures (agent, ctx), sid, and external_link_ok when opening the menu, cancels menus on suspended tabs, refuses "open-link"/"open-image" if the opener closed or its RemoteServer lacks a live proxy, and re-resolves live proxy credentials before opening.
2. Second OpenTab proxy rotation leaves stale prompts.proxy/context on existing tabs ContextPool::resolve_with_hooks returns proxy_updated: Option<(server_id, new_cfg, activate_ready)>; engine.rs::open_tab syncs t.context and t.prompts.proxy across ALL matching RemoteServer tabs before flipping ready = true.
3. Resume ordering race & suspended TabDownloadHandler gap Both set_partition_proxy and resolve_with_hooks flip ready = false BEFORE apply_context_prefs -> close_connections -> return activate_ready, and engine.rs syncs t.context + t.prompts.proxy across all matching tabs BEFORE flipping ready = true LAST. Passed context_ready: Arc<AtomicBool> to TabDownloadHandler (downloads.rs) blocking can_download, on_before_download, and on_download_updated (removing partial files) while !ready (prevents blob:/data: disk writes while suspended).
4. Suspended UI copy, sticky banner, fatal-close toast & small items Added 3 English i18n keys (plugins/browser/locales/en.json: refused.proxyRequired "Paused while reconnecting to the server.", refused.proxyInvalid "Couldn't connect through the server's proxy."; crates/opencode-i18n/locales/rune/en.json: rune.browser.proxy.closed "Closed this tab because the server's browser proxy stopped working."), mapped in failure.luau, set suspended = tab:Refusal() == "browser.proxy.required" in init.luau, cleared "browser.proxy.required" refusal on resume in find.rs::set_partition_proxy and resolve_remote_context (triggering Browser.Changed -> syncRefusal clear), toasted rune.browser.proxy.closed ONLY on fatal browser.proxy.invalid/browser.context.unavailable closures (zero toast on explicit DropContext of a suspended tab). Also fixed panel.luau:425 (env.reachable(url, tab)), set deferred_initial on queued Navigate (engine.rs), and cleared has_engine_tab on unconfirmed engine OpenTab refusals (engine_confirmed in client.rs).

(Zero tests added/edited; zero .github/ edits; preview/, prompts.rs, menu.rs, favicon.rs remain clean vs #281 5d50c6f7.)

Verification

  • pwsh -NoProfile -File scripts/guardrails.ps1: 5/5 passed (client.rs 1490, engine.rs 1391, 0 errors)
  • cargo build --locked --manifest-path apps/browser-engine/Cargo.toml --bins: clean (0 warnings)
  • cargo check --workspace: clean (0 warnings)
  • cargo check -p browser-pane --no-default-features: clean (0 warnings)
  • scripts/web.ps1 -Check: clean (0 warnings; 1038 files, no std::time)
  • Live CEF 156.0.26 proofs (proof/ws1/fix1-remote-proxy.md, OPENCODE_RUNE_OTEL=0, scratch profiles):
    • Unproxied / localhost-hostname / credential-less RemoteServer opens all refused (browser.proxy.required / browser.proxy.invalid), 0 browsers opened.
    • Pipelined OpenTab("about:blank") + immediate CdpCall + Navigate: CdpCall rejected (browser.proxy.required), 0 direct origin hits, nav routed via p1.
    • Transient SetPartitionProxy(None) -> OpenTab Tab 11 rotating to p2: closedDuringSuspend: false, suspended CdpCall/Navigate blocked, blobDownloadsWhileSuspended: 0, window.__unsaved === "keep-me-42" preserved, Tab 10 synced to p2 and routed /after-resume via p2 with 0 407 failures.
    • Live WebRTC UDP STUN & TURN-TCP / hostname containment:
      • stun:127.0.0.1:<udpPort>: RemoteServer = 0 UDP packets, 0 ICE candidates (Default control = 3 UDP packets, 1 ICE candidate).
      • turn:127.0.0.1:<tcpPort>?transport=tcp, turns:127.0.0.1:<tcpPort>?transport=tcp, turn:probe-turn-host.invalid:443?transport=tcp: RemoteServer = 0 direct TCP hits (routed via proxy CONNECT 127.0.0.1:<tcpPort> and CONNECT probe-turn-host.invalid:443; Default control = 3 direct TCP hits).
      • stun:probe-webrtc-dns.invalid:3478: RemoteServer = 0 STUN host lookup errors (Default control = 2 + .local mDNS host candidate).
    • IPv6 [::1] proxy routed cleanly; explicit DropContext closed tab cleanly; reconciled #281 oc-preview:// local preview + pre-init CdpCall rejection verified live.

Round-3 Delta Response (5badf27a -> a8a105b5)

READER-9 Round-3 Finding Fix in a8a105b5
1. Downloads.files keyed only by per-context item.id() (cross-context file deletion + stuck Pending) Keyed Downloads.files by (u64, u32) = (self.tab_id, item.id()) across apps/browser-engine/src/downloads.rs (:44, 64, 132, 150, 161, 177, 183) and emitted DownloadState::Failed { error: Some("canceled") } when cancelling a pending entry on !context_ready (:164-168).
2. Early return; in context_menu.rs leaks held RunContextMenuCallback Replaced early return; on proxy.is_none() in "open-link" and "open-image" (apps/desktop/src/surfaces/browser/context_menu.rs:145-199) with if proxy_ok { ... } so run_context_menu_action(tab_id, menu_id, engine_cmd) always executes and cancels CEF's callback.
  • Round-3 Live CEF 156 proof (C:\tmp\opencode\ws1\prove-fix1-r4.ts, proof/ws1/fix1-remote-proxy.md §4):
    • Default Tab 1 (item.id() == 1, default-keep.txt) + RemoteServer Tab 10 (item.id() == 1, slow remote-slow.bin) suspended mid-download: Tab 10 emitted state: "failed", error: "canceled" and deleted its partial file, while Tab 1's default-keep.txt survived intact on disk.
    • Context menu on RemoteServer Tab 10 losing its proxy cancelled cleanly (menu1Id: 1 -> action: null -> reconnect -> menu2Id: 2 opened cleanly).

New i18n Keys (English only, ready for locale sync word)

  • plugins/browser/locales/en.json: refused.proxyRequired, refused.proxyInvalid
  • crates/opencode-i18n/locales/rune/en.json: rune.browser.proxy.closed

Held non-draft awaiting READER-9 confirmation before merge (do not self-merge).

…n proxy init, close tabs on proxy drop/failure, and block remote loopback external handoff

Addresses `notes/review-rd-engine.md` Finding 1 (and §7 proxy/drop/untrimmed-key, §3.5
password `Debug` redaction, §6 `oc-preview://` menu URL filter, §8 remote loopback
external-open block, and Reader-9 empirical item #7):

- **Refuse unproxied `RemoteServer` tabs fail-closed (`apps/browser-engine/src/context.rs`,
  `crates/browser-pane/src/{protocol,client,find}.rs`, `apps/desktop/src/surfaces/browser/mod.rs`):**
  Removes the `mode: "direct"` fallback for `RemoteServer` contexts. Both `BrowserHost`
  and `ContextPool` require a live authenticated loopback proxy (`browser.proxy.required`
  if absent; `RemoteServer` always requires `partitions && remote_proxy`). Caches
  `remote_proxies` on `BrowserHost` (supplied automatically by `default_browser_context()`
  and re-sent across engine reconnects) for BROWSER-TOOLS' `TunnelProxy` integration.
- **Gate `HostMsg::Navigate` / history nav on `initialized && prefs_ok` (`context.rs`,
  `engine.rs`):** Closes the `about:blank` + immediate `HostMsg::Navigate` race window
  before `on_request_context_initialized` finishes applying `fixed_servers` +
  `<-loopback>` and required lockdown preferences (`webrtc.ip_handling_policy`,
  `net.quic_allowed`, `net.network_prediction_options`), failing closed if any required
  preference write returns `0`. Brackets IPv6 `::1` proxy hosts as `http://[::1]:<port>`
  and trims all pooled `ContextKey` strings canonically.
- **Close live tabs on proxy failure, proxy clear, or `DropContext` (`engine.rs`):**
  Closes and refuses every live tab in a `RemoteServer` context if proxy initialization or
  `SetPartitionProxy` fails or clears (`proxy: None`), and closes all live tabs in a
  context before `DropContext` tears down the pool entry.
- **Block remote loopback external handoff & redact proxy credentials (`surfaces/browser/
  {mod,context_menu}.rs`, `menu.rs`, `wire.rs`, `protocol.rs`):** `external_url_allowed_for_tab`
  refuses loopback HTTP(S) URLs from remote-server tabs in both the page context menu and
  `open_browser_tab_externally`; removes arbitrary `oc-preview://` allow from `menu.rs`;
  redacts `RemoteProxyConfig::{username, password}` in `Debug`.
Hona added a commit that referenced this pull request Nov 20, 2026
…18..UP-122 (#295)

- Fold verified fleet PRs #278, #285, #287, #288, #289, #290, #291, and
  #293 (Rune dc8f7f72: #1301, #1302 focus rescue verified Send+Enter -> effort)
  into docs/upstream-sync/ledger.{json,md}
- Close UP-062 packaged-default regression (#278), UP-095-UI / UP-100 /
  UP-106 / UP-109 / UP-117 (#285, #289), and PRE-08 (#287); reassign
  UP-115, UP-116, UP-075 to BROWSER-UI
- Add separate Reviewed column for browser rows tracking retrospective
  security reviews on merged PRs (#245, #268, #272, #277, #288, #275, #287,
  #285, #289) and pre-merge holds (#274, #280, #281, #283, #286, #292, #294,
  and BROWSER-TOOLS PR 3+)
- Audit upstream anomalyco/opencode bfee96a859..2002222d13 (+6 commits:
  1 skipped, 5 added: UP-118..UP-122) and refine radar routing
@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 added 6 commits November 21, 2026 02:03
…ext inheritance, pref readback, suspend/resume, loopback)
# Conflicts:
#	apps/browser-engine/src/context.rs
# Conflicts:
#	apps/browser-engine/src/context.rs
#	apps/browser-engine/src/engine.rs
#	apps/browser-engine/src/handlers.rs
#	apps/browser-engine/src/prompts.rs
#	apps/browser-engine/src/wire.rs
#	crates/browser-pane/src/protocol.rs
…enTab proxy sync, resume order, downloads gate, suspended UI)
@Hona
Hona merged commit 6d7a6ed into dev Nov 20, 2026
7 checks passed
@Hona
Hona deleted the ws1-fix1-remote-proxy branch November 20, 2026 18:25
Hona added a commit that referenced this pull request Nov 20, 2026
…egacy MCP until Unsupported/Unavailable, and fix #292 merge regressions
Hona added a commit that referenced this pull request Nov 20, 2026
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 a commit that referenced this pull request Nov 20, 2026
…hed servers and harden check_cdp (#296)

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

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

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

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

* 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
Hona added a commit that referenced this pull request Nov 20, 2026
… and ban raw file:// unconditionally (#303)

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

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

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

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

* feat(browser): route local, remote, and artifact previews via oc-preview:// and ban raw file:// unconditionally

* fix(browser): close review-rd281 PR 2 blockers 1, 3, 4 and polish (third-party plugin ban, bounded PreviewFetch pool + abort + backpressure + exact skip, Connecting/zero-OpenTab older-engine fix)

* 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): tighten builtin running check, third-party link pre-filter, per-read timeout, and short-EOF skip guard

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

* fix(browser-engine): slice ranged 200 responses into exact 206/416 streams for CEF StreamReaderURLLoader

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

* fix(browser): close review-rd281 2nd-read findings (unbounded control events + PreviewCredit flow control, tool-scoped open_file/Links:Open agent gating, fair PreviewFetchPool + abortable DNS timeout)

* fix(browser): close review-rd281 3rd-read findings (bounded 20s credit wait + Ready.preview_credit handshake, ranged-200 completion cancel/remove, EINTR + ascii-digit Content-Length)
Hona added a commit that referenced this pull request Nov 20, 2026
…extId, fix wait spin, and bound payloads/cancel (#298)

* 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): 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

* 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): 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): 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): verify live Page.getFrameTree before/after frame commands and drop >16 MiB CDP events pre-parse

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