Skip to content

Commit 4ce2984

Browse files
authored
fix: limit usage of shell.openExternal to web URLs
1 parent a47fdfd commit 4ce2984

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/windows.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export function mainIsReady() {
2424
mainIsReadyResolver();
2525
}
2626

27+
function isWebProtocol(url: string) {
28+
const { protocol } = new URL(url);
29+
return ['http', 'https'].includes(protocol);
30+
}
31+
2732
/**
2833
* Gets default options for the main window
2934
*
@@ -92,13 +97,17 @@ export function createMainWindow(): Electron.BrowserWindow {
9297
});
9398

9499
browserWindow.webContents.setWindowOpenHandler((details) => {
95-
shell.openExternal(details.url);
100+
if (isWebProtocol(details.url)) {
101+
shell.openExternal(details.url);
102+
}
96103
return { action: 'deny' };
97104
});
98105

99106
browserWindow.webContents.on('will-navigate', (event, url) => {
100107
event.preventDefault();
101-
shell.openExternal(url);
108+
if (isWebProtocol(details.url)) {
109+
shell.openExternal(url);
110+
}
102111
});
103112

104113
ipcMainManager.on(IpcEvents.RELOAD_WINDOW, () => {

0 commit comments

Comments
 (0)