Repository navigation
fix(browser): partition isolated CefRequestContexts by scope, fail closed, and drop on last tab close - #288
Merged
Merged
Conversation
…osed, and drop on last tab close Hardens `apps/browser-engine/src/context.rs` as the single shared `CefRequestContext` creator across WS-1, WS-9 (`#274`), PREVIEWS (`#281`), and BROWSER-TOOLS (resolving `notes/review-rd274.md` Finding 5): - **Partitioned scopes & canonical keys (`ContextKind` / `ContextKey`):** - `Default` -> global persistent profile (`OPENCODE_BROWSER_PROFILE/Default`). - `Preview { workspace, grant }` -> `ContextKey::Preview { workspace, grant }` (distinct per workspace and grant; never shares across workspaces or with artifacts). - `Artifact { artifact_id }` -> `ContextKey::Artifact(artifact_id)` (separate namespace from workspace previews). - `Private` -> `ContextKey::Private(tab_id)` (unique per private tab; never shared). - `RemoteServer { server_id, proxy }` -> `ContextKey::RemoteServer(server_id)` keyed by canonical `ServerKey::as_str()` identity (never display name; keeps `#[serde(alias = "partition")]` for wire compatibility). - **Fail closed on every path:** Empty keys return `browser.context.invalid`; non-loopback proxies return `browser.proxy.invalid`; `cef::request_context_create_context` or `browser_host_create_browser_sync` failure returns `browser.context.unavailable` with an explicit pre-create guard forbidding `!context.is_default() && req_ctx.is_none()`. On desktop, `App::default_browser_context()` always returns `RemoteServer` on non-sidecar servers (never silently falling back to `Default` when an older engine lacks `Ready.partitions`), and pop-ups from isolated contexts never inherit into `Default`. - **Ref-counted teardown & zero disk writes:** Every non-`Default` context runs strictly in memory (`cache_path: ""`, `persist_session_cookies: 0`), disables WebRTC non-proxied UDP/multiple routes, DoH, QUIC, and DNS prefetching, strips `file_roots`, and drops immediately when its last tab closes (`ContextPool::release_tab`, closing connections and wiping cookies/storage/caches/service workers; `RemoteServer` proxy configs remain in `remote_proxies` until `DropContext`). - **Shared hooks for PREVIEWS (`#281`) & WS-9 (`#274`):** Adds `ContextHooks` (`resource_filter`, `exclude_default_cookie_schemes`, `on_created`) on `ContextPool::resolve_with_hooks` and `ContextKind::is_isolated()`, plus preserves `agent_driven` across Linux dmabuf `ReopenTabs`.
|
PR test build retired — merged into |
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
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
Resolves
notes/review-rd274.mdFinding 5 in the sharedapps/browser-engine/src/context.rspool for WS-1, WS-9 (#274), PREVIEWS (#281), and BROWSER-TOOLS (ahead of Phase 3b):CefRequestContextper scope (zero cross-scope sharing):ContextKind::Default-> global persistent profile (OPENCODE_BROWSER_PROFILE/Default,persist_session_cookies: 1).ContextKind::Preview { workspace, grant }->ContextKey::Preview { workspace, grant }(distinct per workspace & grant).ContextKind::Artifact { artifact_id }->ContextKey::Artifact(artifact_id)(separate enum & key namespace fromPreview).ContextKind::Private->ContextKey::Private(tab_id)(unique per private tab; never shared).ContextKind::RemoteServer { server_id, proxy }->ContextKey::RemoteServer(server_id)using canonicalServerKey::as_str()identity (never display name;#[serde(alias = "partition")]kept for wire compatibility).Default):browser.context.invalid), non-loopback proxies (browser.proxy.invalid), andrequest_context_create_context/browser_host_create_browser_syncfailures (browser.context.unavailable) with an explicit guard forbiddingcontext.is_isolated() && req_ctx.is_none().App::default_browser_context()always returnsRemoteServerfor non-sidecar servers (removing#277's fallback toDefaultwhen!engine_partitions()so older engines fail closed withbrowser.partitions.unsupported); isolated pop-ups never inherit intoDefault.file_rootson all isolated contexts (context.is_isolated()) in both host and engine, and preservesagent_drivenacross LinuxReopenTabs.Defaultcontexts use emptycache_path+persist_session_cookies: 0(0 bytes on disk) plus WebRTC/DoH/QUIC/DNS-prefetch lockdown.ContextPool::release_tab(tab_id)ref-counts open tabs perContextKeyand immediately removes the entry, closes all connections, deletes in-memory cookies, and drops theCefRequestContextwhen the last tab closes (retainingRemoteServerproxy configs inremote_proxiesuntilDropContext).ContextPool::resolve_with_hooks(ContextHooks { resource_filter, exclude_default_cookie_schemes, on_created }) for PREVIEWS#281andContextKind::is_isolated()for WS-9#274.Verification
scripts/guardrails.ps1: 5/5 passed (0 errors)cargo clippy -p browser-pane --features engine --no-deps -- -D warnings,cargo check -p browser-pane --no-default-features,cargo check --workspace,scripts/web.ps1 -Check,apps/browser-enginebuild: all passed with 0 warningsproof/ws1/context-isolation.md): Opened 8 tabs on the same127.0.0.1origin (Default, 2Previewworkspaces sharing a grant name,Artifactreusing that name, 2RemoteServeridentities, 2 concurrentPrivatetabs); each set a cookie,localStorageentry, CacheStorage bucket, and active intercepting Service Worker (/sw-whoami) -> 0 leaks across all 56 ordered pairs.Preview,Artifact,RemoteServer, andPrivateand reopening the exact same keys yielded empty cookies, emptylocalStorage, empty CacheStorage, 0 SW registrations, andswWhoami = "NO_SW".browser.context.invalid), and non-loopback proxy (browser.proxy.invalid) all emittedEngineMsg::Refusedwith 0 browsers created.<PROFILE>after shutdown):Defaultsentinel found on disk; 0 bytes of all 7 isolated sentinels anywhere on disk.RemoteServerregression check (prove-p3a.ts):proxyChallenges: 1,proxyAuthedHits: 3,userAuthDuringRemote: 0, 0 direct hits on remote target.