fix(desktop): restrict editor deep links (#7697)

Co-authored-by: Simone <[email protected]>
This commit is contained in:
SimoneandSimone authored and GitHub committed 2026-08-20 22:07:49 -07:00
1 parent 45a2c4b2a6
commit 20e5a33968
2 files changed
+64 -6

No files matched your search

@@ -36,6 +36,41 @@ describe("ElectronShell", () => {
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("opens remote SSH editor URLs", () =>
Effect.gen(function* () {
openExternalMock.mockResolvedValue(undefined);
const electronShell = yield* ElectronShell.ElectronShell;
const result = yield* electronShell.openExternal(
"vscode://vscode-remote/ssh-remote+example.com/home/user/project",
);
assert.equal(result, true);
assert.deepEqual(openExternalMock.mock.calls, [
["vscode://vscode-remote/ssh-remote+example.com/home/user/project"],
]);
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("does not open remote editor URLs with userinfo", () =>
Effect.gen(function* () {
openExternalMock.mockResolvedValue(undefined);
const electronShell = yield* ElectronShell.ElectronShell;
const results = yield* Effect.all([
electronShell.openExternal(
"vscode://user@vscode-remote/ssh-remote+example.com/home/user/project",
),
electronShell.openExternal(
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
),
]);
assert.deepEqual(results, [false, false]);
assert.equal(openExternalMock.mock.calls.length, 0);
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("does not open unsafe external URLs", () =>
Effect.gen(function* () {
const electronShell = yield* ElectronShell.ElectronShell;
@@ -46,6 +81,20 @@ describe("ElectronShell", () => {
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("does not open non-remote editor URLs", () =>
Effect.gen(function* () {
openExternalMock.mockResolvedValue(undefined);
const electronShell = yield* ElectronShell.ElectronShell;
const result = yield* electronShell.openExternal(
"vscode://ms-python.python/some-command?argument=attacker",
);
assert.equal(result, false);
assert.equal(openExternalMock.mock.calls.length, 0);
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("returns false when Electron rejects openExternal", () =>
Effect.gen(function* () {
openExternalMock.mockRejectedValue(new Error("open failed"));
+15 -6
View File
@@ -8,14 +8,21 @@ import * as Electron from "electron";
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`)
// must reach the OS handler; every other non-web scheme stays blocked.
const SAFE_EXTERNAL_PROTOCOLS = new Set([
"http:",
"https:",
...REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
const REMOTE_EDITOR_PROTOCOLS = new Set(
REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
const scheme = remoteSchemeForEditor(id);
return scheme === undefined ? [] : [`${scheme}:`];
}),
]);
);
const isRemoteEditorUrl = (url: URL) =>
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&
url.username.length === 0 &&
url.password.length === 0 &&
url.host === "vscode-remote" &&
url.pathname.startsWith("/ssh-remote+") &&
url.pathname.length > "/ssh-remote+".length;
export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
if (typeof rawUrl !== "string") {
@@ -24,7 +31,9 @@ export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
try {
const url = new URL(rawUrl);
return SAFE_EXTERNAL_PROTOCOLS.has(url.protocol) ? Option.some(url.href) : Option.none();
return SAFE_WEB_PROTOCOLS.has(url.protocol) || isRemoteEditorUrl(url)
? Option.some(url.href)
: Option.none();
} catch {
return Option.none();
}