diff --git a/core/state-manager.js b/core/state-manager.js index 770745b4..745ae8e1 100644 --- a/core/state-manager.js +++ b/core/state-manager.js @@ -96,15 +96,19 @@ stateManager.addDomainToAllowlist = function (domain) { stateManager.removeDomainFromAllowlist = function (domain) { return new Promise((resolve) => { - let allowlistedDomains, wildcard; + let allowlistedDomains; allowlistedDomains = requestAnalyzer.allowlistedDomains; - wildcard = helpers.getWildcard(domain); if (allowlistedDomains[domain]) { delete allowlistedDomains[domain]; } else { - delete allowlistedDomains[wildcard]; + for (const key in allowlistedDomains) { + if (key.startsWith('*.') && domain.endsWith(key.substring(2))) { + delete allowlistedDomains[key]; + break; + } + } } storageManager.type.set({allowlistedDomains}, resolve); diff --git a/modules/internal/helpers.js b/modules/internal/helpers.js index 6ea2809b..b5938537 100644 --- a/modules/internal/helpers.js +++ b/modules/internal/helpers.js @@ -185,23 +185,29 @@ helpers.getTopLevelDomain = function (initiatorDomain) { }; helpers.checkAllowlisted = function (domain, list) { - let domainWithoutPrefix, wildcard, tld; + if (!domain) return false; - if (domain === null) { - return false; + const subdomains = helpers.getAllSubdomains(domain); + + for (const subdomain of subdomains) { + if (list[subdomain]) return true; + } + return false; +}; + + +helpers.getAllSubdomains = function (domain) { + const parts = domain.split('.').reverse(); + const subdomains = []; + let currentSubdomain = ''; + + for (const part of parts) { + currentSubdomain = part + (currentSubdomain ? `.${currentSubdomain}` : ''); + subdomains.push(`*.${currentSubdomain}`); + subdomains.push(currentSubdomain); } - if (domain.startsWith(Address.WWW_PREFIX)) { - domainWithoutPrefix = domain.slice(Address.WWW_PREFIX.length); - } - wildcard = helpers.getWildcard(domain); - tld = helpers.getTopLevelDomain(domain); - - return Boolean(list[domain] || - list[domainWithoutPrefix] || - list[wildcard] || - list[domainWithoutPrefix] || - list[tld]); + return subdomains; }; helpers.extractFilenameFromPath = function (path) { diff --git a/pages/updates/updates.html b/pages/updates/updates.html index b27d6ae5..6593c740 100644 --- a/pages/updates/updates.html +++ b/pages/updates/updates.html @@ -25,9 +25,9 @@

New in LocalCDN:

-

+

Improved