fix(desktop): solve #5972 — OSC 8 hyperlinks with non-http(s) schemes are a silent no-op
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:
activatedid no scheme validation of its own (it relied entirely on xterm's http(s) gate), so flipping the flag alone would have started forwardingjavascript:/file:URIs from untrusted terminal output.external.openUrlin the main process refuses anything outsidehttp:/https:/mailto:, and the v1/v2 terminal click handlers can route a URL into an in-app browser pane, which cannot rendercursor://at all.
The fix
New shared scheme policy — apps/desktop/src/shared/external-uri-scheme.ts — classifying user-activated URIs into three tiers:
| tier | schemes | behaviour |
|---|---|---|
allow | http:, https:, mailto: | dispatched directly |
confirm | any other registered scheme (cursor:, vscode:, slack:, …) | native confirm showing the real URI, then shell.openExternal |
block | javascript:, vbscript:, data:, blob:, file:, about:, view-source:, chrome:, devtools:, unparseable | refused |
Wired up as:
terminal-link-manager.tssetsallowNonHttpProtocols: trueso xterm hands us the link, andactivatenow applies the policy —blockschemes are dropped with a scheme-only log line instead of being forwarded.- New
external.openExternalUritRPC procedure applies the same policy in the main process and prompts for theconfirmtier beforeshell.openExternal. The strictexternal.openUrlallowlist is deliberately unchanged, so programmatic opens (OAuth, port forwarding, embedded-browserwindow.open) keep the tighter gate. - Both terminal click sites (v1
Terminal/helpers.ts, v2TerminalPane.tsx) callopenExternalUriand only route through the in-app browser pane whenisWebUri(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 onmain(oscLinkIsDropped("cursor:///Users/me/project")→true, i.e. xterm never builds a link); passes with the fix, andactivateroutes toonUrlClick.still drops OSC 8 links that use script-executing schemes— also fails onmain(all 5 ofjavascript:/data:/vbscript:/file:/malformed reachedonUrlClick), 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
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: trueso@xterm/xtermsurfaces custom-scheme OSC 8 links; renderer now validates schemes before activation. - New shared policy (
external-uri-scheme): allowhttp:,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.openUrlremains strict for programmatic opens. - Terminal clicks (v1 and v2) now call
openExternalUri; in-app browser is used only forisWebUri(url). Added unit tests for policy and terminal link handling.
- Set