[MM-20363] prevent using api to navigate within the app's window (#1137)

* prevent using api to navigate within the app's window

* api calls handled differently

* add aliases to ease development

* small refactor of url navigation

* hardcode http/s protocol being allowed

* add protocols specified on electron-builder
This commit is contained in:
Guillermo Vayá
2020-01-17 19:52:05 +01:00
committed by Dean Whillier
parent b98e6a451d
commit 58cf6d5b28
5 changed files with 131 additions and 72 deletions

View File

@@ -8,17 +8,33 @@ import fs from 'fs';
import {app, dialog, ipcMain, shell} from 'electron';
import {protocols} from '../../electron-builder.json';
import * as Validator from './Validator';
const allowedProtocolFile = path.resolve(app.getPath('userData'), 'allowedProtocols.json');
let allowedProtocols = [];
function addScheme(scheme) {
const proto = `${scheme}:`;
if (!allowedProtocols.includes(proto)) {
allowedProtocols.push(proto);
}
}
function init(mainWindow) {
fs.readFile(allowedProtocolFile, 'utf-8', (err, data) => {
if (!err) {
allowedProtocols = JSON.parse(data);
allowedProtocols = Validator.validateAllowedProtocols(allowedProtocols) || [];
}
addScheme('http');
addScheme('https');
protocols.forEach((protocol) => {
if (protocol.schemes && protocol.schemes.length > 0) {
protocol.schemes.forEach(addScheme);
}
});
initDialogEvent(mainWindow);
});
}