Skip to content

fix(dashboard): delegate display-capture to embedded cross-origin panes - #9112

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/pane-display-capture-delegation
Sep 14, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/pane-display-capture-delegation

Conversation

@javenciu

@javenciu javenciu commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

The screen-snip buttons inside an embedded instances pane are dead. Clicking one does nothing — no picker, no error, no snip.

An instances pane is the same dashboard SPA served on the tunnel's loopback port, so it is a cross-origin iframe (same host, different port). navigator.mediaDevices.getDisplayMedia() is denied in a cross-origin frame unless the parent delegates display-capture through Permissions-Policy, and website/src/components/InstancesViewport.tsx delegated only microphone; fullscreen; clipboard-write.

The affordances still render, because the presence gate (isScreenSnipSupported) checks only that the function EXISTS — true inside any iframe. So three surfaces are live buttons that reject on click with NotAllowedError: ChatInput's snip flow, WebPreviewPanel's crop-to-chat, and MochiSnipHost.

Why it matters

Anyone driving a remote crew through an embedded pane — the normal way to use a remote instance — cannot snip at all, and gets no feedback saying why. The failure is silent: the snip code treats the rejection as "user cancelled". Locally (top-level) the same buttons work, so the capability looks intermittent rather than undelegated.

What changed (motivation → approach → change)

The delegation. display-capture joins the pane iframe's allow list, the same one-token delegation microphone, fullscreen and clipboard-write already carry (clipboard-write landed by the same route in #8907). clipboard-read stays undelegated — read is the more sensitive grant class and out of scope here.

The path that delegation opens, and why it was not safe. In a browser, the engine runs its own source picker and delegation only lets the pane ASK. In the packaged app it does not: the renderer's getDisplayMedia() is answered by the main process, and website/electron/display-media.js was the app's own picker. createDisplayMediaHandler ignored its request argument (_request), and chooseDisplaySource took the first screen:* source desktopCapturer returned and granted it. { useSystemPicker: true } at the setDisplayMediaRequestHandler call site prefers the OS picker where one exists, but the fallback runs everywhere it does not.

So the handler answered every requester on its session identically, with no frame or origin check. An iframe shares its parent's session, so delegating display-capture to panes puts a pane's request in front of it — and the answer would be the entire local screen, from one gesture, with no confirmation UI.

The embedded browser panel is NOT part of this: it runs on the persist:kirocrew-browser partition (window-lifecycle.js partition: BROWSER_PARTITION), which registers no display-media handler at all, and a session with no handler rejects the call outright — the premise this module exists for. browser-view.js's header prose still says it shares the default session; the code at the view's construction site does not, and that prose is left for a separate change.

The gate. website/electron/capture-trust.js authorizes a request by identity, not by the shape of the request. All three must hold:

  1. Registered surface — the requesting webContents is one this app created to host its own documents. registerCaptureSurface is called at each such creation site (the dashboard view, the Mochi panel window, the Mochi crop window), so anything else is refused by default instead of by remembering to deny it.
  2. Its own main frame — the request's frame IS that webContents' main frame. This refuses an embedded pane and every other subframe.
  3. Still its registered origin — the frame's document origin exactly matches the origin registered for that webContents, port included.

Why shape is not enough, and this is the part worth reading. The obvious test is request.frame.parent === null, and an earlier revision of this PR used it. It is not sound. parent === null means "top-level frame of this webContents", not "a document this app loaded". The instances-pane iframe carries no sandbox attribute, and the dashboard's webContents has no will-navigate guard (setWindowOpenHandler governs new-window requests only), so a page inside a pane can target="_top"-navigate on a user click and its document then holds the dashboard's main frame. It would pass a frame-position test — and a loopback-hostname origin test as well, since a pane is served from the same host as the dashboard.

Leg 3 compares the port, which is what actually separates them, and it is bound per webContents rather than globally: a secondary window pointed at a remote gateway is a legitimate capture surface on a different loopback port, and it keeps capture on its own origin without authorizing a sibling's document. A promotion to the app's own origin stays granted, deliberately — that origin is the local gateway serving this app's own token-authed pages, so the document is the app's either way.

This is the shape browser-view.js already uses for the same reason: untrustedContents is a WeakSet of webContents identities because an origin heuristic was not enough there either. captureSurfaces is the positive-direction twin, a WeakMap so an entry vanishes with its window.

display-media.js holds no trust rule of its own and denies when deps.isTrustedRequest is absent — a capability gate must fail closed when nobody wired its decision, which is the state this module started in. The check still runs first, before getSources(), so a refused requester never triggers macOS's Screen Recording prompt and never enumerates open-window titles. A refusal reports untrusted-frame, which the call site logs rather than turning into a System Settings dialog: nothing a user changes there makes an unregistered surface grantable.

Three capture surfaces, all registered. ChatInput / useChatPageResourcesController and WebPreviewPanel capture from the dashboard view; MochiSnipHost captures from the Mochi panel window; mochi/snip/main.tsx captures from the Mochi crop window at native resolution. Missing one would have silently cost that window its snip, so each is registered at its creation site and capture-trust.js is added to the packaged files list.

The browser panel is out of reach of all of this by construction, not by the gate: it runs on the persist:kirocrew-browser partition, which registers no display-media handler at all, and a session with no handler rejects the call outright — the premise this module exists for. browser-view.js's header prose still says it shares the default session; the view's construction site passes partition: BROWSER_PARTITION, and that stale line is left for a separate change.

Net effect. In a browser, a pane's snip starts working through the engine's own source picker — the bug this PR set out to fix. In the packaged app, a pane is refused whether it asks from inside the iframe or promotes itself to the top frame: same user-visible outcome as today (the click does nothing), no silent whole-screen grant. The dashboard's own snip and both Mochi capture windows are unchanged, and all of those paths are pinned through the registered handler in website/electron/test/window-lifecycle.test.js.

Making pane capture work under Electron too needs a real in-app source picker that names the requesting frame. That is a separate change and a maintainer decision on the UI, deliberately not a rider here.

Tests

website/src/test/InstancesViewport.test.tsx

  • The allow-list contract pin, extended to display-capture (exact-string and toContain), with clipboard-read's absence still pinned.

website/electron/test/capture-trust.test.js (new)

  • Per leg: a registered surface's own main frame granted; granted across in-app navigation within the registered origin; a same-origin subframe refused, which only the main-frame leg can do (its origin matches exactly); a pane subframe refused; a promotion to a pane origin refused; a promotion to the app's own origin still granted; sibling surfaces on different ports each bound to their own; an unregistered webContents refused; a frame that resolves to no webContents refused.
  • Registration: the origin is kept (so token/query/route changes do not break capture), and an unparseable or opaque origin is refused rather than stored, since "null" would make two unrelated opaque documents compare equal.
  • Every read guarded: a throwing request.frame, fromFrame, wc.mainFrame and frame.url each deny instead of letting the throw escape into Chromium's request handling.
  • The runtime glue is required, not guessed: createCaptureTrust({}) throws.

website/electron/test/display-media.test.js

  • Asserted per verdict with an injected predicate, so it no longer restates the trust rules: a refused request denies with untrusted-frame and a getSources call count of 0, a throwing predicate denies via the existing error path, the request is passed through untouched, and — new — with no trust dep at all, nothing is granted.

website/electron/test/window-lifecycle.test.js

  • The session-security registration test drives the handler configureSession actually registered, through the real createCaptureTrust: the dashboard's registered main frame is granted, and a pane subframe, a promoted top frame and an unregistered surface are all refused with desktopCapturer's call count stuck at 1.
  • A source contract pins that setupWindowContents registers the dashboard view against that window's gateway origin — the harness registers a surface of its own, which would otherwise mask the production call going missing.

Revert-verify — eight mutations, each redden the suites together: the registry leg failing open (3 failing), the main-frame leg removed (1), the origin leg weakened to hostname only, i.e. the rule this replaces (3), the origin leg removed (3), an opaque origin accepted at registration (1), the handler defaulting to trust (1), the dashboard registration call deleted (1), the predicate not passed to the handler (1).

Manual verification

Not performed in a packaged app, and that is a real gap — recorded rather than papered over. The build host this was prepared on has no display server, so electron . cannot be launched to click a real snip.

What IS verified without one:

  • The registered handler is exercised end to end through configureSession, so the wiring, the grant for the dashboard's own surface, and all three deny paths are covered against the real call site rather than against a module in isolation.
  • The field contract is read off the pinned dependency, not assumed: electron@^43.2.0's electron.d.ts declares DisplayMediaRequestHandlerHandlerRequest.frame: WebFrameMain | null and securityOrigin: string, WebContents.fromFrame(frame), and WebFrameMain.parent / .url. The gate reads only those.
  • Registration is bound to a URL the app itself loads (windowBackendUrl, the Mochi baseUrl), and the origin — not the URL — is stored, so in-app routing and token query params cannot break capture.

What a reviewer with a packaged build should confirm, on a platform that takes the desktopCapturer fallback rather than a native picker (Linux):

  1. The dashboard's own snip still opens and captures.
  2. The Mochi crop window (global snip shortcut) still captures.
  3. A snip clicked inside an instances pane logs [display-media] DENY capture: requester is not a registered capture surface instead of capturing.
  4. The same after a pane navigates the top frame — the case that motivated identity authorization.

Screenshots / video

Why no screenshot: the diff is one token in an iframe allow attribute (a non-rendering Permissions-Policy attribute) plus Electron main-process permission logic. No component, layout, style or state changes, and no element is added or removed — a before/after capture would be two identical images. The user-visible difference is that an already-rendered snip button stops rejecting when clicked, which a still frame cannot show.

Related Issues

no linked issue: reported and verified from the code path, not from a filed issue. The clipboard-write delegation referenced above landed by the same route and is cited as precedent for the pattern, not as an issue this PR closes.

Pattern harvest

Pattern: authorizing a capability by the SHAPE of a request instead of the identity of its requester. frame.parent === null reads as "is the app" and means "is top-level", and the two diverge the moment something else can occupy the top frame. The sibling defect this started from is the same family one step earlier: a handler that discards its request argument entirely, so nothing about the requester is consulted at all.

Rule candidate: lint / review-prompt, scoped to website/electron/**. Two shapes are findings on a grant path: (a) a set*RequestHandler / set*Handler callback that names its request or details parameter with a leading underscore, or omits it, and (b) a decision that rests on a frame's POSITION (parent, isMainFrame) or on hostname alone. Bind the decision to an identity the app itself recorded — browser-view.js's untrustedContents WeakSet and capture-trust.js's captureSurfaces WeakMap are the shape to match — and compare origins whole, port included, unless there is a stated reason not to.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — the module header documents the new trust rule and both legs
  • No secrets, credentials, or internal references in the diff

@javenciu
javenciu requested review from a team and patrigao September 6, 2026 20:07
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — 🟡 CONCERNS

UX-level review of bc556402210615374f374dce12981dee941844e7 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: CONCERNS

Browser panes get working snip; in the packaged app the same live-looking snip button still fails silently, acknowledged but unfixed.

Watch

  • Silent dead button in Electron panes persists: the new deny branch emits only console.warn("[display-media] DENY capture…"), and the renderer's captureScreen maps the resulting NotAllowedError to return null // user cancelled (useScreenSnip.ts:94) — so a packaged-app user clicking snip in a pane gets nothing, every time, with no visible explanation. Frequency: every remote-pane snip attempt in the app; impact: friction plus "is this broken?" confusion; persistence: every click. Smallest fix inside this PR's surface: have the untrusted-frame branch surface a user-visible notice (e.g. the pane shows "Screen capture isn't available in embedded panes yet") instead of a console breadcrumb, until the deferred in-app picker lands.

No evidence gap: the diff adds one non-rendering allow token and main-process logic — no control, string, or state changes, so the stated no-visual-delta claim holds. The one user-visible behavior gain (browser pane snip opening the engine's native picker) is engine chrome, not app UI.

[UX-REVIEWED] bc55640

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed bc556402210615374f374dce12981dee941844e7 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] bc55640

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of bc556402210615374f374dce12981dee941844e7 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Identity-based capture trust with fail-closed wiring is the right shape; the rejected shape-test alternative is argued and pinned, and the Electron pane limitation is deliberate.

Suggestions

  • In the packaged app an embedded pane's snip affordances still render and die on click — now by designed refusal; when the deferred in-app picker lands, consider tightening isScreenSnipSupported in the meantime so the affordance hides rather than errors in that one environment.

[DESIGN-REVIEWED] bc55640

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of bc556402210615374f374dce12981dee941844e7 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

All premises verified against the base checkout. The dashboard view has setWindowOpenHandler but no will-navigate guard (window-lifecycle.js:830), the pane iframe carries no sandbox attribute (InstancesViewport.tsx:1009), the browser panel is constructed on BROWSER_PARTITION (window-lifecycle.js:491), the base handler ignores its request and grants the first screen source (display-media.js:50-73), and neither existing trust mechanism (isAppOrigin — hostname-only; untrustedContents — a negative WeakSet on browser-view contents) can separate a pane by port. Renderer capture flows resolve to exactly the three surfaces the PR registers.

First-Principles-Verdict: PASS

Verify on the packaged app that the dashboard's own snip still gets a grant — the fail-closed gate now fronts every capture, so a registration/origin mismatch fails silently.

Not justified as shipped

  1. rides along — lens 1's fix is the delegation; the Electron identity gate is a companion the delegation makes necessary, declared at length.

What this change ships

Inventory (4 items) — 3 justified

Intent: FIX — make the screen-snip buttons inside an embedded instances pane actually capture instead of silently rejecting on click.

  1. Snip inside an embedded pane now works in a browser (parent delegates display-capture) — justified
  2. Packaged app: screen capture granted only to app-registered windows; a pane, embedded or top-promoted, is refused before source enumeration (includes registering the dashboard view and both Mochi windows, and packaging capture-trust.js) — rides along, required by item 1
  3. A refused capture logs one warning instead of raising the macOS Screen Recording dialog — justified
  4. The display-media handler denies everything when no trust predicate is wired (fail-closed) — justified

Evidence run: grepped getDisplayMedia in website/src — all flows land on 3 surfaces, all 3 registered, none missed. Grepped isAppOrigin|untrustedContents in website/electron — 2 existing trust mechanisms, neither compares ports, so capture-trust.js is not a second spelling. registerCaptureSurface: 3 non-test consumers. Base premises (no sandbox on the pane iframe, no will-navigate on the dashboard view, browser panel on its own partition, handler ignoring _request) all confirmed on the checkout.

Watch

The identity gate's runtime glue (webContents.fromFrame, destroyed-frame throw behavior) is pinned only against mocks; if the claim is wrong the packaged app's own snip dies, not the pane's. Clears when: the author confirms a grant on a packaged build on macOS or Linux.

[FIRST-PRINCIPLES-REVIEWED] bc55640

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed bc556402210615374f374dce12981dee941844e7 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] bc55640

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

@javenciu Thanks for this. I audited it against main and the other open PRs. The change is still needed, but one thing has to be resolved before it can land.

Nothing of this goal exists on main yet: website/src/components/InstancesViewport.tsx still carries allow="microphone; fullscreen; clipboard-write", and website/src/test/InstancesViewport.test.tsx still pins that exact string. The only merged PR touching your two files since your merge base is #9141, which reworks warm/connect journaling and leaves the delegation list alone. So there is no duplicate and no supersession here.

The blocker is the security finding, and it is substantiated in the code rather than theoretical. The PR body says every capture runs the browser's own source picker on a user gesture. That does not hold in the packaged app: website/electron/display-media.js chooseDisplaySource auto-selects a screen:* source with no picker and no frame or origin check, and website/electron/window-lifecycle.js passes {useSystemPicker: true}, which only surfaces an OS picker where a native one exists. On the fallback path a delegated cross-origin pane can capture the whole local screen from a single gesture. Please gate subframe capture in this PR, either with a picker or an explicit confirmation, or by restricting delegation to trusted pane origins.

Two smaller items. The branch is well behind main, so please rebase before the next review pass. And #9325 edits the same iframe element in the same file, with its last component hunk ending directly above the lines you rewrite, so expect a textual conflict even though the two behaviours are independent and both can land.

Posted from the 2026-09-08 open-PR relationship audit (read-only, one auditor per PR); reply here if any of this is wrong.

@iamwhatever iamwhatever added the drive-to-green PR claimed by drive-to-green pipeline label Sep 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

Picking this up to drive it to green. The display-capture delegation is the right fix and it is still unfixed on main — but the GPT 5.6 BLOCK-MERGE was upheld on adjudication and @bolichen97's ask for subframe gating is correct, so this needs a realignment before it can go green rather than a rebase.

The finding, verified on main. website/electron/display-media.js createDisplayMediaHandler ignores its request argument (_request), and chooseDisplaySource takes the first screen:* source desktopCapturer returns and grants it. { useSystemPicker: true } at the setDisplayMediaRequestHandler call site only helps where a native picker exists; the fallback runs everywhere else. So once panes are delegated display-capture, a pane could receive the whole local screen from one gesture with no confirmation UI — and the same handler already answers requests from the embedded browser panel, which shares the default session. That voids the PR body's claim that "every capture runs the browser's own source picker".

Plan.

  1. Keep the author's allow-list change and its test pin exactly as written.
  2. Add an identity gate to display-media.js: grant only the top-level frame (request.frame.parent === null) of the app's own origin (request.securityOrigin through the existing isAppOrigin), fail closed on absent/null/throwing fields, deny with a new untrusted-frame reason before getSources() runs. Injected via deps.isTrustedRequest like the module's other seams.
  3. Deny-path unit tests in website/electron/test/display-media.test.js, asserted on a getSources call counter rather than an exit code, plus revert-verify on both legs.
  4. Correct the source comment and the PR body, and add the ## Pattern harvest section main now requires on fix: PRs.

Net effect after the realignment: in a browser the pane's snip starts working through the engine's own source picker; in the packaged app the pane's request is refused instead of silently answered with the desktop. The dashboard's own top-level snip is unchanged, and the browser panel loses an auto-grant it should never have had.

Authorship stays with @javenciu — the commit keeps them as author with a Co-authored-by trailer for the realignment. Reply here if you would rather take it back over.

@iamwhatever
iamwhatever force-pushed the fix/pane-display-capture-delegation branch from d78e9cd to d104cdd Compare September 14, 2026 00:19
@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

@bolichen97 — both of your asks are in, on head d104cdd4.

Rebase. Done: one commit, level with origin/main at 8ea09825, no conflicts. @javenciu stays the commit author.

Subframe capture gating. Done, and your read of it was right — the gap was wider than the delegation. display-media.js's handler took _request and discarded it, so it answered every requester in the default session with the first screen:* source desktopCapturer returned. That means the embedded browser panel (browser-view.js, arbitrary web content, same session, top-level frame) could already reach a whole-screen auto-grant; delegating display-capture to panes would have added a second route to it.

The gate is isTrustedDisplayRequest, and it grants only the top-level frame of the app's own origin:

  • request.frame.parent === null — a pane's subframe carries a parent and is refused.
  • request.securityOrigin through the existing isAppOrigin — a visited https:// page is refused.

Both legs are load-bearing on their own, which is what the revert-verify measures: removing the frame leg leaves 2 tests failing, removing the origin leg leaves 3. A pane is served from loopback exactly like the dashboard, so origin alone admits it; the browser panel's main frame is top-level, so frame alone admits it. Port is deliberately not part of the origin leg — remote hosts arrive through an SSH forward onto that same port, per isAppOrigin's own note — so the frame leg is what separates a pane from the dashboard.

Fail-closed on absent/null/throwing fields (Electron nulls frame after the requesting frame navigates; a destroyed WebFrameMain throws on access). The check runs before getSources(), so a refusal never triggers the macOS Screen Recording prompt or enumerates window titles. Deny path reports untrusted-frame, which the call site logs instead of opening the System Settings dialog — that dialog is for an OS denial the user can act on, and this is not one.

Deny tests assert a getSources call counter of 0 alongside the empty payload, so a denial cannot pass as a granted stream the caller ignored.

One consequence worth naming explicitly, since it is a deliberate scope call rather than an oversight: in the packaged app a pane's snip is now refused by the gate rather than by the missing delegation. Same user-visible outcome as today, no silent whole-screen grant. In a browser it starts working through the engine's own picker, which is the bug this PR set out to fix. Making pane snips work under Electron too needs a real in-app source picker with the requesting frame shown — a separate change, and one that wants a maintainer decision on the UI rather than a rider here.

I also dropped the PR body's "every capture runs the browser's own source picker" claim, which was the sentence the GPT 5.6 lane correctly voided, and added the ## Pattern harvest section main now requires on fix: PRs.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 14, 2026
@iamwhatever
iamwhatever force-pushed the fix/pane-display-capture-delegation branch 2 times, most recently from b9b6f30 to aa1e71d Compare September 14, 2026 00:40
@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

self-added: yes
mechanism: the trust gate and its fail-closed branches were added by this PR's own realignment round, so the risk this names is self-introduced.

  • "Manual verification: N/A" for a gate that only executes in the packaged app — span=d0bf39bf4027 — fixed on the mechanism; the live-run evidence is recorded as not obtained

The mechanism you named is right and it is now closed. The precedent you cited is the load-bearing part: permission-handler.js's header records a fail-closed origin check whose runtime field premise was wrong, which killed the mic in the packaged app while Chrome worked. Reading that module again, the fix it shipped was not "verify the field" — it was stop resting on one field. isAppOrigin reads TWO sources precisely because "neither is always present".

The gate was resting on one. head=aa1e71df changes the origin leg to hand isAppOrigin both of its sources — request.securityOrigin AND the live frame's own url:

return isAppOrigin({ getURL: () => frame.url }, request.securityOrigin);

Either source naming the app grants. So if Electron omits or reshapes securityOrigin on some version or platform, the dashboard's own capture is still granted on the frame's url, and the failure you describe cannot occur from that field being wrong. Each source is pinned granting ALONE (accepts the frame's own url when securityOrigin is absent, accepts securityOrigin when the frame's url throws), and revert-verify narrows the leg to each source in turn — both narrowings redden.

On the field contract itself, read off the pinned dependency rather than assumed: electron@^43.2.0's electron.d.ts declares DisplayMediaRequestHandlerHandlerRequest.frame: WebFrameMain | null and securityOrigin: string as REQUIRED members, and WebFrameMain carries parent: WebFrameMain | null and url: string. frame is documented null only "if accessed after the frame has either navigated or been destroyed" — a request that can no longer be attributed, which is not one to grant. The mic defect was the inverse shape: it ignored a nullability the same type file declared.

Wiring is no longer asserted against the module in isolation. website/electron/test/window-lifecycle.test.js's session-security registration test now drives the handler that configureSession actually registered: the dashboard's own top-level frame is granted, a pane subframe and a foreign top-level origin are refused, and desktopCapturer's call count stays at 1 across all three. Removing the gate reddens that suite too.

What I did NOT do, stated plainly rather than papered over: no packaged-app run. The host this was prepared on has no display server, so electron . cannot be launched to click a real snip, and I will not record a verification I did not perform. Your Clears-when asks for exactly that, so treat this as answered on the mechanism and open on the observation.

The one-minute check for anyone with a build, on a fallback platform (Linux) rather than one with a native picker: the dashboard's own snip still opens and captures, and a snip clicked inside an instances pane logs [display-media] DENY capture: requester is not the app's own top-level frame instead of capturing. The Manual verification section of the description now carries that, plus what is and is not verified without it.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • Pane snip buttons still render and still die silently on click in the packaged app — span=cb6425d69373 — accepted and deferred, taking the recorded-decision route your Clears-when offers

Correct on every fact. The refusal reaches only a main-process console.warn, useScreenSnip.ts reads the rejection as a cancellation, and isScreenSnipSupported is untouched, so the affordance keeps rendering.

The decision, recorded: this PR fixes the browser case and deliberately does not change what a pane snip does in the packaged app. Before it, that click failed silently because display-capture was not delegated at all; after it, the same click fails silently because the gate refuses it. Same user-visible outcome, no silent whole-screen grant added. What the PR will not do is trade the invisible failure for a real one — every route out of it changes renderer behaviour this diff does not otherwise touch, and each is a product decision:

  • Surface the refusal — needs a main→renderer channel for a permission refusal (none exists), a rejection useScreenSnip.ts can distinguish from a cancellation, plus copy and i18n keys.
  • Suppress the affordance — needs an "embedded pane under Electron" signal in the renderer and touches all three consumers, and it hides a capability that DOES work in the same pane loaded in a browser tab.
  • Make it work — an in-app source picker naming the requesting frame, with its own trust story and a decision about what a remote pane may be shown.

Picking among those is a maintainer call on the UI, not a mechanical fix, and folding any of them in here would put a renderer redesign inside a one-token delegation fix.

Filed as #10655 with the three shapes written out, the affected consumers, deferred-finding, an assignee and a due date. The description's Net effect section now states the packaged-app outcome and names the in-app picker as the separate change rather than implying delegation alone fixes both runtimes.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • Packaged-app pane snips still fail invisibly, with no explanation, every attempt — span=aba1fd913379 — accepted and deferred, with both of your fix shapes carried into the tracker

Verified independently, and your severity framing is the right one: task failure × every attempt × permanent is worse than a visible refusal. useScreenSnip.ts's catch { return null } cannot tell a trust refusal from Escape, and untrusted-frame stops at a main-process console.warn.

Not fixed here, and the reason is scope rather than disagreement. Your first shape — route untrusted-frame to a one-line non-modal renderer notice — needs a main→renderer channel for a permission refusal, which does not exist today, plus a rejection the hook can distinguish from a cancellation, plus copy and i18n keys. Your second — gate the affordances off inside Electron-embedded panes — needs a reliable "embedded pane under Electron" signal and touches ChatInput.tsx, WebPreviewPanel.tsx and MochiSnipHost.tsx, and it suppresses a control that DOES work in the same pane opened in a browser tab, so the condition has to be the runtime and not the frame. Either one is a renderer change inside a PR whose whole diff is one iframe attribute token plus main-process permission logic.

Both shapes are written out verbatim in #10655, with a third (a real in-app picker, which is the only route that gives the Electron user the feature rather than an explanation), the three affected consumers, the deferred-finding label, an assignee and a due date. Whoever picks a shape has your analysis in front of them rather than a summary of it.

On the part of your review that was a PASS: the no-visual-delta claim is now carried the way the Screenshot Evidence gate documents for fork PRs — a <!-- no-visual-delta --> marker with a **Why no screenshot:** justification line — rather than as prose the gate cannot read.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

self-added: yes
mechanism: the "always carries both" comment and the fail-closed branches it justified were written by this PR's own realignment round.

  • The grant path rested on an asserted Electron request shape that nothing exercises for real — span=9165573a203b — fixed by removing the single-field dependency; the live-snip observation is recorded as not obtained

You isolated the right sentence. "Only Electron's real request (which always carries both) is granted" was a premise doing load-bearing work with a fabricated request behind it, and fail-closed makes being wrong about it cost the dashboard its own snip.

The answer is not a better assertion, it is not needing the assertion. head=aa1e71df gives the origin leg TWO sources through isAppOrigin — request.securityOrigin and the live frame's url — so one field being absent or differently shaped no longer denies anything:

return isAppOrigin({ getURL: () => frame.url }, request.securityOrigin);

That is the same two-source design permission-handler.js:118-131 documents for exactly this reason ("Checks TWO sources because neither is always present"), which your own verification pass confirmed is the function this patch reuses. Each source is now pinned granting ALONE, and revert-verify narrows the leg to securityOrigin only and to frame.url only — both narrowings redden. So the premise has been demoted from load-bearing to belt-and-braces.

The frame leg still fails closed, and that one I will defend rather than soften: electron@^43.2.0's own electron.d.ts declares frame: WebFrameMain | null and documents the null case as "accessed after the frame has either navigated or been destroyed". A request whose frame is gone cannot be attributed to the dashboard, so granting it would be the actual defect. A revert-verify mutation that accepts frame: null reddens.

Your Clears-when asks for one real snip confirmed granted in the packaged app on a desktopCapturer-fallback platform. Not done, and I am not going to claim otherwise: the host this was prepared on has no display server. The wiring is now exercised through the handler configureSession actually registered (window-lifecycle.test.js), which is as close as this repo can get without a build, and the Manual verification section states what is verified, what is not, and the one-minute check for someone holding a build.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • The fix only lands for browser-served dashboards; Electron pane users keep the silent dead-button failure — span=bca8a3795d81 — accepted and deferred, and "the affordance lies to the packaged-app user" is the right way to put it

Every fact checks out, including the one that stings: useScreenSnip.ts's catch cannot tell a trust refusal from Escape, isScreenSnipSupported is existence-only, and the deny reaches no further than a main-process console.warn. So the packaged app keeps exactly the symptom the Problem section opens with.

Recording the split honestly rather than claiming it away: this PR fixes the browser half of its own motivation and makes the Electron half SAFE without making it work. Before it, a pane click failed silently because the delegation was missing; after it, the same click fails silently because identity refuses it. Same user-visible outcome, no whole-desktop grant on either side of the change.

Why not here. Your Clears-when names two exits and both leave this diff's shape. Distinguishing the denial needs a main-to-renderer channel for a permission refusal (there is none) plus a rejection the hook can tell apart, plus copy and i18n keys. Hiding the affordance needs an "embedded pane under Electron" signal in the renderer and touches ChatInput.tsx, WebPreviewPanel.tsx and MochiSnipHost.tsx — and it suppresses a control that DOES work in the same pane opened in a browser tab, so the condition has to key on the runtime rather than the frame. Both are product calls about whether to hide or explain, inside a PR whose diff is one iframe attribute token plus main-process permission logic.

#10655 carries all three shapes (explain, suppress, or the in-app picker that makes it work), the three affected consumers, deferred-finding, an assignee and a due date. Whoever picks a shape gets the analysis, not a summary of it.

On the part of this round that is not deferred: the gate you called sound is authorized by identity now, not by frame position — registered surface, own main frame, exact origin including the port. That is what closed the target="_top" promotion the GPT lane found on the previous head, and it is pinned by eight revert-verify mutations including one that reintroduces the hostname-only rule it replaced.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • A will-navigate guard on the dashboard webContents would close the promotion vector for every delegated permission at once — span=e1494860bce4 — agreed, already filed, and your generalisation is the reason it is worth doing on its own

Right, and it is the better observation of the two. capture-trust.js closes the CONSEQUENCE for screen capture; it does not close the promotion. Anything else the default session grants the dashboard is still inherited by a promoted document — and permission-handler.js grants media to any localhost origin, so the microphone is reachable by the same click that reached the screen. A per-capability gate cannot keep up with that; the navigation guard is the one place it stops for all of them.

Filed in #10657, which I narrowed this round to exactly the two supporting items now that the identity fix has landed here: the will-navigate guard, and sandbox without allow-top-navigation on the pane iframe. Either one alone also breaks the chain, so they are defence in depth over the identity fix rather than a substitute.

Why the guard is not in this PR, stated as a risk rather than as scope discipline: it is a behavioural change to the dashboard window that refuses navigations, and a wrongly-scoped one would brick the dashboard — worse than the hole it closes. mochi/panelWindow.js already does exactly this against its baseUrl and is the pattern to copy, but confirming that no legitimate in-app top navigation exists (an auth redirect, a deep link) wants someone who can launch the app. The host this drive ran on has no display server, so shipping it here would have meant guessing on a change that can take the whole window down. That constraint is in the issue so the next person does not have to rediscover it.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • The untrusted-frame deny emits only a main-process console.warn, no user-facing feedback, while the snip affordances keep rendering — span=d981a596d478 — accepted and deferred, unchanged from your previous round and unchanged for the same reason

Held, correctly. A console.warn in the main process is invisible to the person clicking, the presence gate keeps the button on screen, and nothing in between translates a refusal into anything a user can read.

The one thing worth adding about the main-process side: the warning is deliberately NOT the System Settings dialog that a macOS Screen Recording denial opens. That dialog exists because the user can act on it; nothing they change there makes an unregistered surface grantable, so pointing them at it would be a dead end wearing a recovery affordance. The message did change this round — it now names the real reason (requester is not a registered capture surface) rather than frame position — but that is diagnosability for whoever reads the log, not feedback for the user, and I am not going to present it as the latter.

Nothing in this round touched the renderer beyond a comment: it moved authorization from frame shape to identity in the main process, which is invisible from the UI.

#10655 carries your two shapes verbatim — a one-line non-modal notice, or gating the affordance off inside Electron-embedded panes — plus a third (a real in-app picker, the only route that gives the user the feature instead of an explanation), the three affected consumers, deferred-finding, an assignee and a due date. Your severity framing from the earlier round is in there as the argument for prioritising it.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • The dead-affordance symptom the description opens with persists for Electron panes, because the presence gate still tests only that the function exists — span=045d7b03ee9f — accepted and deferred; your own reading of it as declared-and-deferred is the one I am confirming

Correct, and thank you for checking the declaration rather than only the code — isScreenSnipSupported at website/src/hooks/useScreenSnip.ts:10 is existence-only, which is true in any frame, so the affordance renders wherever the function exists regardless of whether a capture can succeed.

Confirming the disposition you inferred: it is deferred, not overlooked, and the description says so in its own Net effect section rather than implying the delegation fixes both runtimes. Your Clears-when offers two exits and both are in #10655 — the in-app picker, or teaching the presence gate the delegation/trust verdict. That second one is the cheaper half and needs a main-to-renderer signal that does not exist yet, which is why it is a follow-up rather than a line in this diff.

On the premise side, which is your lane's actual subject: the thing this round changed is that the grant path no longer rests on an assertion about frame position. Authorization is by identity now — a registered capture surface, its own main frame, still on its registered origin with the port compared — so the claim "top-level means the dashboard", which the GPT lane disproved on the previous head, is gone rather than re-argued. I also traced every captureScreen consumer before registering surfaces (dashboard view, Mochi panel, Mochi crop window) rather than assuming which windows capture, because missing one would have cost that window its snip silently. Two coverage gaps that revert-verify caught are written up in the PR comment on this head; both were mine and both are closed.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

Backend Tests (3.12, 1) is inherited, not this PR's

Recording it here so nobody spends the diagnosis twice.

FAILED .../aws_control/crew/runtime/container_tests/test_review_findings.py::test_the_detail_attribute_carries_the_authored_message
  - ModuleNotFoundError: No module named 'httpx'
1 failed, 8885 passed, 33 skipped

Evidence it is not this PR:

  • This PR's diff contains zero .py files — git diff --name-only origin/main...HEAD | grep -c '\.py$' is 0. It is one iframe attribute token, Electron main-process JS, and their tests.
  • The failing file was added to main by feat(aws-control): the crew container image and its runtime (#9223) (6b6d07e841), not here.
  • httpx is a container-runtime dependency that container/requirements.txt marks "must NOT become dependencies of the Kiro Crew app itself", so the app's CI env deliberately does not install it. container_tests/conftest.py carries a guard whose stated job is to decline collection in exactly that environment — the guard did not hold, which is the real defect and is main-side.

Deterministic, so a re-run will not clear it: a missing module does not come and go. I have not patched it — adding httpx to the app's dependencies would contradict the runtime contract that conftest documents, and the fix is a decision about the guard's mechanism (an ignore does not survive explicit node selection the way a skip does).

Filed as #10723 with the mechanism, two candidate causes to check, and fix shapes.

Everything else on 00229b82ab796340171731562c1ee5c0f6ca9690 is green, and every review lane is answered: GPT and Opus clean with no line-level findings, First Principles PASS, Design and UX at advisory CONCERNS with a disposition each.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

Correcting my own note on the Backend Tests (3.12, 1) red

My earlier comment called it inherited and pointed at sharding. The classification holds; the mechanism I gave was wrong, and one thing I implied is false in a way that would send the next reader the wrong direction.

Main is GREEN on this. The CI run on bc22d866fe — this PR's exact base — has all four 3.12 shards passing. So "check main and you will see it too" does not work, and taken at face value that looks like evidence the PR is at fault.

It is not, and the reason is the mechanism. Verified end to end:

  1. This PR's diff has zero .py files, so the changes job sets only_frontend=true.
  2. The backend lane's Select test scope step then takes the reduced path: ci-surface-tests.py --surface backend --summary. Run on this checkout it emits 531 files, three of them from the tree in question, including container_tests/test_review_findings.py.
  3. Run tests passes those paths to pytest as explicit command-line arguments.
  4. A path named explicitly on the command line is not subject to collect_ignore_glob — which is the entire mechanism container_tests/conftest.py uses to decline this tree when the image runtime deps (httpx, fastapi, uvicorn) are absent, as they deliberately are in the app's CI env.
  5. test_review_findings.py is collected, imports container.supervisor.backend, which imports httpx → ModuleNotFoundError.

Main never reaches step 2, because main is not a frontend-only diff: it runs the full suite with no explicit targets, the ignore applies, the tree is skipped as designed. The guard holds on exactly the runs that do not need it and is bypassed on the ones that do.

Two consequences worth stating plainly:

  • It will fail on every push of this PR, and on any other frontend-only PR. Not a flake, not a re-run candidate, and not something a change to this diff can avoid — the trigger is the absence of Python files, so the only way for this PR to make it go away would be to add unrelated backend code.
  • This PR therefore cannot reach failing=0 while container_tests collect-ignore guard is bypassed on frontend-only diffs, reddening a backend shard on httpx #10723 is open, through no fault of its own. Coverage Gate is a cascade of it (frontend-test=success frontend-coverage-merge=success backend-test=failure → backend-test=failure -- failing closed), so the two reds are one cause.

#10723 is updated with the verified chain, a corrected title, a local reproduction, and corrected fix shapes — the short version being that collect_ignore_glob cannot survive explicit selection, so the decline belongs on the items (importorskip / a shared pytestmark), and it has to cover the transitive case, since test_review_findings.py imports no image dep directly and still fails.

Everything else on 00229b82ab796340171731562c1ee5c0f6ca9690 is green, and every review lane is answered: GPT and Opus clean with no line-level findings, First Principles PASS, Design and UX at advisory CONCERNS with a disposition each.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

Ready for maintainer review — 00229b82ab796340171731562c1ee5c0f6ca9690

Rebased onto origin/main at bc22d866fe, one commit, @javenciu preserved as author. Every review lane is stamped and answered. The two remaining reds trace to one main-side defect this PR cannot cause or avoid.

Review lanes, all fresh on this head

Lane Verdict
GPT 5.6 clean, no findings
Opus 4.8 clean, no findings
First Principles PASS
Design CONCERNS (advisory) — "sound identity-based capture gate"
UX CONCERNS (advisory)

Zero line-level findings. 17 disposition comments, 17 from verified writers, no rule violations. Every advisory item has its own disposition and a tracker.

What the change is

@javenciu's display-capture delegation, kept as written, plus the gate the review rounds asked for.

website/electron/capture-trust.js authorizes a capture request by identity, not by the shape of the request. All three must hold: the requesting webContents is one this app registered as its own capture surface; the frame is that webContents' main frame; and the document's origin still exactly matches the registered origin, port included.

That third leg is what closed the target="_top" promotion the GPT lane found on the previous head. frame.parent === null means "top-level frame of this webContents", not "a document this app loaded" — a page inside a non-sandboxed iframe can navigate the top frame and inherit its position, passing both a frame-position test and a loopback-hostname origin test. The port is what separates them, and the binding is per webContents, so a secondary window on a remote gateway keeps capture on its own origin without authorizing a sibling's.

display-media.js now holds no trust rule of its own and denies when the dep is absent — a capability gate must fail closed when nobody wired its decision.

Three capture surfaces are registered at their creation sites (dashboard view, Mochi panel window, Mochi crop window), traced from every captureScreen consumer rather than assumed, since missing one would cost that window its snip silently. capture-trust.js is in the packaged files list.

Eight revert-verify mutations, all caught, including one that reintroduces the hostname-only rule this replaces. Full Electron suite 1892 passing.

The two reds are one inherited cause

Backend Tests (3.12, 1) fails on ModuleNotFoundError: No module named 'httpx', and Coverage Gate fails closed off it (backend-test=failure). Filed and fully diagnosed as #10723.

The trigger is that this PR is frontend-only — zero .py files — which puts the backend lane on the reduced-scope path, where test files are passed to pytest as explicit arguments, and an explicitly-named path is not subject to the collect_ignore_glob that container_tests/conftest.py relies on to decline that tree when the image deps are absent. Main runs the full suite, so the ignore applies there and main is green. Nothing in this diff can avoid it short of adding unrelated backend code.

One thing I got wrong, so the status field is not trusted

PR Readiness currently reads failure | 1 blocking readiness item(s). That value is from my own manual re-fire and it is not reliable: the event-driven run computed at 06:07, before CI finished, and my two re-fires produced contradictory lane snapshots that listed lanes as in_progress which had completed an hour earlier — one reported failed=[], the other failed=[GPT 5.6 Review (failure)] while both GPT check-runs on this head are SUCCESS. Re-firing readiness is the documented remedy when every check is green and the status is stale; here the checks are not all green, so it could not produce passed and only republished a racing snapshot. My mistake, and I stopped rather than dispatch again.

Read the check-runs instead. The only two non-green on this head are the pair above:

completed/failure  Backend Tests (3.12, 1)
completed/failure  Coverage Gate

What is left for a human

  1. A packaged-build check. The Design lane asked for it across rounds and it is the one thing I could not do — this host has no display server, so I did not run it and did not record it as done. On a platform taking the desktopCapturer fallback (Linux): the dashboard's own snip captures; the Mochi crop window captures; a pane snip logs [display-media] DENY capture: requester is not a registered capture surface; and the same holds after a pane navigates the top frame.
  2. container_tests collect-ignore guard is bypassed on frontend-only diffs, reddening a backend shard on httpx #10723, or a decision to merge past it. This PR cannot reach failing=0 while it is open.
  3. Display-media trust gate authorizes by frame shape, so a top-navigated pane passes it #10657 — the two supporting fixes for the promotion vector: a will-navigate guard on the dashboard webContents (wider than capture — a promoted document inherits every default-session grant, including the microphone) and sandbox without allow-top-navigation on the pane iframe. Both deliberately out of this PR: the guard refuses navigations on the dashboard window, and a wrongly-scoped one bricks it, which wants someone who can launch the app.
  4. Packaged-app pane snips fail silently after the display-capture trust gate #10655 — packaged-app pane snips still fail silently. Three fix shapes; it is a product call between hiding the affordance and explaining it.

drive-to-green left on. Nothing merged, no auto-merge armed.

An instances pane is the same SPA on the tunnel's loopback port, so it is
a CROSS-ORIGIN iframe and `getDisplayMedia()` is denied there unless the
parent delegates `display-capture` via Permissions-Policy. The snip
affordances still RENDER inside the pane, because the presence gate
(`isScreenSnipSupported`) only checks that the function EXISTS -- true in
any frame -- so ChatInput's snip flow, WebPreviewPanel's crop-to-chat and
MochiSnipHost are live buttons that die on click with NotAllowedError.
Adding `display-capture` to the pane iframe's `allow` list is the same
one-token delegation microphone, fullscreen and clipboard-write already
carry.

Delegating it also opens a second path, and that path was not safe. In
the packaged app the renderer's call is answered by the main process, and
`display-media.js` was the app's OWN picker: it ignored the request
argument, took the first `screen:*` source `desktopCapturer` returned,
and granted it. `{ useSystemPicker: true }` prefers the OS picker where
one exists, but the fallback runs everywhere it does not. An iframe
shares its parent's session, so a delegated pane's request would have
reached that grant -- the whole local screen, from one gesture, with no
confirmation UI.

Fix: authorize the request by IDENTITY, in a new `capture-trust.js`.
A request is granted only when all three hold:

  1. Its webContents is REGISTERED as one of the app's own capture
     surfaces. `registerCaptureSurface` is called where each is created
     -- the dashboard view and the Mochi panel/crop windows -- so
     anything else is refused by default rather than by remembering to
     deny it.
  2. Its frame IS that webContents' main frame, which refuses an
     embedded pane and every other subframe.
  3. Its document's origin still EXACTLY matches the origin registered
     for that webContents, port included.

Shape is deliberately not the test. `frame.parent === null` means
"top-level frame of this webContents", NOT "a document this app loaded":
a page inside a non-sandboxed iframe can navigate the top frame with
`target="_top"` on a user click, and the promoted document then holds the
dashboard's main frame. It would pass a frame-position test, and a
loopback-HOSTNAME origin test as well, since a pane is served from the
same host. Leg 3 compares the port, which is what separates them, and it
is bound per webContents so a secondary window on a remote gateway keeps
capture on its own origin without authorizing a sibling's.

`display-media.js` therefore holds no trust rule of its own and denies
when `deps.isTrustedRequest` is absent: a capability gate must fail
closed when nobody wired its decision. The check still runs before
`getSources()`, so a refused requester never triggers macOS's Screen
Recording prompt or enumerates open-window titles. A refusal reports
`untrusted-frame`, which the call site logs rather than turning into a
System Settings dialog: nothing the user can change there makes an
unregistered surface grantable.

The embedded browser panel is out of reach of all of this by
construction, not by the gate -- it runs on the `persist:kirocrew-browser`
partition, which registers no display-media handler, and a session with
no handler rejects the call.

Net effect: a browser pane's snip starts working through the engine's own
source picker, and the packaged app refuses a pane whether it asks from
inside the iframe or promotes itself to the top frame. The dashboard's
own snip and both Mochi capture windows are unchanged.

Tests: the `allow`-list contract pin; `capture-trust.js` covered per leg,
including a same-origin subframe (which only the main-frame leg can
refuse), a promotion to a pane origin, a promotion to the app's own
origin (still granted -- that origin is the app's own gateway), sibling
surfaces on different ports, an unregistered webContents, an
unregistered opaque origin, and every read throwing; `display-media.js`
asserted per verdict with a getSources CALL COUNTER, including that it
denies with no trust dep at all; and the session-security registration
test drives the handler `configureSession` actually registered, with the
subframe, the promoted frame and an unregistered surface all refused.
Revert-verify: eight mutations -- each leg, the hostname-only rule this
replaces, an accepted opaque origin, the fail-open handler default, the
missing registration call, and the unwired predicate -- each redden.

## Pattern harvest

Defect class: authorizing a capability by the SHAPE of a request instead
of the identity of its requester. `frame.parent === null` reads as "is
the app" and means "is top-level", and the two diverge the moment
something else can occupy the top frame.

Rule candidate: in `website/electron/**`, a grant path that decides on a
frame's position (`parent`, `isMainFrame`) or on hostname alone is a
finding. Bind the decision to an identity the app itself recorded --
`browser-view.js`'s `untrustedContents` WeakSet and this module's
`captureSurfaces` WeakMap are the shape to match -- and compare origins
whole, port included, unless there is a stated reason not to.

Co-authored-by: Joe Guo <zejiangg@amazon.com>
@iamwhatever
iamwhatever force-pushed the fix/pane-display-capture-delegation branch from 00229b8 to bc55640 Compare September 14, 2026 15:37
@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

Rebased onto current main to pick up the httpx fix — bc556402210615374f374dce12981dee941844e7

The backend red is fixed on main and this PR now carries it. Base is origin/main at c719ef81aa, still one commit, @javenciu preserved as author, no code change — a base sync only.

Correcting my own two comments above

The bug was already filed as #10700 and fixed by #10709 (66cc779d6f), merged at 06:26 UTC. My duplicate issue #10723 is closed with credit.

One thing from that comment does still stand and is worth keeping: a re-run would not have helped. GitHub had not recomputed refs/pull/9112/merge after the base moved — it still read Merge 00229b82 into bc22d866fe — so replaying the run would have replayed the stale merge. Verified before pushing rather than assumed; the rebase was the only route.

@rubencu's fix is also better than the shape I suggested. I proposed importorskip / a shared pytestmark; the fix substitutes a declining collector in pytest_pycollect_makemodule, which holds however the file is reached — directory walk, explicit file argument, or file.py::test node id — and declines before import instead of relying on each module to guard itself.

Verified locally on the rebased tree

$ python3 -m pytest .../container_tests/test_review_findings.py -q
1 skipped

That is the exact invocation that failed before: naming the file directly now declines.

Plus, unchanged by the rebase: Electron suite 1892 passing, InstancesViewport 45 passing, tsc clean, brand and comment-history gates green against the new base.

Where this leaves the PR

The identity gate is unchanged from the review round the lanes already judged — GPT clean, Opus clean, First Principles PASS, Design and UX advisory CONCERNS, all dispositioned. The lanes will re-stamp on this head; nothing in the diff moved, so no new verdict is expected on the code.

Remaining, and both need a human:

  1. A packaged-build check — the one Design ask I cannot satisfy (no display server here). On a desktopCapturer-fallback platform: the dashboard's own snip captures; the Mochi crop window captures; a pane snip logs [display-media] DENY capture: requester is not a registered capture surface; and the same after a pane navigates the top frame.
  2. Approval — the branch rules require one approving review, code-owner review, and the team required for website/src/** and website/electron/**. Worth noting dismiss_stale_reviews_on_push: true and require_last_push_approval: true: this rebase was deliberately done BEFORE asking for review, so no paid approval was thrown away, and further pushes should be avoided once one lands.

#10657 (the will-navigate guard and pane iframe sandbox) and #10655 (silent pane snips under Electron) stay open as follow-ups. Neither gates this PR.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • Silent dead button in Electron panes persists; the deny branch emits only a console breadcrumb — span=d168f2dd4f2a — accepted and deferred, and your headline is the honest summary of this PR

"Browser panes get working snip; in the packaged app the same live-looking snip button still fails silently, acknowledged but unfixed" — that is exactly right, and it is the shape of the change rather than an oversight in it. Every fact checks out: useScreenSnip.ts:94 maps the rejection to return null // user cancelled, so nothing downstream can tell a trust refusal from Escape, and the refusal stops at a main-process console.warn.

On your smallest-fix suggestion specifically: surfacing a notice is not inside this PR's surface, which is the one thing I would push back on. The untrusted-frame branch lives in the Electron MAIN process; the notice would have to render in the RENDERER, and there is no main-to-renderer channel for a permission refusal today. So the "smallest fix" is a new IPC path plus a rejection the hook can distinguish plus copy plus i18n keys — a renderer feature, not a change to the branch that logs. That is why it is a follow-up and not a line here.

The other route, hiding the affordance, has a real product cost you should weigh when the follow-up is picked up: the same control DOES work in the same pane opened in a browser tab, so suppression has to key on the runtime rather than on the frame, and it hides a capability rather than explaining it.

#10655 carries both of your shapes plus a third (the in-app picker, the only route that gives the user the feature instead of an explanation), the three affected consumers, deferred-finding, an assignee and a due date.

Nothing in this head touched the renderer — it is a base-sync rebase onto current main with no code change, taken to pick up the httpx CI fix (#10709). Your evidence-gap finding is unchanged and still correct: one non-rendering allow token plus main-process logic, so the no-visual-delta claim holds.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • Consider tightening isScreenSnipSupported so the affordance hides rather than errors in the packaged app, until the in-app picker lands — span=d6b7857c7442 — accepted as an interim shape and recorded in the tracker

Agreed on the framing, including "now by designed refusal" — that distinction matters and I am glad it reads that way. Before this PR the pane click failed because the delegation was missing; now it fails because identity refuses it. Same outcome for the user, no whole-desktop grant available in either case.

Your interim suggestion is the cheapest of the three shapes on the table and is written into #10655 as such. What it needs that this diff does not have: isScreenSnipSupported is existence-only today (typeof getDisplayMedia === 'function', true in any frame), so making it environment-aware means giving the renderer a way to know "I am an embedded pane under Electron" — and it touches ChatInput.tsx, WebPreviewPanel.tsx and MochiSnipHost.tsx.

One caution for whoever implements it, since "hide it in that one environment" is easy to state and easy to get wrong: the condition has to be the RUNTIME plus the frame, not either alone. The same pane opened in a browser tab captures fine, and the dashboard's own top-level snip must keep rendering everywhere. A gate keyed only on "embedded" would break the browser case that this PR just fixed.

No code change for this item on this head — it is a base-sync rebase onto current main, taken to pick up the httpx CI fix (#10709), with the diff unchanged.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

self-added: yes
mechanism: the identity gate and its runtime-glue assumptions were introduced by this PR's realignment rounds, so the unverified surface is self-introduced.

  • The identity gate's runtime glue is pinned only against mocks; if the claim is wrong the packaged app's OWN snip dies, not the pane's — span=895c73fb0cac — accepted; this is the standing open item and it resolves on a packaged build, not on anything I can push

The asymmetry you name is the right thing to be worried about, and it is worth stating plainly rather than softening: this gate fails CLOSED, so a wrong assumption about webContents.fromFrame or destroyed-frame behaviour costs the DASHBOARD its snip. The pane losing capture is the intended outcome; the dashboard losing it would be the regression, and no test here can catch that because every test supplies the mock.

What I can offer as evidence, labelled as what it is — the pinned dependency's own type contract, not an observation:

  • electron@^43.2.0's electron.d.ts declares WebContents.fromFrame(frame: WebFrameMain): WebContents | undefined, WebFrameMain.parent: WebFrameMain | null and WebFrameMain.url: string. Those four reads are all the gate performs.
  • Every one of them is individually guarded, and each guard denies rather than throwing — a throw from here would land inside Chromium's request handling. capture-trust.test.js pins a throwing request.frame, a throwing fromFrame, a throwing wc.mainFrame and a throwing frame.url separately.
  • The wiring is exercised through the handler configureSession actually registers (window-lifecycle.test.js), not against the module alone, so the gate cannot be present in the module and absent from the real call site.

None of that is a live grant, which is what your Clears-when asks for. Not done, and I will not record it as done: this host has no display server, so electron . cannot be launched. That is the one item that has stayed open across every round, and it is now the last thing between this PR and a maintainer decision.

The check, on macOS or Linux (both take the desktopCapturer fallback; macOS additionally exercises the TCC leg): the dashboard's own snip captures; the Mochi crop window captures; a pane snip logs [display-media] DENY capture: requester is not a registered capture surface; and the same holds after a pane navigates the top frame. The first two are the ones your finding is about — they are the regression risk, and the third and fourth are the property the gate exists for.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

  • The Electron identity gate listed as riding along on the delegation fix — span=3f6ca68fb361 — accepted as stated, and "a companion the delegation makes necessary" is the accurate reading

Agreed, and I would not want it recorded as anything else. The delegation is the fix; the gate is not an independent improvement someone slipped in, it is the cost of making the delegation safe. Shipping the first without the second would have put a remote cross-origin pane one gesture away from the whole local screen on the desktopCapturer fallback path — so the smaller-looking change was never actually available.

One note on how the rider grew, since your lens is whether the shipped surface is the smallest honest version: it grew because the review rounds proved the cheap version wrong, not by accretion. The first attempt gated on frame position (parent === null), the GPT lane showed a pane can target="_top"-navigate the top frame and inherit that position, and identity is what actually holds. Each step replaced the previous rule rather than layering on top of it — display-media.js now carries no trust rule at all, and the frame-position and hostname-only rules are both gone rather than kept as extra legs.

No code change for this item. This head is a base-sync rebase onto current main, taken to pick up the httpx CI fix (#10709); the diff is identical to the one your PASS verdict judged.

@iamwhatever

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: iamwhatever#241cc860]:

Best state this PR has been in — bc556402210615374f374dce12981dee941844e7

Superseding my earlier maintainer-review summary, which was written when two checks were red. Both of those are gone: the httpx failure was a main-side defect (#10700, fixed by #10709) that this head now carries, and the Coverage Gate cascade went with it.

Lane Verdict
GPT 5.6 clean, no findings
Opus 4.8 clean, no findings
Design PASS
First Principles PASS
UX CONCERNS (advisory, dispositioned)

0 failing checks. 21 disposition comments, 21 from verified writers, no rule violations. Design has moved BLOCK → CONCERNS → PASS across the three rounds.

What is still running

Five macOS jobs — Build Desktop (macos-15), Backend Tests (macOS) 1-3, E2E Gateway Boot (macos-15) — have been QUEUED for roughly 100 minutes without starting, plus the readiness recompute behind them. Hosted macOS runner shortage: nothing has started and failed, so there is nothing to re-run or classify.

I am standing my polling loop down rather than keep waking to re-read an unmoving queue. If one of those jobs goes red once it starts, it will need a look — everything else on this head is settled.

What needs a human, unchanged

  1. A packaged-build check. The one item open across every round, and the one I cannot do — this host has no display server, so I never ran it and never recorded it as done. First Principles pointed it at the right risk on this head: the gate fails CLOSED, so a wrong assumption about webContents.fromFrame costs the DASHBOARD its snip, not the pane's. On macOS or Linux: the dashboard's own snip captures; the Mochi crop window captures; a pane snip logs [display-media] DENY capture: requester is not a registered capture surface; and the same after a pane navigates the top frame. The first two are the regression check, the last two are the property the gate exists for.
  2. Approval. PR Readiness is the only required status check; beyond it the rules need one approving review, code-owner review, and the team required for website/src/** and website/electron/**. dismiss_stale_reviews_on_push and require_last_push_approval are both on, so the rebase was deliberately done BEFORE asking for review and no further push should land once an approval does.

#10657 (dashboard will-navigate guard, pane iframe sandbox) and #10655 (silent pane snips under Electron) remain open follow-ups. Neither gates this PR.

drive-to-green left on. Nothing merged, no auto-merge armed.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 14, 2026
@bolichen97
bolichen97 merged commit d55c8c5 into kirodotdev:main Sep 14, 2026
85 checks passed
@dwu96 dwu96 removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 14, 2026
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 14, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…es (kirodotdev#9112)

An instances pane is the same SPA on the tunnel's loopback port, so it is
a CROSS-ORIGIN iframe and `getDisplayMedia()` is denied there unless the
parent delegates `display-capture` via Permissions-Policy. The snip
affordances still RENDER inside the pane, because the presence gate
(`isScreenSnipSupported`) only checks that the function EXISTS -- true in
any frame -- so ChatInput's snip flow, WebPreviewPanel's crop-to-chat and
MochiSnipHost are live buttons that die on click with NotAllowedError.
Adding `display-capture` to the pane iframe's `allow` list is the same
one-token delegation microphone, fullscreen and clipboard-write already
carry.

Delegating it also opens a second path, and that path was not safe. In
the packaged app the renderer's call is answered by the main process, and
`display-media.js` was the app's OWN picker: it ignored the request
argument, took the first `screen:*` source `desktopCapturer` returned,
and granted it. `{ useSystemPicker: true }` prefers the OS picker where
one exists, but the fallback runs everywhere it does not. An iframe
shares its parent's session, so a delegated pane's request would have
reached that grant -- the whole local screen, from one gesture, with no
confirmation UI.

Fix: authorize the request by IDENTITY, in a new `capture-trust.js`.
A request is granted only when all three hold:

  1. Its webContents is REGISTERED as one of the app's own capture
     surfaces. `registerCaptureSurface` is called where each is created
     -- the dashboard view and the Mochi panel/crop windows -- so
     anything else is refused by default rather than by remembering to
     deny it.
  2. Its frame IS that webContents' main frame, which refuses an
     embedded pane and every other subframe.
  3. Its document's origin still EXACTLY matches the origin registered
     for that webContents, port included.

Shape is deliberately not the test. `frame.parent === null` means
"top-level frame of this webContents", NOT "a document this app loaded":
a page inside a non-sandboxed iframe can navigate the top frame with
`target="_top"` on a user click, and the promoted document then holds the
dashboard's main frame. It would pass a frame-position test, and a
loopback-HOSTNAME origin test as well, since a pane is served from the
same host. Leg 3 compares the port, which is what separates them, and it
is bound per webContents so a secondary window on a remote gateway keeps
capture on its own origin without authorizing a sibling's.

`display-media.js` therefore holds no trust rule of its own and denies
when `deps.isTrustedRequest` is absent: a capability gate must fail
closed when nobody wired its decision. The check still runs before
`getSources()`, so a refused requester never triggers macOS's Screen
Recording prompt or enumerates open-window titles. A refusal reports
`untrusted-frame`, which the call site logs rather than turning into a
System Settings dialog: nothing the user can change there makes an
unregistered surface grantable.

The embedded browser panel is out of reach of all of this by
construction, not by the gate -- it runs on the `persist:kirocrew-browser`
partition, which registers no display-media handler, and a session with
no handler rejects the call.

Net effect: a browser pane's snip starts working through the engine's own
source picker, and the packaged app refuses a pane whether it asks from
inside the iframe or promotes itself to the top frame. The dashboard's
own snip and both Mochi capture windows are unchanged.

Tests: the `allow`-list contract pin; `capture-trust.js` covered per leg,
including a same-origin subframe (which only the main-frame leg can
refuse), a promotion to a pane origin, a promotion to the app's own
origin (still granted -- that origin is the app's own gateway), sibling
surfaces on different ports, an unregistered webContents, an
unregistered opaque origin, and every read throwing; `display-media.js`
asserted per verdict with a getSources CALL COUNTER, including that it
denies with no trust dep at all; and the session-security registration
test drives the handler `configureSession` actually registered, with the
subframe, the promoted frame and an unregistered surface all refused.
Revert-verify: eight mutations -- each leg, the hostname-only rule this
replaces, an accepted opaque origin, the fail-open handler default, the
missing registration call, and the unwired predicate -- each redden.

## Pattern harvest

Defect class: authorizing a capability by the SHAPE of a request instead
of the identity of its requester. `frame.parent === null` reads as "is
the app" and means "is top-level", and the two diverge the moment
something else can occupy the top frame.

Rule candidate: in `website/electron/**`, a grant path that decides on a
frame's position (`parent`, `isMainFrame`) or on hostname alone is a
finding. Bind the decision to an identity the app itself recorded --
`browser-view.js`'s `untrustedContents` WeakSet and this module's
`captureSurfaces` WeakMap are the shape to match -- and compare origins
whole, port included, unless there is a stated reason not to.

Co-authored-by: Joe Guo <zejiangg@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants