1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

mind whitelist directives for filterable behind-the-scene requests (#3654)

This commit is contained in:
Raymond Hill 2018-04-02 09:10:38 -04:00
parent 2b92f114bb
commit fe11ff61c8
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 33 additions and 10 deletions

View File

@ -104,14 +104,12 @@ vAPI.net.registerListeners = function() {
return '';
};
var reNetworkURI = /^(?:ftps?|https?|wss?)/;
var normalizeRequestDetails = function(details) {
// Chromium 63+ supports the `initiator` property, which contains
// the URL of the origin from which the network request was made.
if (
details.tabId === vAPI.noTabId &&
reNetworkURI.test(details.initiator)
typeof details.initiator === 'string'
) {
details.tabId = vAPI.anyTabId;
details.documentUrl = details.initiator;

View File

@ -100,13 +100,12 @@ vAPI.net.registerListeners = function() {
let punycode = self.punycode;
let reAsciiHostname = /^https?:\/\/[0-9a-z_.:@-]+[/?#]/;
let reNetworkURI = /^(?:ftps?|https?|wss?)/;
let parsedURL = new URL('about:blank');
let normalizeRequestDetails = function(details) {
if (
details.tabId === vAPI.noTabId &&
reNetworkURI.test(details.documentUrl)
typeof details.documentUrl === 'string'
) {
details.tabId = vAPI.anyTabId;
}

View File

@ -339,21 +339,26 @@ var onBeforeBehindTheSceneRequest = function(details) {
pageStore = µb.pageStoreFromTabId(details.tabId);
if ( pageStore === null ) { return; }
var context = pageStore.createContextFromPage(),
var µburi = µb.URI,
context = pageStore.createContextFromPage(),
requestType = details.type,
requestURL = details.url;
context.requestURL = requestURL;
context.requestHostname = µb.URI.hostnameFromURI(requestURL);
context.requestHostname = µburi.hostnameFromURI(requestURL);
context.requestType = requestType;
var normalURL;
if ( details.tabId === vAPI.anyTabId && context.pageHostname === '' ) {
context.pageHostname = µb.URI.hostnameFromURI(details.documentUrl);
context.pageDomain = µb.URI.domainFromHostname(context.pageHostname);
normalURL = µb.normalizePageURL(0, details.documentUrl);
context.pageHostname = µburi.hostnameFromURI(normalURL);
context.pageDomain = µburi.domainFromHostname(context.pageHostname);
context.rootHostname = context.pageHostname;
context.rootDomain = context.pageDomain;
}
pageStore.logData = undefined;
// https://bugs.chromium.org/p/chromium/issues/detail?id=637577#c15
// Do not filter behind-the-scene network request of type `beacon`: there
// is no point. In any case, this will become a non-issue once
@ -373,7 +378,28 @@ var onBeforeBehindTheSceneRequest = function(details) {
// requests. Hopefully this will not break stuff as it used to be the
// case.
var result = pageStore.filterRequest(context);
var result = 0;
if (
µburi.isNetworkURI(details.documentUrl) ||
µb.userSettings.advancedUserEnabled ||
requestType === 'csp_report'
) {
result = pageStore.filterRequest(context);
// The "any-tab" scope is not whitelist-able, and in such case we must
// use the origin URL as the scope. Most such requests aren't going to
// be blocked, so we further test for whitelisting and modify the
// result only when the request is being blocked.
if (
result === 1 &&
normalURL !== undefined &&
µb.getNetFilteringSwitch(normalURL) === false
) {
result = 2;
pageStore.logData = { engine: 'u', result: 2, raw: 'whitelisted' };
}
}
pageStore.journalAddRequest(context.requestHostname, result);