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) {
|
stateManager.removeDomainFromAllowlist = function (domain) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let allowlistedDomains, wildcard;
|
let allowlistedDomains;
|
||||||
|
|
||||||
allowlistedDomains = requestAnalyzer.allowlistedDomains;
|
allowlistedDomains = requestAnalyzer.allowlistedDomains;
|
||||||
wildcard = helpers.getWildcard(domain);
|
|
||||||
|
|
||||||
if (allowlistedDomains[domain]) {
|
if (allowlistedDomains[domain]) {
|
||||||
delete allowlistedDomains[domain];
|
delete allowlistedDomains[domain];
|
||||||
} else {
|
} 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);
|
storageManager.type.set({allowlistedDomains}, resolve);
|
||||||
|
|
|
@ -185,23 +185,29 @@ helpers.getTopLevelDomain = function (initiatorDomain) {
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.checkAllowlisted = function (domain, list) {
|
helpers.checkAllowlisted = function (domain, list) {
|
||||||
let domainWithoutPrefix, wildcard, tld;
|
if (!domain) return false;
|
||||||
|
|
||||||
if (domain === null) {
|
const subdomains = helpers.getAllSubdomains(domain);
|
||||||
return false;
|
|
||||||
|
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)) {
|
return subdomains;
|
||||||
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]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.extractFilenameFromPath = function (path) {
|
helpers.extractFilenameFromPath = function (path) {
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
<h2>New in LocalCDN:</h2>
|
<h2>New in LocalCDN:</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="release-notes-area">
|
<div class="release-notes-area">
|
||||||
<p></p>
|
<p>Improved</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li></li>
|
<li>Wildcard support extended in all lists (<a href="https://codeberg.org/nobody/LocalCDN/issues/1622">#1622</a>)</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="generator-section">
|
<div id="generator-section">
|
||||||
|
|
Loading…
Reference in New Issue