Skip to content

Commit 064749d

Browse files
committed
fix(desktop): restrict editor deep links
1 parent beab688 commit 064749d

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

‎apps/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ describe("ElectronShell", () => {
3636
}).pipe(Effect.provide(ElectronShell.layer)),
3737
);
3838

39+
it.effect("opens remote SSH editor URLs", () =>
40+
Effect.gen(function* () {
41+
openExternalMock.mockResolvedValue(undefined);
42+
43+
const electronShell = yield* ElectronShell.ElectronShell;
44+
const result = yield* electronShell.openExternal(
45+
"vscode://vscode-remote/ssh-remote+example.com/home/user/project",
46+
);
47+
48+
assert.equal(result, true);
49+
assert.deepEqual(openExternalMock.mock.calls, [
50+
["vscode://vscode-remote/ssh-remote+example.com/home/user/project"],
51+
]);
52+
}).pipe(Effect.provide(ElectronShell.layer)),
53+
);
54+
3955
it.effect("does not open unsafe external URLs", () =>
4056
Effect.gen(function* () {
4157
const electronShell = yield* ElectronShell.ElectronShell;
@@ -46,6 +62,20 @@ describe("ElectronShell", () => {
4662
}).pipe(Effect.provide(ElectronShell.layer)),
4763
);
4864

65+
it.effect("does not open non-remote editor URLs", () =>
66+
Effect.gen(function* () {
67+
openExternalMock.mockResolvedValue(undefined);
68+
69+
const electronShell = yield* ElectronShell.ElectronShell;
70+
const result = yield* electronShell.openExternal(
71+
"vscode://ms-python.python/some-command?argument=attacker",
72+
);
73+
74+
assert.equal(result, false);
75+
assert.equal(openExternalMock.mock.calls.length, 0);
76+
}).pipe(Effect.provide(ElectronShell.layer)),
77+
);
78+
4979
it.effect("returns false when Electron rejects openExternal", () =>
5080
Effect.gen(function* () {
5181
openExternalMock.mockRejectedValue(new Error("open failed"));

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import * as Option from "effect/Option";
66

77
import * as Electron from "electron";
88

9-
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`)
10-
// must reach the OS handler; every other non-web scheme stays blocked.
11-
const SAFE_EXTERNAL_PROTOCOLS = new Set([
12-
"http:",
13-
"https:",
14-
...REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
9+
const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
10+
const REMOTE_EDITOR_PROTOCOLS = new Set(
11+
REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
1512
const scheme = remoteSchemeForEditor(id);
1613
return scheme === undefined ? [] : [`${scheme}:`];
1714
}),
18-
]);
15+
);
16+
17+
const isRemoteEditorUrl = (url: URL): boolean =>
18+
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&
19+
url.host === "vscode-remote" &&
20+
url.pathname.startsWith("/ssh-remote+") &&
21+
url.pathname.length > "/ssh-remote+".length;
1922

2023
export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
2124
if (typeof rawUrl !== "string") {
@@ -24,7 +27,9 @@ export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
2427

2528
try {
2629
const url = new URL(rawUrl);
27-
return SAFE_EXTERNAL_PROTOCOLS.has(url.protocol) ? Option.some(url.href) : Option.none();
30+
return SAFE_WEB_PROTOCOLS.has(url.protocol) || isRemoteEditorUrl(url)
31+
? Option.some(url.href)
32+
: Option.none();
2833
} catch {
2934
return Option.none();
3035
}

0 commit comments

Comments
 (0)