Restrict URLs which can be opened in an external browser

This commit is contained in:
Saúl Ibarra Corretgé 2020-06-04 09:54:18 +02:00
parent 27fc58f927
commit 962470d97e
2 changed files with 27 additions and 3 deletions

View File

@ -52,5 +52,5 @@ export function normalizeServerURL(url: string) {
* @returns {void}
*/
export function openExternalLink(link: string) {
window.jitsiNodeAPI.shellOpenExternal(link);
window.jitsiNodeAPI.openExternalLink(link);
}

View File

@ -1,13 +1,37 @@
const createElectronStorage = require('redux-persist-electron-storage');
const { shell } = require('electron');
const os = require('os');
const url = require('url');
const jitsiMeetElectronUtils = require('jitsi-meet-electron-utils');
const protocolRegex = /^https?:/i;
/**
* Opens the given link in an external browser.
*
* @param {string} link - The link (URL) that should be opened in the external browser.
* @returns {void}
*/
function openExternalLink(link) {
let u;
try {
u = url.parse(link);
} catch (e) {
return;
}
if (protocolRegex.test(u.protocol)) {
shell.openExternal(link);
}
}
window.jitsiNodeAPI = {
createElectronStorage,
osUserInfo: os.userInfo,
shellOpenExternal: shell.openExternal,
openExternalLink,
jitsiMeetElectronUtils
};