Initial commit to add wildcard for Google Fonts and HTML filters (#613)

This commit is contained in:
nobody 2021-08-07 08:39:10 +02:00
parent 67b67bbd68
commit 651d19bfa6
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
6 changed files with 13 additions and 11 deletions

View File

@ -46,13 +46,16 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
if (Regex.GOOGLE_FONTS.test(requestDetails.url)) {
let initiatorDomain = helpers.extractDomainFromUrl(tab.url, true);
let initiatorDomain, isListed;
initiatorDomain = helpers.extractDomainFromUrl(tab.url, true);
isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts);
// Check if the website is allowed to load Google Fonts
if (interceptor.blockGoogleFonts === true && !interceptor.allowedDomainsGoogleFonts[initiatorDomain]) {
if (interceptor.blockGoogleFonts === true && isListed === false) {
return {
'cancel': true
};
} else if (interceptor.blockGoogleFonts === false || interceptor.allowedDomainsGoogleFonts[initiatorDomain]) {
} else if (interceptor.blockGoogleFonts === false || isListed === true) {
return {
'cancel': false
};

View File

@ -54,11 +54,11 @@ messenger._handleMessageReceived = function (message, sender, sendResponse) {
return MessageResponse.SYNCHRONOUS;
case 'domain:fetch-is-allowlisted':
sendResponse({'value': Boolean(helpers.checkAllowlisted(value))});
sendResponse({'value': Boolean(helpers.checkAllowlisted(value, requestAnalyzer.allowlistedDomains))});
return MessageResponse.SYNCHRONOUS;
case 'domain:fetch-is-manipulateDOM':
sendResponse({'value': Boolean(requestAnalyzer.domainsManipulateDOM[value])});
sendResponse({'value': Boolean(helpers.checkAllowlisted(value, requestAnalyzer.domainsManipulateDOM))});
return MessageResponse.SYNCHRONOUS;
case 'allowlist:add-domain':

View File

@ -39,7 +39,7 @@ requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
initiatorDomain = Address.EXAMPLE;
}
isAllowlisted = helpers.checkAllowlisted(initiatorDomain);
isAllowlisted = helpers.checkAllowlisted(initiatorDomain, requestAnalyzer.allowlistedDomains);
if (isAllowlisted) {
return false;
}

View File

@ -63,7 +63,7 @@ requestSanitizer._stripMetadata = function (requestDetails) {
sensitiveHeaders = [Header.COOKIE, Header.ORIGIN, Header.REFERER];
initiatorDomain = helpers.extractDomainFromUrl(requestDetails.initiator, true);
allowlistedDomains = helpers.checkAllowlisted(initiatorDomain);
allowlistedDomains = helpers.checkAllowlisted(initiatorDomain, requestAnalyzer.allowlistedDomains);
if (allowlistedDomains) {
return {

View File

@ -230,7 +230,7 @@ stateManager._domainIsListed = function (domain, listname) {
allowlistRecord = requestAnalyzer.domainsManipulateDOM[domain];
isAllowlisted = Boolean(allowlistRecord);
} else {
allowlistRecord = helpers.checkAllowlisted(domain);
allowlistRecord = helpers.checkAllowlisted(domain, requestAnalyzer.allowlistedDomains);
isAllowlisted = Boolean(allowlistRecord);
}
return isAllowlisted;

View File

@ -133,8 +133,8 @@ helpers.getWildcard = function (initiatorDomain) {
};
helpers.checkAllowlisted = function (domain) {
let domainWithoutPrefix, wildcard, list;
helpers.checkAllowlisted = function (domain, list) {
let domainWithoutPrefix, wildcard;
if (domain === null) {
return false;
@ -144,7 +144,6 @@ helpers.checkAllowlisted = function (domain) {
domainWithoutPrefix = domain.slice(Address.WWW_PREFIX.length);
}
wildcard = helpers.getWildcard(domain);
list = requestAnalyzer.allowlistedDomains;
return Boolean(list[domain] || list[domainWithoutPrefix] || list[wildcard] || list[domainWithoutPrefix]);
};