Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

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

Simone20e5a3396858
diff --git a/apps/desktop/src/electron/ElectronShell.test.ts b/apps/desktop/src/electron/ElectronShell.test.ts
index f5c85769c..9ae6f502b 100644
--- a/apps/desktop/src/electron/ElectronShell.test.ts
+++ b/apps/desktop/src/electron/ElectronShell.test.ts
@@ -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"));
diff --git a/apps/desktop/src/electron/ElectronShell.ts b/apps/desktop/src/electron/ElectronShell.ts
index 126be71b6..2ed13bfeb 100644
--- a/apps/desktop/src/electron/ElectronShell.ts
+++ b/apps/desktop/src/electron/ElectronShell.ts
@@ -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();
}