fix(desktop): solve #5972 — OSC 8 hyperlinks with non-http(s) schemes are a silent no-op

Draft
GI
4mo ago
+294-21

Root cause

xterm.js gates OSC 8 hyperlinks on scheme before they become links. In OscLinkProvider.provideLinks, if the terminal's linkHandler does not set allowNonHttpProtocols, any URI whose protocol isn't http:/https: is dropped and no ILink is built at all.

TerminalLinkManager installed its OSC link handler with allowNonHttpProtocols: false (apps/desktop/src/renderer/lib/terminal/terminal-link-manager.ts). So a cursor:///path hyperlink still got the OSC 8 underline decoration from the cell attributes, but there was no link object behind it — the click never reached activate, hence no dialog, no error, no feedback.

Two further layers would have blocked it even after xterm surfaced the link:

  • activate did no scheme validation of its own (it relied entirely on xterm's http(s) gate), so flipping the flag alone would have started forwarding javascript:/file: URIs from untrusted terminal output.
  • external.openUrl in the main process refuses anything outside http:/https:/mailto:, and the v1/v2 terminal click handlers can route a URL into an in-app browser pane, which cannot render cursor:// at all.

The fix

New shared scheme policy — apps/desktop/src/shared/external-uri-scheme.ts — classifying user-activated URIs into three tiers:

tierschemesbehaviour
allowhttp:, https:, mailto:dispatched directly
confirmany other registered scheme (cursor:, vscode:, slack:, …)native confirm showing the real URI, then shell.openExternal
blockjavascript:, vbscript:, data:, blob:, file:, about:, view-source:, chrome:, devtools:, unparseablerefused

Wired up as:

  • terminal-link-manager.ts sets allowNonHttpProtocols: true so xterm hands us the link, and activate now applies the policy — block schemes are dropped with a scheme-only log line instead of being forwarded.
  • New external.openExternalUri tRPC procedure applies the same policy in the main process and prompts for the confirm tier before shell.openExternal. The strict external.openUrl allowlist is deliberately unchanged, so programmatic opens (OAuth, port forwarding, embedded-browser window.open) keep the tighter gate.
  • Both terminal click sites (v1 Terminal/helpers.ts, v2 TerminalPane.tsx) call openExternalUri and only route through the in-app browser pane when isWebUri(url).

Why confirm rather than open silently: terminal output is attacker-influenced (build logs, cat of a checked-in file, a hostile statusline) and the OSC 8 label is arbitrary — "open in cursor" can point anywhere. Superset's hover hint shows only an action label, never the target URI, so the dialog is the first place the user sees where the link actually goes. This also matches the behaviour the issue asks for ("lets macOS show its native confirmation"). Note that activation additionally requires Cmd/Ctrl+click, per the existing terminal link policy.

externalUrlLogLabel in main/lib/safe-url now delegates to the shared externalUriSchemeLabel so there's one implementation; behaviour is unchanged.

Tests

Reproduction, in terminal-link-manager.test.ts — a helper mirroring xterm's OscLinkProvider gate, so the test exercises the actual reason the click died rather than just asserting a flag:

  • keeps OSC 8 links with a custom scheme clickable — fails on main (oscLinkIsDropped("cursor:///Users/me/project") → true, i.e. xterm never builds a link); passes with the fix, and activate routes to onUrlClick.
  • still drops OSC 8 links that use script-executing schemes — also fails on main (all 5 of javascript:/data:/vbscript:/file:/malformed reached onUrlClick), demonstrating that the old code had no guard of its own; passes with the fix.

New apps/desktop/src/shared/external-uri-scheme.test.ts covers the three tiers, case-insensitivity, and non-URI input.

Verified: bun test in apps/desktop — 2298 pass, 0 fail. bun run typecheck clean, bun run lint exits 0.

Not covered: the openExternalUri procedure body itself (Electron dialog/shell are not mocked in this suite), and no end-to-end click was performed in a running app — the classification logic it delegates to is unit-tested, but the dialog and shell.openExternal handoff are unverified at runtime, which is why this is a draft.

Closes #5972


Open in Stage

Summary by cubic

Fixes #5972 by making OSC 8 hyperlinks with non-http(s) schemes clickable again. Adds a shared URI scheme policy: web/mail open directly, custom app schemes prompt, and unsafe schemes are blocked.

  • Bug Fixes
    • Set allowNonHttpProtocols: true so @xterm/xterm surfaces custom-scheme OSC 8 links; renderer now validates schemes before activation.
    • New shared policy (external-uri-scheme): allow http:, https:, mailto:; confirm custom app schemes (e.g., cursor:); block script/local-file schemes.
    • Introduced external.openExternalUri (tRPC) that applies the policy and shows a native confirm for non-web schemes; external.openUrl remains strict for programmatic opens.
    • Terminal clicks (v1 and v2) now call openExternalUri; in-app browser is used only for isWebUri(url). Added unit tests for policy and terminal link handling.