Skip to content

fix(browser): partition site permissions by context and prevent Chromium persistence - #305

Merged
Hona merged 6 commits into
devfrom
ws1-fix3-permissions
Nov 20, 2026
Merged

Hona merged 6 commits into
devfrom
ws1-fix3-permissions

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Known Gap (Disclosed Ahead of Merge — Immediate Next HIGH-Urgency Follow-Up PR)

While ALLOW is live in Default's HostContentSettingsMap, an agent_driven (or plugin-controlled) tab in Default on the exact same origin silently inherits notifications and clipboard-read — and geolocation on hosts where OS Location is enabled — for both (a) "Always allow" and (b) "Allow this time" while the granting human tab stays on that origin (camera/microphone stay refused per-tab via on_request_media_access_permission). Fixing controlled-tab permission inheritance + per-tab clipboard-write refusal via per-tab Permissions-Policy, Notification stubbing, and check_cdp userGesture: true stripping is the immediate next HIGH-urgency PR before any engine publish.

Live CEF 156.0.26 Probe Matrix (Default Tab 2 agent_driven: true, same origin http://localhost:<p> as human Tab 1)

  • notifications: (a) "Always allow" -> permissions.query == "granted", new Notification(...) succeeded (ok:test-ORIG_A, 0 prompts). (b) "Allow this time" -> same silent grant while Tab 1 stayed on origin; reverted to "prompt" immediately on Tab 1 cross-origin navigation or close.
  • clipboard-read: (a) "Always allow" -> permissions.query == "granted", navigator.clipboard.readText() succeeded (ok:13, reading "human-copy-ok" off the OS clipboard, 0 prompts). (b) "Allow this time" -> same silent read (ok:13, 0 prompts) while Tab 1 stayed on origin; reverted to "prompt" immediately on Tab 1 cross-origin navigation.
  • camera & microphone (getUserMedia): permissions.query read "granted", however CEF 156 Alloy STILL consulted TabPermissionHandler::on_request_media_access_permission (is_media: true) every time (camPromptConsulted: true, micPromptConsulted: true), so getUserMedia was NOT silently granted (err:NotAllowedError:Permission denied).
  • geolocation: Chromium wrote geolocation: { "http://localhost:<p>,*": { "setting": 1 } } to Default's HostContentSettingsMap. On Windows with OS Location off, GeolocationPermissionContextWin re-prompted (geoPromptConsulted: true); on macOS/Linux (and Windows with OS Location enabled), Chromium resolves geolocation directly from HostContentSettingsMap == ALLOW.
  • Other origins & isolated scopes: Default originB, Private originA, and proxied RemoteServer originA all stayed "prompt" under both (a) and (b).

Round-3 Fix (d590a0b1, Addressing READER-9 Round-2 Blocker)

  • Pre-spawn Default/Preferences lock & temp-file race (crates/browser-pane/src/{profile.rs, prompts/store.rs, transport.rs}):
    • Added profile::try_lock_exclusive(dir) -> Option<File> matching apps/browser-engine/src/profile.rs:98 (create(true).truncate(false).write(true) + try_lock()).
    • scrub_chromium_preferences_for_older_engine now holds both an in-process PREFS_SCRUB_LOCK: Mutex<()> (serializing multi-window spawns in one process) and the exclusive OS engine.lock handle across the entire read-modify-rename (dropping before .spawn()).
    • Uses a monotonic per-call temp filename Preferences.tmp-{pid}-{seq} (PREFS_SCRUB_SEQ: AtomicU64) and removes tmp if either write or rename fails.
    • Live 50-run concurrency proof (probe-prefs-race): 50 runs × 3 concurrent BrowserHost spawns per run (2 in-process threads + 1 external process = 150 spawns over seeded 48 KB Default/Preferences) -> validJson: 50/50, revokedScrubbed: 50/50, keptIntact: 50/50, zeroLeftoverTmps: 50/50.
    • Fixed prove-fix3-r2.ts:73 (navigator.hid.requestDevice({ filters: [] })) and reran on CEF 156.0.26 -> hid: "empty:0" (zero picker, zero grant) across Default, Private, and proxied RemoteServer.

Summary of Changes (Round-1 READER-9 Findings 1–4 + origin/dev b5167f7e Merge)

  1. Finding 1 (AgentClipboardGuard removed): Removed AgentClipboardGuard completely from prompts.rs, handlers.rs, and engine.rs (human clipboard write works while controlled tabs share the origin; per-tab clipboard-write refusal moves to the immediate follow-up PR).
  2. Finding 2 (PermissionTracker lifecycle in apps/browser-engine/src/permissions.rs):
    • Added #[serde(default)] persist: bool to HostMsg::AnswerPermission and HostMsg::SyncSitePermissions { entries } (SitePermissionEntry).
    • "Always allow" / "Never allow" (Default only, persist: true) keep HostContentSettingsMap live until Settings revocation; "Block" (dismiss: true) uses CEF_PERMISSION_RESULT_DISMISS.
    • "Allow this time" (persist: false) is ref-counted per (ctx_scope, tab_id, origin, kind) and reset to DEFAULT on committed cross-origin navigation, tab close, ExtEffect::CloseTab, ReopenTabs, and Shutdown/Drop (before cef::shutdown()).
    • Startup scrub_legacy_content_settings wipes all 6 exact-origin permission tables in Default/Preferences (plus set_website_setting(..., GEOLOCATION_WITH_OPTIONS, None)), and BrowserHost syncs rune.sitePermissions on Ready and every Settings > Browser edit.
  3. Finding 3 (All 7 hardware-device & File System Access guards locked on every context): Locked USB_GUARD, SERIAL_GUARD, HID_GUARD, BLUETOOTH_GUARD, BLUETOOTH_SCANNING, FILE_SYSTEM_READ_GUARD, and FILE_SYSTEM_WRITE_GUARD across Default, isolated context prefs, and per explicit origin on every navigation (Default, Private, proxied RemoteServer).
  4. Finding 4 (RemoteServer VisitOnly + older-engine Settings restart notice): Simplified PermissionScope to { Profile, VisitOnly }; exposed permissionSync on Browser:Engine(); added settings.sites.restartNote (plugins/browser/locales/en.json) + locked pre-spawn Default/Preferences scrub for older engines.
  5. Merge reconciliation (origin/dev b5167f7e incl. #294, #274, #307, #306) & verbatim move: Moved EngineManager::{waits_for_texture, poll_frames, run_frames, frames_failed} verbatim to apps/browser-engine/src/engine/frames.rs (engine.rs 1,451/1,500 lines).

(Zero tests added/edited; zero .github/ edits; zero new third-party crates.)

Verification (d590a0b1, All 5 Targets + Live Proofs)

  • Previous head (e32c10a8) CI: guardrails pass, plan pass, build-macos pass, build-windows (arm64) pass (build-windows (x64) pending, 0 failures).
  • Guardrails: 5/5 passed (engine.rs 1,451/1,500; client.rs 1,472/1,500; 0 errors).
  • Windows: apps/browser-engine --bins, cargo check --workspace, cargo check -p browser-pane --no-default-features — clean (0 warnings).
  • wasm32 (scripts/web.ps1 -Check): clean (0 warnings).
  • Linux (adais, x86_64-unknown-linux-gnu): --workspace --all-targets clean (27 s; apps/browser-engine untouched since e32c10a8 clean check).
  • macOS (air, aarch64-apple-darwin, under mac-lock-as.py): --workspace clean (4 s, air_free: 65.5 GiB).
  • Live proofs (proof/ws1/fix3-permissions.md, OPENCODE_RUNE_OTEL=0, scratch profiles): prove-fix3-r2.ts (fixed navigator.hid.requestDevice -> empty:0), probe-prefs-race (50/50 valid JSON across 150 concurrent multi-thread + multi-process spawns), prove-fix3-settings.ts, #292 pair, #306 probe — ALL PASS.

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

… persistence, use DISMISS, sync revocations, and block agent clipboard write
@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 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
Hona merged commit 00d73a6 into dev Nov 20, 2026
7 checks passed
@Hona
Hona deleted the ws1-fix3-permissions branch November 20, 2026 23:15
Hona added a commit that referenced this pull request Nov 20, 2026
Hona added a commit that referenced this pull request Nov 20, 2026
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