Repository navigation
fix(browser): refuse controlled-tab actions on Default origins holding inherited grants - #319
Merged
Merged
Conversation
…g inherited grants
…ic MCP message for inherited-permission blocks
|
PR test build retired — merged into |
…cal origins and BFCache protection
…ions # Conflicts: # apps/browser-engine/src/engine.rs # apps/browser-engine/src/handlers.rs
…ttp(s) tuple origins
…d Guard 1b reply checks into one helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A controlled (
agent_driven) tab in theDefaultprofile silently inherits theALLOWgrants (clipboard-read,geolocation,notifications) that the user gave an origin in a human tab: CEF156.0.26never callsPermissionHandler::on_show_permission_promptonce aDefaultorigin holdsALLOW(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 typedEngineMsg::ControlledPermissionRefused { tab_id, url }.permissions.rs::classify_origin):Url::parse->Url::origin().ascii_serialization()(url = "2", already2.5.8inapps/browser-engine/Cargo.lock). This strips:80/:443, canonicalizes IPv6, punycodes IDNs, and mapsblob:http(s)://…to its creator origin. Opaque origins (about:blank,chrome-error://chromewebdata/,data:) are not refused. Parse failures fail closed.engine/extensions.rs::refuse_if_controlled_tab_blocked, first line ofEngineManager::handle). It is an exhaustivematchwith no_ =>arm, so a newHostMsgdoes not compile until it is classified. It checks the tab's committed origin only, so navigating away from a granted origin always works.CdpCall,TypedCdpCall,SiteCookies,ClearSite,ClearSiteCache,Back,Forward,Reload, agentFind(non-empty, alsostop_finding),SetInspect { enabled: true },HighlightNode { Some(_) },ContextMenuAction { Some(_) }(also cancels the held menu).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.OpenTab,Navigate. The destination is checked separately (pre-check plus Guard 2), so leaving a granted origin is never blocked.CloseTab,FocusTab,Stop,StopFind,SetTabPolicy,SetAgentDriven,Find { query: "" },SetInspect { enabled: false },HighlightNode { None },ContextMenuAction { None }. These only tear down or cancel.Find { user_initiated: true }. Only the bundled find bar sets it, and#312keeps itsFindResultaway from agents and third-party plugins. This mirrors#312's extension-surface rule.SetZoom,Resize,Emulate,FrameRead. These are presentation only and read no page data.MouseMove,MouseButton,Wheel,Key,EditCmd,Ime,AnswerDialog,AnswerPermission,AnswerAuth.cdp_ledger.rs::TabCdpObserver::refuse_reply). One helper re-checks the committed origin before anyCdpPendingreply (Raw,CookieCount,ClearSite) and any flattened OOPIF reply leaves the engine, andCdpEventforwarding is dropped while blocked. A grant landing mid-flight therefore never leaks a reply.OpenTab/Navigate.history_entry_url(±1)pre-check onBack/Forward, beforego_back()/go_forward()runs.on_before_browsecancels main-frame loads and server redirects to granted origins before the request is sent.Memory.simulatePressureNotification({ level: "critical" })flushes the back-forward cache onSetAgentDriven(true)and on newDefaultgrants (AnswerPermission,SyncSitePermissions), whenever a controlledDefaulttab and an inherited grant coexist.on_address_change(run beforesnapis locked) callsstop_load()andload_url("about:blank"), and emits the refusal without writing the granted URL intosnap.url.BlockedGuardReason::InheritedPermission { url }renders in the#306notice bar, and"Open in new tab"uses the refusal'surl(t.urlis never overwritten). The notice survives theabout:blankfallback commit,panel.luaudoes not cover it with the blank home page,init.luausuppresses the duplicate "Only web pages" bar, andmcp.luaureturns a generic message that names no permission.Back-forward cache: window and closure
Backor JShistory.back()/history.forward()withouton_before_browse, and reads the clipboard inpageshow(persisted).Back/Forwardhistory pre-check; (2) the memory-pressure flush, after which a JS history move becomes a normal navigation thaton_before_browsecancels; (3) theon_address_changeeviction as a backstop.pageshowread on a back-forward-cache return.persisted: trueintopersisted: false.Not covered
156.0.26(probe-iframe-delegation.ts),clipboard-readandgeolocationfollow the top-level origin, so this PR covers them.notificationsdoes not follow it: a granted cross-origin iframe inside an ungranted page still seesNotification.permission === "granted". This is left to Option B (a dedicatedCefRequestContextfor controlled tabs, escalated to the owner).camera,microphone) stay prompt-gated or device-guard-blocked.blob:mapping is covered by the classifier only and is not live-proven.ENGINE_REVISIONThe live index (
https://anoma.ly/release/opencode-rune/browser-engine/stable.json) holds only156.0.14-1(rev 1, macOS arm64), anddevhasENGINE_REVISION = 2with no rev-2 engine published. If a rev-2 engine is published before this PR merges, bumpENGINE_REVISIONincrates/browser-pane/src/installer.rsbefore merging, becauseEngineMsg::ControlledPermissionRefusedis 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). CEF156.0.26has no check callback onceALLOWis stored on aDefaultorigin, so refusing controlled actions on grantedDefaultorigins is the closest sound port short of a CEF patch or Option B.Verification (
a349e08f,origin/dev8b42a094merged in, no rebase)dev: 18 files, +509/−38.permissions.rs+148,engine/extensions.rs+143 (about 75 of these are the no-catch-allmatchnaming everyHostMsgvariant),engine.rs+39,cdp_ledger.rs+37,handlers.rs+33,wire.rs+8, Cargo +2.scripts/guardrails.ps15/5 (engine.rs1,462/1,500,client.rs1,454/1,500,handlers.rs1,214/1,500).check --workspace,check -p browser-pane --no-default-features, engine--bins, andbuild -p opencode-desktopall have 0 warnings. wasm32scripts/web.ps1 -Checkpasses.adais):--workspace --all-targetsclean in 49 s; engine--binsclean in 9 s.air):--workspaceclean. The only warning is the existingtrace.rstscwarning ondev.156.0.26.1(prove-stopgap-r2.ts,OPENCODE_RUNE_OTEL=0, scratch profile): ALL_PASSpersistedtrue,pageshowreads 1.persistedfalse.OpenTab,Navigate, and a 302 to the granted origin: 0 HTTP hits, 0 reads.Back, JShistory.back(), a repeatedBack, hostForward, JShistory.forward(), andhistory.back()after a mid-visit grant: all refused, 0 reads, 0 hits, still on the ungranted page.:443,:80, Unicode IDN, uppercase IDN, and[::0:1]are all refused.TypedCdpCall,SiteCookies,ClearSiteCache, andReloadare refused. AgentFindis refused; the user'sFindstill works (1 match, no refusal).ERR_CONNECTION_REFUSED, not a refusal. The human tab still reads the clipboard.Private,RemoteServer,Preview, andArtifacttabs are unaffected.prove-stopgap-desktop.ts,proof/ws1/stopgap-notice.png): one notice bar with"Open in new tab", andt.urlstaysabout:blank..github/files changed.