Wildcard support extended in all lists (#1622)
This commit is contained in:
parent
f785cd77b9
commit
2efaf25bb6
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
<h2>New in LocalCDN:</h2>
|
||||
</div>
|
||||
<div class="release-notes-area">
|
||||
<p></p>
|
||||
<p>Improved</p>
|
||||
<ul>
|
||||
<li></li>
|
||||
<li>Wildcard support extended in all lists (<a href="https://codeberg.org/nobody/LocalCDN/issues/1622">#1622</a>)</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="generator-section">
|
||||
|
|
Loading…
Reference in New Issue