Skip to content

fix(browser): refuse controlled-tab actions on Default origins holding inherited grants - #319

Merged
Hona merged 8 commits into
devfrom
ws1-controlled-permissions
Nov 21, 2026
Merged

Hona merged 8 commits into
devfrom
ws1-controlled-permissions

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

A controlled (agent_driven) tab in the Default profile silently inherits the ALLOW grants (clipboard-read, geolocation, notifications) that the user gave an origin in a human tab: CEF 156.0.26 never calls PermissionHandler::on_show_permission_prompt once a Default origin holds ALLOW (recorded in #305). This PR refuses controlled actions on such origins, in the engine only.

Round 2 (per READER-9's first read): the ~170-line app-side mirror is deleted. The engine enforces everything through two choke points, one url-crate origin classifier, history pre-checks, a back-forward-cache flush, and commit-time eviction. The app only renders the typed EngineMsg::ControlledPermissionRefused { tab_id, url }.

  • Canonical origin (permissions.rs::classify_origin): Url::parse -> Url::origin().ascii_serialization() (url = "2", already 2.5.8 in apps/browser-engine/Cargo.lock). This strips :80/:443, canonicalizes IPv6, punycodes IDNs, and maps blob:http(s)://… to its creator origin. Opaque origins (about:blank, chrome-error://chromewebdata/, data:) are not refused. Parse failures fail closed.
  • Guard 1a: deny-by-default dispatch (engine/extensions.rs::refuse_if_controlled_tab_blocked, first line of EngineManager::handle). It is an exhaustive match with no _ => arm, so a new HostMsg does not compile until it is classified. It checks the tab's committed origin only, so navigating away from a granted origin always works.
    • Guarded: CdpCall, TypedCdpCall, SiteCookies, ClearSite, ClearSiteCache, Back, Forward, Reload, agent Find (non-empty, also stop_finding), SetInspect { enabled: true }, HighlightNode { Some(_) }, ContextMenuAction { Some(_) } (also cancels the held menu).
    • Exempt, and why:
      • Engine-global, not tab-addressed: Hello, ClickExtension, ListExtensions, UninstallExtension, ReloadExtension, CancelExtensionOpenTab, ExtensionMetrics, SetColorScheme, SetPartitionProxy, DropContext, DmabufFailed, ResetPermission, SyncSitePermissions, PreviewResponseHead, PreviewResponseChunk, PreviewResponseEnd, Shutdown. None reads or acts on a tab's document.
      • Navigation: OpenTab, Navigate. The destination is checked separately (pre-check plus Guard 2), so leaving a granted origin is never blocked.
      • Lifecycle and cancel: CloseTab, FocusTab, Stop, StopFind, SetTabPolicy, SetAgentDriven, Find { query: "" }, SetInspect { enabled: false }, HighlightNode { None }, ContextMenuAction { None }. These only tear down or cancel.
      • User's own find bar: Find { user_initiated: true }. Only the bundled find bar sets it, and #312 keeps its FindResult away from agents and third-party plugins. This mirrors #312's extension-surface rule.
      • Layout: SetZoom, Resize, Emulate, FrameRead. These are presentation only and read no page data.
      • Human input and prompt answers: MouseMove, MouseButton, Wheel, Key, EditCmd, Ime, AnswerDialog, AnswerPermission, AnswerAuth.
  • Guard 1b: reply and event choke point (cdp_ledger.rs::TabCdpObserver::refuse_reply). One helper re-checks the committed origin before any CdpPending reply (Raw, CookieCount, ClearSite) and any flattened OOPIF reply leaves the engine, and CdpEvent forwarding is dropped while blocked. A grant landing mid-flight therefore never leaks a reply.
  • Guard 2: navigation, history, and back-forward cache:
    • Destination pre-check on OpenTab/Navigate. history_entry_url(±1) pre-check on Back/Forward, before go_back()/go_forward() runs.
    • on_before_browse cancels main-frame loads and server redirects to granted origins before the request is sent.
    • Memory.simulatePressureNotification({ level: "critical" }) flushes the back-forward cache on SetAgentDriven(true) and on new Default grants (AnswerPermission, SyncSitePermissions), whenever a controlled Default tab and an inherited grant coexist.
    • Backstop: on_address_change (run before snap is locked) calls stop_load() and load_url("about:blank"), and emits the refusal without writing the granted URL into snap.url.
  • App: BlockedGuardReason::InheritedPermission { url } renders in the #306 notice bar, and "Open in new tab" uses the refusal's url (t.url is never overwritten). The notice survives the about:blank fallback commit, panel.luau does not cover it with the blank home page, init.luau suppresses the duplicate "Only web pages" bar, and mcp.luau returns a generic message that names no permission.

Back-forward cache: window and closure

  • Threat: a granted document in the back-forward cache returns through Back or JS history.back()/history.forward() without on_before_browse, and reads the clipboard in pageshow(persisted).
  • Closed by: (1) the host Back/Forward history pre-check; (2) the memory-pressure flush, after which a JS history move becomes a normal navigation that on_before_browse cancels; (3) the on_address_change eviction as a backstop.
  • Measured (see Verification):
    • Without the guard, the same page makes 1 document-start read and 1 pageshow read on a back-forward-cache return.
    • The flush turns persisted: true into persisted: false.
    • Every guarded path made 0 reads and 0 HTTP hits.
  • Window: (3) was not exercised live, because (1) and (2) refused every case first.

Not covered

  • Notifications in a cross-origin embedded frame. Live on CEF 156.0.26 (probe-iframe-delegation.ts), clipboard-read and geolocation follow the top-level origin, so this PR covers them. notifications does not follow it: a granted cross-origin iframe inside an ungranted page still sees Notification.permission === "granted". This is left to Option B (a dedicated CefRequestContext for controlled tabs, escalated to the owner).
  • Non-inherited permissions (camera, microphone) stay prompt-gated or device-guard-blocked.
  • The blob: mapping is covered by the classifier only and is not live-proven.

ENGINE_REVISION

The live index (https://anoma.ly/release/opencode-rune/browser-engine/stable.json) holds only 156.0.14-1 (rev 1, macOS arm64), and dev has ENGINE_REVISION = 2 with no rev-2 engine published. If a rev-2 engine is published before this PR merges, bump ENGINE_REVISION in crates/browser-pane/src/installer.rs before merging, because EngineMsg::ControlledPermissionRefused is a wire change. No bump is needed if this merges first.

Difference from official opencode (b9a60d9d)

Official checks permissions per web contents with Electron's request and check handlers (packages/desktop/src/main/browser/session-guard.ts:23-78, site-permissions.ts:131-149, page-prompts.ts:453, 468). CEF 156.0.26 has no check callback once ALLOW is stored on a Default origin, so refusing controlled actions on granted Default origins is the closest sound port short of a CEF patch or Option B.

Verification (a349e08f, origin/dev 8b42a094 merged in, no rebase)

  • Size vs dev: 18 files, +509/−38.
    • Engine +438: permissions.rs +148, engine/extensions.rs +143 (about 75 of these are the no-catch-all match naming every HostMsg variant), engine.rs +39, cdp_ledger.rs +37, handlers.rs +33, wire.rs +8, Cargo +2.
    • App, UI, and plugins +71.
  • Guardrails: scripts/guardrails.ps1 5/5 (engine.rs 1,462/1,500, client.rs 1,454/1,500, handlers.rs 1,214/1,500).
  • Windows: check --workspace, check -p browser-pane --no-default-features, engine --bins, and build -p opencode-desktop all have 0 warnings. wasm32 scripts/web.ps1 -Check passes.
  • Linux (adais): --workspace --all-targets clean in 49 s; engine --bins clean in 9 s.
  • macOS (air): --workspace clean. The only warning is the existing trace.rs tsc warning on dev.
  • Live CEF 156.0.26.1 (prove-stopgap-r2.ts, OPENCODE_RUNE_OTEL=0, scratch profile): ALL_PASS
    • Positive controls (human tab, granted origin, no guard active):
      • Document-start reads: 1.
      • Back-forward-cache return: persisted true, pageshow reads 1.
      • After the flush: persisted false.
    • Controlled tab:
      • OpenTab, Navigate, and a 302 to the granted origin: 0 HTTP hits, 0 reads.
      • Host Back, JS history.back(), a repeated Back, host Forward, JS history.forward(), and history.back() after a mid-visit grant: all refused, 0 reads, 0 hits, still on the ungranted page.
    • Origin forms: :443, :80, Unicode IDN, uppercase IDN, and [::0:1] are all refused.
    • Guarded commands: the in-flight reply, TypedCdpCall, SiteCookies, ClearSiteCache, and Reload are refused. Agent Find is refused; the user's Find still works (1 match, no refusal).
    • Things that must keep working: leaving a mid-visit-granted origin works. An unreachable ungranted URL shows ERR_CONNECTION_REFUSED, not a refusal. The human tab still reads the clipboard. Private, RemoteServer, Preview, and Artifact tabs are unaffected.
  • Live Desktop (prove-stopgap-desktop.ts, proof/ws1/stopgap-notice.png): one notice bar with "Open in new tab", and t.url stays about:blank.
  • No test files and no .github/ files changed.

@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 1e791b7 into dev Nov 21, 2026
7 checks passed
@Hona
Hona deleted the ws1-controlled-permissions branch November 21, 2026 01:35
Hona added a commit that referenced this pull request Nov 21, 2026
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