Skip to content

fix(browser): refuse agent calls into granted frames by origin, with inheritance, on every path - #451

Merged
Hona merged 5 commits into
devfrom
ws1-c3-granted-frames
Nov 21, 2026
Merged

Hona merged 5 commits into
devfrom
ws1-c3-granted-frames

Conversation

@Hona

@Hona Hona commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Fixes READER-9 C3 on #411 (notes/review-rd-engine.md, 21 Nov). An agent could act inside an embedded site that holds an inherited grant (clipboard-read, location, notifications), even though #411 refuses agent calls into granted frames.

Cause: target_frame_url picked one frame and decided by its URL. A blank or srcdoc child of the granted frame reads as about:blank, an opaque URL that holds no grant, so the call was let through. It also checked only the app's frame claim or the context, never params.frameId or argument objects. It was never checked again at reply time, and Input.* was checked only against the main frame.

Fix: decide by origin with inheritance, on every path.

  • EngineCdpLedger::reach lists every frame a call can act in: the app's frame claim, params.frameId, the frames of contextId / executionContextId, objectId and each arguments[*].objectId, and the session's own root. For an object the engine did not resolve, it reads the context from V8's <isolate>.<context>.<id> id. Some calls reach the whole tab: Input.* (input lands under the pointer or in the focused frame), uniqueContextId, and any context or object the engine cannot place.
  • frame_origins gives the origins a frame can run as: the securityOrigin Chromium reports, its URL, and every ancestor's origin for about:blank, about:srcdoc and frames with nothing committed yet. A frame the engine does not know, or an overflowed frame table, fails closed.
  • Checked when the call is sent: typed calls, raw calls (which had no OOPIF check before), and UploadFiles (its target session and frame, which feat(browser): complete OOPIF pointer/upload/drop coords, HTML5 drag interception, request postData fallback, and trace/cpu auto-stop timers #446 added) / DropFiles (whole tab).
  • Checked again when the reply comes back: CdpPending::Raw.reach is checked again in refuse_reply, so a grant or a navigation while the call is in flight refuses the reply. A DOM.getNodeForLocation hit is checked against the frame it lands in.
  • Changed behaviour: agent input is refused on a controlled Default tab while any of its frames runs as a granted origin. Key events go to the focused frame, so no narrower rule is safe. The person's own input is not affected.

Proof: READER-9's nesting case (C:\tmp\opencode\ws1\prove-c3-granted-frames.ts, Windows, scratch profile). Un-granted localhost embeds the OOPIF 127.0.0.1, which holds notifications ALLOW. That frame holds an about:blank child and a srcdoc child. A same-shaped OOPIF on 127.0.0.2 with no grant is the control.

Agent call before (dev) after
Runtime.evaluate by contextId in the granted frame's about:blank child ran: ["about:blank","granted"] refused
same in its srcdoc child ran: ["about:srcdoc","granted"] refused
Accessibility.getFullAXTree { frameId: <granted> } with a different frame claim ran (granted frame's tree) refused
typed Input.dispatchMouseEvent over the granted frame ran refused
raw Input.dispatchMouseEvent over the granted frame ran refused
Runtime.evaluate in flight when its frame's origin gains a grant answered refused on reply
control: same calls in the un-granted OOPIF's three frames, main-frame evaluate ran ran

objectId arguments use the same reach path. The proof could not reach them end to end: the typed path takes only engine-resolved objects, and the granted frame's child frame ids are never sent to the app. Regressions on the same build: prove-passkeys.ts, prove-404.ts and the C1/C2 proof all pass.

Checked on dev (merged in before merge): engine build + tools\cargo.ps1 check --locked -p opencode-desktop. ENGINE_REVISION stays 5 (dev = 5, published = 4). Zero test edits, zero .github/ edits.

Also fixes the wrong-reason refusal while a tab's first page loads (found during the C1/C2 proof). Before a controlled tab's first document commits, Chromium reports its frame's securityOrigin as ://. target_frame_url fell back to that origin. has_inherited_default_grant("://") fails closed (unparseable), so typed calls got "Controlled browser actions are blocked on this site because it holds a profile permission" when no grant existed. frame_origins skips :// and null and walks to the URL or the parent instead. Probe: C:\tmp\opencode\ws1\probe-load-refusal.ts sends 30 alternating typed and raw calls during a 1.5 s first load, in a profile with no grants. Wrong-reason refusals: dev 8, 8, 9 (three runs); this branch 0, 0, 0.

@Hona
Hona merged commit e0d00c6 into dev Nov 21, 2026
@Hona
Hona deleted the ws1-c3-granted-frames branch November 21, 2026 09:37
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