Merge pull request #286 from Jigsaw-Code/bemasc-filter

Filter URL type before calling openExternal
This commit is contained in:
Benjamin M. Schwartz 2018-10-24 17:27:25 -04:00 • committed by GitHub
commit 4e9a5201b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,7 +88,16 @@ function createMainWindow() {
const LOADING_WINDOW_DELAY_MS = 3000;
const handleNavigation = (event: Event, url: string) => {
shell.openExternal(url);
try {
const parsed: URL = new URL(url);
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
shell.openExternal(url);
} else {
console.warn(`Refusing to open URL with protocol "${parsed.protocol}"`);
}
} catch (e) {
console.warn('Could not parse URL: ' + url);
}
event.preventDefault();
};
win.webContents.on('will-navigate', (event: Event, url: string) => {