Skip to content

Commit 46fe6b2

Browse files
authored
Merge pull request j4wg#61 from bhaumikmaan/feat/security-fix-1
Fix URL check
2 parents 6f8695f + 37a9a6d commit 46fe6b2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

electron/main.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,19 @@ async function createWindow(): Promise<void> {
293293
}
294294
state.mainWindow.webContents.setWindowOpenHandler(({ url }) => {
295295
console.log("Attempting to open URL:", url)
296-
if (url.includes("google.com") || url.includes("supabase.co")) {
297-
shell.openExternal(url)
298-
return { action: "deny" }
296+
try {
297+
const parsedURL = new URL(url);
298+
const hostname = parsedURL.hostname;
299+
const allowedHosts = ["google.com", "supabase.co"];
300+
if (allowedHosts.includes(hostname) || hostname.endsWith(".google.com") || hostname.endsWith(".supabase.co")) {
301+
shell.openExternal(url);
302+
return { action: "deny" }; // Do not open this URL in a new Electron window
303+
}
304+
} catch (error) {
305+
console.error("Invalid URL %d in setWindowOpenHandler: %d" , url , error);
306+
return { action: "deny" }; // Deny access as URL string is malformed or invalid
299307
}
300-
return { action: "allow" }
308+
return { action: "allow" };
301309
})
302310

303311
// Enhanced screen capture resistance

0 commit comments

Comments
 (0)