mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
mind whitelist directives for filterable behind-the-scene requests (#3654)
This commit is contained in:
parent
2b92f114bb
commit
fe11ff61c8
3 changed files with 33 additions and 10 deletions
|
|
@ -104,14 +104,12 @@ vAPI.net.registerListeners = function() {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
var reNetworkURI = /^(?:ftps?|https?|wss?)/;
|
|
||||||
|
|
||||||
var normalizeRequestDetails = function(details) {
|
var normalizeRequestDetails = function(details) {
|
||||||
// Chromium 63+ supports the `initiator` property, which contains
|
// Chromium 63+ supports the `initiator` property, which contains
|
||||||
// the URL of the origin from which the network request was made.
|
// the URL of the origin from which the network request was made.
|
||||||
if (
|
if (
|
||||||
details.tabId === vAPI.noTabId &&
|
details.tabId === vAPI.noTabId &&
|
||||||
reNetworkURI.test(details.initiator)
|
typeof details.initiator === 'string'
|
||||||
) {
|
) {
|
||||||
details.tabId = vAPI.anyTabId;
|
details.tabId = vAPI.anyTabId;
|
||||||
details.documentUrl = details.initiator;
|
details.documentUrl = details.initiator;
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,12 @@ vAPI.net.registerListeners = function() {
|
||||||
|
|
||||||
let punycode = self.punycode;
|
let punycode = self.punycode;
|
||||||
let reAsciiHostname = /^https?:\/\/[0-9a-z_.:@-]+[/?#]/;
|
let reAsciiHostname = /^https?:\/\/[0-9a-z_.:@-]+[/?#]/;
|
||||||
let reNetworkURI = /^(?:ftps?|https?|wss?)/;
|
|
||||||
let parsedURL = new URL('about:blank');
|
let parsedURL = new URL('about:blank');
|
||||||
|
|
||||||
let normalizeRequestDetails = function(details) {
|
let normalizeRequestDetails = function(details) {
|
||||||
if (
|
if (
|
||||||
details.tabId === vAPI.noTabId &&
|
details.tabId === vAPI.noTabId &&
|
||||||
reNetworkURI.test(details.documentUrl)
|
typeof details.documentUrl === 'string'
|
||||||
) {
|
) {
|
||||||
details.tabId = vAPI.anyTabId;
|
details.tabId = vAPI.anyTabId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -339,21 +339,26 @@ var onBeforeBehindTheSceneRequest = function(details) {
|
||||||
pageStore = µb.pageStoreFromTabId(details.tabId);
|
pageStore = µb.pageStoreFromTabId(details.tabId);
|
||||||
if ( pageStore === null ) { return; }
|
if ( pageStore === null ) { return; }
|
||||||
|
|
||||||
var context = pageStore.createContextFromPage(),
|
var µburi = µb.URI,
|
||||||
|
context = pageStore.createContextFromPage(),
|
||||||
requestType = details.type,
|
requestType = details.type,
|
||||||
requestURL = details.url;
|
requestURL = details.url;
|
||||||
|
|
||||||
context.requestURL = requestURL;
|
context.requestURL = requestURL;
|
||||||
context.requestHostname = µb.URI.hostnameFromURI(requestURL);
|
context.requestHostname = µburi.hostnameFromURI(requestURL);
|
||||||
context.requestType = requestType;
|
context.requestType = requestType;
|
||||||
|
|
||||||
|
var normalURL;
|
||||||
if ( details.tabId === vAPI.anyTabId && context.pageHostname === '' ) {
|
if ( details.tabId === vAPI.anyTabId && context.pageHostname === '' ) {
|
||||||
context.pageHostname = µb.URI.hostnameFromURI(details.documentUrl);
|
normalURL = µb.normalizePageURL(0, details.documentUrl);
|
||||||
context.pageDomain = µb.URI.domainFromHostname(context.pageHostname);
|
context.pageHostname = µburi.hostnameFromURI(normalURL);
|
||||||
|
context.pageDomain = µburi.domainFromHostname(context.pageHostname);
|
||||||
context.rootHostname = context.pageHostname;
|
context.rootHostname = context.pageHostname;
|
||||||
context.rootDomain = context.pageDomain;
|
context.rootDomain = context.pageDomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageStore.logData = undefined;
|
||||||
|
|
||||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=637577#c15
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=637577#c15
|
||||||
// Do not filter behind-the-scene network request of type `beacon`: there
|
// 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
|
// 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
|
// requests. Hopefully this will not break stuff as it used to be the
|
||||||
// case.
|
// 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);
|
pageStore.journalAddRequest(context.requestHostname, result);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue