1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2025-06-05 21:49:31 +02:00

Block bad resources (#703)

This commit is contained in:
nobody
2021-09-29 06:50:53 +02:00
parent f4daff688f
commit e0f8719391
4 changed files with 31 additions and 0 deletions

View File

@@ -41,6 +41,14 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
};
}
if (!interceptor.blockMissing && interceptor._isBadResource(requestDetails.url)) {
console.warn(`[ LocalCDN ] Evil resource blocked: ${requestDetails.url}`);
log.append(tab.url, requestDetails.url, '-', true);
return {
'cancel': true
};
}
targetDetails = requestAnalyzer.getLocalTarget(requestDetails, tab.url);
targetPath = targetDetails.path;
@@ -141,6 +149,10 @@ interceptor._handleStorageChanged = function (changes) {
}
};
interceptor._isBadResource = function (requestUrl) {
requestUrl = requestUrl.replace(/(^\w+:|^)\/\//, '');
return Object.keys(BadResources).filter((path) => requestUrl.startsWith(path)).length !== 0;
};
/**
* Event Handlers