Skip to content

Commit

Permalink
Restrict URLs which can be opened in an external browser
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Jun 4, 2020
1 parent 27fc58f commit 962470d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/features/utils/functions.js
Expand Up @@ -52,5 +52,5 @@ export function normalizeServerURL(url: string) {
* @returns {void}
*/
export function openExternalLink(link: string) {
window.jitsiNodeAPI.shellOpenExternal(link);
window.jitsiNodeAPI.openExternalLink(link);
}
28 changes: 26 additions & 2 deletions app/preload/preload.js
@@ -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
};

0 comments on commit 962470d

Please sign in to comment.