Skip to content

fix(desktop): restrict local frontend access to electron - #835

Merged
nixuuu merged 1 commit into
devfrom
fix/secure-desktop-local-connections
Nov 15, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/secure-desktop-local-connections

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 15, 2026

Copy link
Copy Markdown
Member

Change

Opening the desktop's loopback frontend in a browser or local HTTP client previously exposed the application. Require a random 256-bit capability for each launch, shared between Electron main and its controller through private stdin and checked before SvelteKit for documents, assets, API requests and SSE. Electron adds it only to owned windows and trusted top-level requests, strips it from external destinations, and revokes it before shutdown or immediately after controller exit.

Keep the exact GET OAuth callback available to the system browser, with existing state, binding and expiry checks. Preserve the frontend origin and profile storage. Hide desktop “Open in new tab” actions and prevent internal links from opening in the system browser. Disable HTTPS over Tailscale for desktop gateways to close the alternate browser entry; paired Network access clients and server gateways remain supported.

Update the architecture, desktop, remote frontend, Tailscale and UI/API docs, including the protection's limits against processes that can read memory or attach a debugger.

Verification

Passed locally on Linux:

  • Full nightly desktop build: CANOPY_CHANNEL=nightly bun run --cwd apps/desktop build; rebuilt the Electron shell after the final shutdown change.
  • Bundled runtime and shutdown integration tests: local and remote modes, enrollment, restart durability, gateway recovery, controller EOF and cleanup.
  • Desktop session/context-menu security tests, OAuth return integration and Tailscale HTTPS integration, including desktop refusal and retained server behavior.
  • Real Electron quit smoke using production preload and Svelte layout in both windows; production syntax-highlighting worker and dynamically imported language modules.
  • Actual production Electron main under a temporary virtual display, using an isolated profile and the OS keychain: first-run setup through the UI, real PostgreSQL/gateway/worker startup, restart on the same profile, both-window reload, unchanged settings save, API 200, SSE, retained localStorage and unauthenticated HTTP 403.
  • Desktop TypeScript check, lint/format of edited files, test-shard allocation check and git diff --check.
  • Manual browser review in light/dark themes at desktop and phone widths, with short, typical and long names: desktop hides the action, web retains it.

The full repository gate runs in CI. Native macOS/Windows startup and a complete OAuth sign-in through the system browser against a real provider remain unverified locally.

Copy audit (docs/copy.md §8): pass. Desktop “Open in new tab” → hidden, because internal pages stay inside Canopy. Unauthorized content → “Open Canopy to use this app.” Desktop HTTPS availability → “Open this computer in Canopy. Browser access is unavailable.” Shutdown failures state that services stopped and ask the user to restart Canopy. New copy is English, uses plain language, and gives an action without exposing implementation terms; no audit exceptions.

Authenticate all desktop frontend requests with a launch-only capability
shared over private controller stdin. Scope credential injection to owned
Electron windows and revoke it on shutdown or controller exit. Preserve
the narrow OAuth callback and existing profile storage.

Remove desktop browser-opening actions and disable desktop HTTPS over
Tailscale while keeping paired Network access clients supported.
@nixuuu
nixuuu enabled auto-merge (squash) November 15, 2026 14:09
@nixuuu
nixuuu merged commit 9b930fd into dev Nov 15, 2026
11 checks passed
@nixuuu
nixuuu deleted the fix/secure-desktop-local-connections branch November 15, 2026 14:24
nixuuu added a commit that referenced this pull request Nov 16, 2026
## Change

Closing the last Windows window could throw `Object has been destroyed`
after shutdown was latched, leaving services running and both Open and
Quit in the tray inactive. Check BrowserWindow and WebContents liveness
before session revocation, header authorization and IPC authorization;
capture navigation targets before teardown.

Local desktop sidebar preferences now use a stable scope instead of the
gateway's random port, preserving grouping, project order and the
Working section across restarts. Remote desktop and server scopes stay
isolated. Existing port-derived records cannot be reliably migrated, so
users may need to select their preferences once after upgrading.

Fixes: #835
Fixes: #583

## Verification

- 39 focused tests passed: desktop session security, IPC delivery, app
routes, quit guard and device-view persistence. Temp-directory checks
passed.
- Desktop typecheck, lint and formatting of edited files, and diff
checks passed locally.
- Real Electron on Linux reproduced the old destroyed-window getter
failure. The patched lifecycle completed session revocation and quit
when closing the last window, invoking Quit with live windows, and
invoking Quit after closing the main window while settings remained
open.
- Updated desktop and UI/API documentation. No UI layout or copy
changes; copy audit is not applicable.

The full repository gate runs in CI. Native Windows verification remains
outstanding; the Linux lifecycle smoke does not verify Windows
integration or the full packaged runtime shutdown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant