Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(desktop): restrict shell.openExternal to http/https schemes (#1124)
Junghwan1ea6e6a078cf
diff --git a/apps/desktop/src/main/external-url.test.ts b/apps/desktop/src/main/external-url.test.tsnew file mode 100644index 0000000000..d49d2dd594--- /dev/null+++ b/apps/desktop/src/main/external-url.test.ts@@ -0,0 +1,16 @@+import { describe, expect, it } from "vitest";+import { isSafeExternalHttpUrl } from "./external-url";++describe("isSafeExternalHttpUrl", () => {+ it("allows http and https URLs", () => {+ expect(isSafeExternalHttpUrl("https://multica.ai")).toBe(true);+ expect(isSafeExternalHttpUrl("http://localhost:3000/auth")).toBe(true);+ });++ it("rejects invalid and non-http schemes", () => {+ expect(isSafeExternalHttpUrl("not a url")).toBe(false);+ expect(isSafeExternalHttpUrl("file:///etc/passwd")).toBe(false);+ expect(isSafeExternalHttpUrl("vscode://file/test")).toBe(false);+ expect(isSafeExternalHttpUrl("mailto:[email protected]")).toBe(false);+ });+});diff --git a/apps/desktop/src/main/external-url.ts b/apps/desktop/src/main/external-url.tsnew file mode 100644index 0000000000..caac84d709--- /dev/null+++ b/apps/desktop/src/main/external-url.ts@@ -0,0 +1,10 @@+export function isSafeExternalHttpUrl(url: string): boolean {+ let parsed: URL;+ try {+ parsed = new URL(url);+ } catch {+ return false;+ }++ return parsed.protocol === "https:" || parsed.protocol === "http:";+}diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.tsindex f7658a9c3f..ba6308ec6e 100644--- a/apps/desktop/src/main/index.ts+++ b/apps/desktop/src/main/index.ts@@ -5,6 +5,7 @@ import { electronApp, optimizer, is } from "@electron-toolkit/utils";import fixPath from "fix-path";import { setupAutoUpdater } from "./updater";import { setupDaemonManager } from "./daemon-manager";+import { isSafeExternalHttpUrl } from "./external-url";// Bundled icon used for dev-mode dock/taskbar branding. In production the// app bundle icon (from electron-builder) wins; this path is only consumed@@ -104,6 +105,10 @@ function createWindow(): void {});mainWindow.webContents.setWindowOpenHandler((details) => {+ if (!isSafeExternalHttpUrl(details.url)) {+ console.warn("[security] blocked window.open external URL");+ return { action: "deny" };+ }shell.openExternal(details.url);return { action: "deny" };});@@ -183,8 +188,16 @@ if (!gotTheLock) {optimizer.watchWindowShortcuts(window);});- // IPC: open URL in default browser (used by renderer for Google login)+ // IPC: open URL in default browser (used by renderer for Google login).+ // Restrict to http/https so the renderer can't dispatch arbitrary OS+ // protocol handlers (file://, smb://, ms-msdt:, vscode://, ...) which+ // become a concern under this app's intentional webSecurity: false ++ // sandbox: false configuration.ipcMain.handle("shell:openExternal", (_event, url: string) => {+ if (!isSafeExternalHttpUrl(url)) {+ console.warn("[security] blocked openExternal: invalid external URL");+ return;+ }return shell.openExternal(url);});