Restrict desktop external URL schemes (#845)

This commit is contained in:
João Sousa Andrade
2026-05-10 21:02:47 +08:00
committed by GitHub
parent b9940e285c
commit 3f5acfff31
2 changed files with 72 additions and 1 deletions
+19 -1
View File
@@ -1,7 +1,25 @@
import { shell, ipcMain } from "electron";
const ALLOWED_EXTERNAL_URL_PROTOCOLS = new Set(["http:", "https:"]);
export function isAllowedExternalUrl(value: unknown): value is string {
if (typeof value !== "string") {
return false;
}
try {
const url = new URL(value);
return ALLOWED_EXTERNAL_URL_PROTOCOLS.has(url.protocol);
} catch {
return false;
}
}
export function registerOpenerHandlers(): void {
ipcMain.handle("paseo:opener:openUrl", async (_event, url: string) => {
ipcMain.handle("paseo:opener:openUrl", async (_event, url: unknown) => {
if (!isAllowedExternalUrl(url)) {
throw new Error("Unsupported external URL");
}
await shell.openExternal(url);
});
}