Skip to content

feat(browser-engine): add pierce refusal, unified CDP frame graph, and serialized read/node extension masking - #314

Closed
Hona wants to merge 3 commits into
devfrom
ws9/pr1b2-read-node-masking
Closed

Hona wants to merge 3 commits into
devfrom
ws9/pr1b2-read-node-masking

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Paused pending the owner's decision on agent-tab contexts.

Summary Part 2 of 4 of the extension sub-frame masking split (review-rd274.md #311 & #314 reads). - Refuses pierce: true on DOM.getDocument and DOM.describeNode in crates/browser-policy/src/{cdp,agent}.rs (app + sidecar). - Unified true CDP frame graph & C++ read/node masking (apps/browser-engine/src/extensions/{frame_guard,mask_queue,mask_ops}.rs): merges Page.getFrameTree with Target.getTargets() (type == "iframe", filtered to ancestors of THIS tab's main_frame_id before counting against MAX_FRAME_TREE_NODES = 512), strips closed ShadowRoots, pseudoElements, AX descendants, and extension frames without leaking backendNodeIds, fails closed while any pre-commit extension sub-frame is pending (ctx.has_pending()), and keeps Input.* and Page.captureScreenshot refused on Subframes (Input.* under Option A; screenshots move to PR 1b-4). - Round-2 fixes (closing READER-7 #314 Findings 1–4 + merging dev 95cb36a8): 1. Finding 1 (Accessibility.* + AX cascade + pseudoElements + fail-closed depth): Added ReadFilterKind::AxTree (Accessibility.getFullAXTree, getPartialAXTree, etc.) to is_clean_ext_guarded_method and Clean dispatch; strip_ax_tree now builds a childIds/parentId adjacency map (zero allocations when clean) and BFS-cascades dropped nodes to all descendants (InlineTextBox, pseudo-element AX nodes) plus prunes relatedNodes; walk_dom_for_protected and strip_dom_node walk/strip pseudoElements, and strip_dom_node fails closed (Err) on depth > MAX_DOM_WALK_DEPTH. 2. Finding 2 (Single-target & integer ID validation): parse_single_dom_target / parse_required_node_id / parse_get_document_depth inspect all three of nodeId, backendNodeId, and objectId, reject multi-identifier combos (closing Blink AssertNode nodeId-over-backendNodeId precedence) and JSON floats (12.0), and strip explicit null target keys before forwarding. 3. Finding 3 (Filter & suppress events BEFORE redacting): TabCdpObserver::on_dev_tools_event bumps dom_epoch on DOM.*/Page.*, drops Page.*/DOM.*/Overlay.*/Target.*/Accessibility.* before IPC, drops extension-attributed Runtime.*/Log.*/Network.* events (by origin, stack, frameId, tracked extension requestIds, and tracked extension executionContextIds) before running redact_ext_strings. 4. Finding 4 (DOM.getFrameOwner, awaitPromise timeout, encoded redaction): DOM.getFrameOwner now runs InternalDoc and rejects any owner backendNodeId/nodeId inside a closed ShadowRoot; TabMaskQueue enforces a 10 s engine-side active-op timeout (expire_timed_out + next_mask_deadline wake) so awaited promises never wedge the queue; redact_ext_strings covers bare extension://, blob:extension://, filesystem:*extension://, and percent/double-percent/HTML-entity/unicode-escaped forms. 5. Epoch-scoped protected-set cache (Rc<CachedMaskState>): Keyed on TabPrompts::dom_epoch (bumped by Blink DOM.*/Page.* events and CEF frame/nav lifecycle), computes the pierced DOM/frame sets once per DOM epoch and reuses them across browser.snapshot and querySelectorAll + getBoxModel loops with Mojo-FIFO post-reply epoch verification and 1-shot fresh retry (answering DOM.getDocument via clone_dom_to_depth + DOM.describeNode FIFO fence so Blink's nodeId table stays valid end-to-end). 6. Merged dev 95cb36a8 (#307, #306, #301, #296): Sole conflict in crates/browser-policy/src/lib.rs resolved by keeping #296's mod cdp; pub use cdp::check_cdp; and wiring crate::agent::check_dom_pierce_params(method, params) into crates/browser-policy/src/cdp.rs for "DOM.getDocument" | "DOM.describeNode". ## Known Limit - Non-iframe closed-ShadowRoot extension UI on Clean tabs: On a Clean tab (0 extension iframes), extension content-script widgets rendered purely inside a closed ShadowRoot without an <iframe> remain unreachable by all DOM/AX/node reads (DOM.*, Accessibility.*), while remaining reachable by Page.captureScreenshot (closed in follow-up PR 1b-4) and Input.* (it lives in the page's own DOM; any click on it that opens an extension frame transitions the tab to Subframes, where Input.* is refused). ## Benchmark (2,296 elements / 3,450 DOM nodes, live CEF 156 release, proof/ws9/pr1b2-cache-bench.json) All timings in µs (median (min–max)): | Workload | Extensions inactive (floor) | Extensions active — before caching | Extensions active — after caching | |---|---:|---:|---:| | browser.snapshot (boxes: true, 25 fields + 40 quads, warm, n=15) | 111,891 (95,151–144,641) | 1,364,281 (1,229,625–1,562,354) | 97,055 (84,827–143,761) | | browser.snapshot (boxes: true, cold epoch after DOM edit, n=7) | 133,780 (102,498–148,535) | 1,730,563 (1,437,332–1,895,791) | 126,470 (114,832–193,252) | | browser.snapshot (boxes: false, 25 fields, warm, n=15) | 99,064 (80,633–114,197) | 667,280 (596,869–811,268) | 95,340 (83,253–108,416) | | querySelectorAll (25) + 25× getBoxModel (backendNodeId, n=15) | 4,597 (3,982–6,478) | 611,354 (540,782–809,087) | 6,052 (5,056–16,200) | | querySelectorAll (25) + 25× getBoxModel (nodeId, n=15) | 4,541 (4,222–5,586) | failed at item #2 (Blink nodeId reset) | 6,306 (4,850–8,081) | ## Verification - scripts/guardrails.ps1 5/5 (engine.rs 1,428/1,500; mask_ops.rs 830; mask_queue.rs 807; 0 errors) - cargo check --workspace, browser-policy (aarch64-apple-darwin & x86_64-unknown-linux-gnu), scripts/web.ps1 -Check, apps/browser-engine check & release build (0 warnings, 0 new crates, 0 test files) - Live CEF 156 proofs: proof/ws9/pr1b2-read-node-proof.json (29/29 passed) + proof/ws9/pr1b2-r2-proof.json (29/29 passed: Findings 1–4, multi-target/float rejection, DOM.* event suppression, closed-ShadowRoot iframe getFrameOwner refusal, encoded URL redaction, all 4 cache-invalidation attacks incl. same-origin iframe mutation, and 10 s awaitPromise timeout recovery).

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Test build ready — Download OpenCode-Rune-PR-314-macos-arm64.dmg

  • App: OpenCode (Rune) · ws9-pr1b2-read-node-masking.app (badged #314, bundle ID anomaly.opencode-rune.pr.314)
  • Commit: f9dfed4f0 (0.0.0-pr-314-676, sha256 8fa18699ba6e…)
  • Side-by-side: installs alongside OpenCode (Rune).app without replacing your dev build; retired automatically when this PR closes.
  • Signing: Ad-hoc signed preview (PR code is never signed with release credentials) — after dragging to /Applications, run xattr -cr "/Applications/OpenCode (Rune) · ws9-pr1b2-read-node-masking.app" once before first open.
  • Windows: x64 arm64 — unsigned setup (OpenCode (Rune) · ws9-pr1b2-read-node-masking, installs side by side). SmartScreen asks once: More info, then Run anyway.

@Hona

Hona commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Closing (not merged) per official-parity ruling (
otes/review-rd274.md): with #296 suppressing raw DOM.* on modern servers, #314's pierced DOM walker and epoch cache are replaced by a smaller follow-up PR porting official's typed �xperimental.browser extension-frame isolation (Target.setAutoAttach, �xtensionTargets/�xtensionContexts, rameIndex/�gentFrame, pinned contextId, best-effort input verification) while keeping raw legacy/3P CDP refused outright where extensions are involved. Branch ws9/pr1b2-read-node-masking (head 9dfed4f) and local ws9/pr1b4-screenshot-masking are kept intact for reference.

@Hona Hona closed this Nov 20, 2026
Hona added a commit that referenced this pull request Nov 20, 2026
…P-143 (#318)

- Fold confirmed merged PRs #307 (a1e7d0d, click-to-load reply videos),
  #306 (b5167f7, atomic agent_driven), #301 (6522f11, routed-session
  attach + recency closing #287 regression), #296 (95cb36a, legacy
  rune_mcp suppression + Half::is_builtin + check_cdp), #303 (6fb05ce,
  oc-preview:// app routing + raw file:// ban completing UP-095-PREVIEWS),
  and #316 (6e98fc2, Rune 7a707454 / #1307 strict local video opening)
- Add missing browser follow-up rows UP-095-3P-CONTRACT (#296 narrow
  third-party plugin browser contract gap) and UP-095-PROMPT-GATE
  (new-session-start-only prompt gate split from #302)
- Record #302 split (tunnel vs gate), #314 masking stream paused pending
  owner decision on agent-tab contexts, and updated browser Reviewed entries
- Audit upstream anomalyco/opencode 4122af0206..b9a60d9d07 (+11 commits:
  3 skipped, 8 added UP-136..UP-143)
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