mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-26 08:51:22 -06:00
Electron-217
* Implemented basic logic on whitelisting urls * Removed a space in PULL_REQUEST_TEMPLATE.md
This commit is contained in:
parent
bc231a8022
commit
84cb11e629
@ -5,7 +5,7 @@ A few sentences describing the overall goals of the pull request's commits. Desc
|
||||
## Approach
|
||||
How does this change address the problem?
|
||||
- #### Problem with the code:
|
||||
- #### Fix :
|
||||
- #### Fix:
|
||||
|
||||
|
||||
## Learning
|
||||
|
@ -3,6 +3,7 @@
|
||||
"minimizeOnClose" : true,
|
||||
"launchOnStartup" : true,
|
||||
"alwaysOnTop" : false,
|
||||
"whiteListURL": "*",
|
||||
"notificationSettings": {
|
||||
"position": "upper-right",
|
||||
"display": ""
|
||||
|
101
js/utils/isWhiteList.js
Normal file
101
js/utils/isWhiteList.js
Normal file
@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
|
||||
const { getConfigField } = require('./../config.js');
|
||||
const parse = require('parse-domain');
|
||||
|
||||
/**
|
||||
* Loops through the list of whitelist urls
|
||||
* @param url {String} - url the electron is navigated to
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function isWhiteList(url) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
getConfigField('whitelist').then((whiteList) => {
|
||||
if (checkWhiteList(url, whiteList)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that compares url against a list of whitelist
|
||||
* returns true if hostName or domain present in the whitelist
|
||||
* @param url {String} - url the electron is navigated to
|
||||
* @param whiteList {String} - coma separated whitelists
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function checkWhiteList(url, whiteList) {
|
||||
let whiteLists = whiteList.split(',');
|
||||
const parsedURL = parse(url);
|
||||
|
||||
if (whiteLists.indexOf('*') !== -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return whiteLists.some((whiteListHost) => {
|
||||
let parsedWhiteList = parse(whiteListHost);
|
||||
|
||||
if (!parsedWhiteList) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return matchDomains(parsedURL, parsedWhiteList);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the respective hostName
|
||||
* @param parsedURL {Object} - parsed url
|
||||
* @param parsedWhiteList {Object} - parsed whitelist
|
||||
*
|
||||
* example:
|
||||
* matchDomain({ subdomain: www, domain: example, tld: com }, { subdomain: app, domain: example, tld: com })
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
function matchDomains(parsedURL, parsedWhiteList) {
|
||||
|
||||
if (_.isEqual(parsedURL, parsedWhiteList)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const hostNameFromURL = parsedURL.domain + parsedURL.tld;
|
||||
const hostNameFromWhiteList = parsedWhiteList.domain + parsedWhiteList.tld;
|
||||
|
||||
if (!parsedWhiteList.subdomain) {
|
||||
return hostNameFromURL === hostNameFromWhiteList
|
||||
}
|
||||
|
||||
return matchSubDomains(parsedURL.subdomain, parsedWhiteList.subdomain);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the last occurrence in the sub-domain
|
||||
* @param subDomainURL {String} - sub-domain from url
|
||||
* @param subDomainWhiteList {String} - sub-domain from whitelist
|
||||
*
|
||||
* example: matchSubDomains('www', 'app')
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function matchSubDomains(subDomainURL, subDomainWhiteList) {
|
||||
|
||||
if (subDomainURL === subDomainWhiteList) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const subDomainURLArray = subDomainURL.split('.');
|
||||
const lastCharSubDomainURL = subDomainURLArray[subDomainURLArray.length - 1];
|
||||
|
||||
const subDomainWhiteListArray = subDomainWhiteList.split('.');
|
||||
const lastCharWhiteList = subDomainWhiteListArray[subDomainWhiteListArray.length - 1];
|
||||
|
||||
return lastCharSubDomainURL === lastCharWhiteList;
|
||||
}
|
||||
|
||||
module.exports = isWhiteList;
|
@ -104,9 +104,10 @@
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"filesize": "^3.5.10",
|
||||
"keymirror": "0.1.1",
|
||||
"lodash.difference": "^4.5.0",
|
||||
"lodash.omit": "^4.5.0",
|
||||
"lodash.pick": "^4.4.0",
|
||||
"lodash.difference": "^4.5.0",
|
||||
"parse-domain": "^2.0.0",
|
||||
"winreg": "^1.2.3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
Loading…
Reference in New Issue
Block a user