Skip to content

fix(desktop): refuse dashboard top-level navigation off the app origin - #23868

Merged
iamwhatever merged 1 commit into
mainfrom
fix/10657-dashboard-will-navigate
Oct 25, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/10657-dashboard-will-navigate

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A page inside a dashboard pane can no longer take over the desktop app's main window.

The instances-pane iframe can top-navigate the dashboard window. The dashboard WebContents has no will-navigate guard, so the pane's own document then becomes the top frame. That document holds every default-session grant the dashboard has, including media (the microphone) for localhost origins. The capture trust gate from #9112 already refuses the screen-capture part; the navigation itself is still allowed.

Why it matters

Any page served into a pane (a remote crew, a local app on another port) could promote itself to the main window and act with the dashboard's permissions. A promoted page also strands the user: the app is no longer showing the dashboard.

Not a goal

  • Adding sandbox to the instances-pane iframe (the issue's other item). It can break the pane, so it needs its own PR and a manual check.
  • Opening refused URLs in the system browser. The guard only refuses.
  • Changing what the capture trust gate or the window-open handler allows.

What changed (motivation → approach → change)

A pane top-navigates the dashboard → no will-navigate listener on the dashboard WebContents → add one that refuses the move.

Target of a page-started top navigation Result
http(s) on the window's own origin (scheme, host and port) allowed
another port, another host, 127.0.0.1 vs localhost refused
file:, blob:, data:, unparseable refused

createNavigationGuard in website/electron/external-scheme.js reuses the existing classifyNavigation same-origin check. window-lifecycle.js arms it on the dashboard view and on every pop-out window, next to the window-open handler. A refusal logs only the target's origin, never the full URL. Main-process loadURL/loadFile calls do not emit will-navigate, so boot, reconnect, token retry and recovery loads are unaffected. The token prompt's own hand-off goes to http://localhost:<port>, which is the window's origin, so it still passes.

Decision on "own origin": the origin each window was opened on (windowBackendUrl), the same value the capture trust gate and the window-open handler already use. Exact match, no loopback-alias widening.

Backwards compatibility

Compatible: every in-app top navigation in website/src goes through withBase(...) on the dashboard origin, and every shell page hands off to the window's own origin.

Reader: website/electron/window-lifecycle.js:setupWindowContents -- release -- dashboard routes and the token-prompt hand-off stay same-origin; refuses a top-level navigation off the app origin checks both.
Reader: website/src/hooks/useFrameSrc.ts:location.replace -- crew page -- navigates the pane iframe, not the top frame, so will-navigate on the main frame does not see it.

Tests

  • test/window-lifecycle.test.js › refuses a top-level navigation off the app origin, in the dashboard and its pop-outs: other port, 127.0.0.1, foreign https, file:, blob: and junk are refused on the dashboard and a pop-out; own-origin routes and ?token= pass; nothing is opened externally.
  • The wiring-order test lists the new view.on:will-navigate registration.

Proof: not provable -- frontend test (prove.py runs Python only)

Local GPT and Opus review lanes on e8ce81bbae: no findings. The backend scoped set was not run locally (this worktree lacks the backend venv); CI runs it.

Mutants, each run against the new test: guard not wired → fails; guard allows everything → fails; guard allows any web origin → fails. Clean head passes. npm run test:electron: 2866 pass, 0 fail.

Manual verification

Not run: this host cannot launch the packaged app. A maintainer check worth doing: open the dashboard, open a remote-crew pane, and confirm normal in-app navigation, the token prompt, and a 403 token retry still work.

Related Issues

Part of #10657

Sibling sweep

Swept: git grep -nE "new (BrowserWindow|WebContentsView)(|will-navigate" -- website/electron
Sibling: website/electron/mochi/panelWindow.js -- not affected -- already has a will-navigate guard on its base URL
Sibling: website/electron/mochi/snipWindow.js -- not affected -- loads one fixed gateway page and hosts no pane iframe
Sibling: website/electron/runtime/window/browser-panels.js -- not affected -- browser panels are meant to browse and use their own deny-all partition

Pattern harvest

Rule candidate: review-prompt
Pattern: a WebContents that embeds third-party iframes needs a will-navigate guard, or a frame can promote itself to the top frame.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 24, 2026 23:36
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The change is a main-process navigation guard in website/electron/ that only logs when it refuses a navigation. It adds or changes no user-visible control, label or state, so the missing screenshots and blind read leave no gap.

[UX-REVIEWED] 6ddb90b

Description read

[DESCRIPTION-READ] 078ee0c04308d548452d866f56106a22778dcb0306430e5ed66242ebbb0f197a

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8 — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. The change reuses classifyNavigation for the same-origin check, adds a single deny-only listener at the place the defect comes from (no will-navigate guard on the dashboard WebContents), and links #10657.

What this change ships

Inventory (4 items) — 4 justified

Intent: stop a page inside a dashboard pane from replacing the desktop app's main window and taking over its permissions. This is a FIX.

  1. A pane can no longer top-navigate the dashboard window to an off-origin page (another port, another host, 127.0.0.1 vs localhost, file:, data:, or an unparseable URL). — justified
  2. The same refusal applies in session pop-out windows and their children. — justified
  3. A navigation to a same-origin blob: URL is refused too, because only http(s) is allowed. — justified
  4. Each refusal writes a log line with the target's origin only, never the full URL. — justified

[FIRST-PRINCIPLES-REVIEWED] 6ddb90b

Description read

[DESCRIPTION-READ] c4d2464b0f9860bff59135df9ce9f5ef664324cdba0d32a7d3f89f28fcc30e0a

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns. Every in-app top navigation under website/src goes through withBase on the window's own origin, and main-process loads never emit will-navigate.

Notes

[DESIGN-REVIEWED] 6ddb90b

Description read

[DESCRIPTION-READ] 1ff1521acde920724990f4204cf2082931b7600da007705435cac1fe705c1c7b

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6ddb90b

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6ddb90b

Verdict parsed from the review's SHA-scoped output markers for commit 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8 false-positive: <reason, 20 to 500 characters>

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Bundle Size Gate is red on this head for a reason outside this PR. The log says assets/ModelEffortDropdown-*.js: 505.0 KB exceeds its 500.0 KB budget by 5.0 KB. That chunk is the web dashboard bundle; this PR touches only website/electron/, which Vite does not bundle. The same failure on pristine main is tracked in #23866, and #23867 is the fix. This PR waits for that fix to merge, then rebases once. No budget change and no rerun here.

🤖 AI-assisted comment 🤖

@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 Oct 25, 2026
A pane iframe can top-navigate the dashboard WebContents to its own
document, which then inherits the dashboard's default-session grants.
Add a deny-only will-navigate guard on the dashboard view and its
pop-out windows: only http(s) URLs on the window's own origin pass;
everything else is refused and nothing is opened externally.
@iamwhatever
iamwhatever force-pushed the fix/10657-dashboard-will-navigate branch from e8ce81b to 6ddb90b Compare October 25, 2026 01:10
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased onto main 3503760, which carries the Bundle Size Gate fix from #23867 (old head e8ce81b, new head 6ddb90b). No code change. Scoped electron tests pass (81 of 81). CI is re-running.

🤖 AI-assisted comment 🤖

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 25, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready on head 6ddb90b. All 107 checks pass, 0 failing; label readiness: passed. GPT, Opus, Design, First Principles and UX lanes all pass with no blocking findings, and there are no unresolved threads. The branch is fresh against main (no overlap). The only remaining gate is a maintainer approval. This PR covers the will-navigate item of #10657; the iframe sandbox item stays open there.

🤖 AI-assisted comment 🤖

@cruisercohen cruisercohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6ddb90b0f6 merged onto current main. Comment only: this is a desktop navigation guard, so it is security scope for us.

What it does. A new will-navigate guard (createNavigationGuard) runs on the dashboard view and on every pop-out. It allows a top-level navigation only when the scheme is http(s) and classifyNavigation says "allow". That check compares full WHATWG origins exactly (target.origin === new URL(appOrigin).origin) and rejects an opaque "null" origin, so a different port, userinfo, or a longer host or port can't pass. A refused URL is dropped (preventDefault plus a log line with the origin only) and is never handed to openExternal. The window-open hand-off is unchanged and still allows only cross-origin http(s) and the two System Settings URLs. The guard is always on.

Nothing legitimate breaks that I could find: same-origin location changes and pop-outs pass, and the OAuth path avoids blank tabs. The one behaviour change is that a plain external <a> without target=_blank now does nothing, where before it replaced the dashboard.

Checks run. window-lifecycle (48) and external-scheme (33) tests: 81 pass, run against a one-line electron stub because node_modules was absent. Removing the will-navigate hookup turns 2 tests red.

Non-blocking, hardening:

  • Swapping the exact origin comparison for a prefix match leaves all 81 green. createNavigationGuard has no unit tests of its own, so a few prefix / userinfo / longer-port cases would pin the exact compare.
  • will-redirect isn't guarded. A same-origin URL the server redirects off-origin would still navigate the window. I found no such redirect today: the browser-view relay refuses an off-origin Location, and the other redirects are path-only. A will-redirect hookup using the same guard would close the class, possibly alongside the sandbox item still open on #10657.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

@cruisercohen thanks for the review (review).

Exact-compare tests. Agreed. A prefix-match mutant passing all 81 tests means the exact origin compare is not pinned. Two ways to close it:

  • (a) In this PR: add 3-4 unit tests for createNavigationGuard that pin the exact compare: a prefix host (http://localhost:5476.evil.example/), userinfo (http://localhost:5476@evil.example/), a longer port (http://localhost:54760/), and an opaque null origin. Each one is shown red against a prefix-match mutant before the push. Tests only, no production change.
  • (b) Test-only follow-up PR with the same tests, so this head stays as reviewed.

I will do (a) if you prefer it.

will-redirect. Agreed that it is the same class. Since you found no off-origin redirect today, I would rather not widen this PR. I will note it on #10657 next to the open sandbox item, so both land as one follow-up.

🤖 AI-assisted comment 🤖

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 6ddb90b0f6a1ec11dd8c13d499f6b88f985811c8.

What it fixes. A page loaded into a dashboard pane could top-navigate the desktop app window and take over the dashboard's session grants. The dashboard view and every pop-out now refuse any page-started top-level navigation that is not http(s) on the window's own origin.

What I checked.

  • createNavigationGuard (external-scheme.js) allows only when the scheme is http(s) and classifyNavigation returns allow; that check is an exact WHATWG origin equality with the opaque "null" origin rejected. Every other path, including a parse error, calls preventDefault(), and a throwing log sink cannot undo the refusal.
  • It is armed inside armWindowOpen, so the main view and each recursive pop-out child get it, with the same windowBackendUrl the window-open handler and capture gate use. That value is always http://localhost:<port>; remote hosts come in through a local tunnel port.
  • Probed the guard directly: a different or longer port, user@host confusion (localhost:5476@other.host), https on the same port, trailing-dot host, [::1], ws:, javascript:, data:, about:blank are all refused. Only true same-origin spellings (uppercase scheme/host, userinfo on the real host, leading-zero port) pass.
  • The token prompt hand-off goes to http://localhost:<port>?…, which is the window's own origin, so it still works.

Tests. test/window-lifecycle.test.js + test/external-scheme.test.js: 81 pass. Mutants, one at a time: guard unwired, scheme check dropped, catch-allows, preventDefault removed and hostname-only compare are each caught by refuses a top-level navigation off the app origin…. One survives: changing the origin compare to startsWith reddens nothing, because no test uses a port-prefix target.

CI. On this head: 91 success, 13 skipped, 0 failure; all review lanes pass. Auto-merge is off.

Follow-ups (non-blocking).

  1. Add http://localhost:54760/ (port-prefix) to the new test so a startsWith regression is caught.
  2. A same-window external <a href> in the dashboard is now a dead click; consider handing refused http(s) targets to the browser in a later PR if any such link exists.
  3. The packaged-app manual check (pane, credential prompt, 403 retry) is still worth doing once.

@iamwhatever
iamwhatever enabled auto-merge (squash) October 25, 2026 06:35
@iamwhatever
iamwhatever merged commit 26379e8 into main Oct 25, 2026
109 checks passed
@iamwhatever
iamwhatever deleted the fix/10657-dashboard-will-navigate branch October 25, 2026 07:10
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 25, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

@cruisercohen the exact-origin tests you suggested are in the test-only follow-up PR #23938.

🤖 AI-assisted comment 🤖

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.

3 participants