Skip to content

Commit d04dc4c

Browse files
committed
Add -blocked directive to urlskip= option
Potentially breaking change: `urlskip=` option will no longer apply by default to blocked network requests, only network requests which are not blocked can be skipped through a `urlskip=` filter. The new `urlskip=` directive `-blocked` can be used to explicitly allow a `urlskip=` filter to also apply to blocked network requests. Example: given the filter `||example.com^`, the filter: ||example.com/path/to/tracker$urlskip=?url Will not prevent strict-blocking when navigating to: https://example.com/path/to/tracker?url=https://example.org/ However, the filter: ||example.com/path/to/tracker$urlskip=-blocked ?url Will cause the strict-blocking to be ignored and allow navigation to proceed to the URL extracted as a result of applying the `urlskip=` filter: https://example.org/ Related discussion: uBlockOrigin/uBlock-issues#3206 (comment)
1 parent 50785ea commit d04dc4c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/js/benchmarks.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export async function benchmarkStaticNetFiltering(options = {}) {
191191
removeparamCount += 1;
192192
}
193193
}
194-
if ( sfne.urlSkip(fctxt) ) {
194+
if ( sfne.urlSkip(fctxt, false) ) {
195195
urlskipCount += 1;
196196
}
197197
if ( fctxt.isDocument() ) {
@@ -210,7 +210,7 @@ export async function benchmarkStaticNetFiltering(options = {}) {
210210
if ( sfne.redirectRequest(redirectEngine, fctxt) ) {
211211
redirectCount += 1;
212212
}
213-
if ( fctxt.isRootDocument() && sfne.urlSkip(fctxt) ) {
213+
if ( fctxt.isRootDocument() && sfne.urlSkip(fctxt, true) ) {
214214
urlskipCount += 1;
215215
}
216216
}

src/js/pagestore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ const PageStore = class {
943943
staticNetFilteringEngine.filterQuery(fctxt, directives);
944944
}
945945
if ( this.urlSkippableResources.has(fctxt.itype) ) {
946-
staticNetFilteringEngine.urlSkip(fctxt, directives);
946+
staticNetFilteringEngine.urlSkip(fctxt, false, directives);
947947
}
948948
if ( directives.length === 0 ) { return; }
949949
if ( logger.enabled !== true ) { return; }

src/js/static-net-filtering.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -5405,6 +5405,9 @@ StaticNetFilteringEngine.prototype.transformRequest = function(fctxt, out = [])
54055405
*
54065406
* `-uricomponent`: decode the current string as a URI encoded string.
54075407
*
5408+
* `-blocked`: allow the redirection of blocked requests. By default, blocked
5409+
* requests can't by urlskip'ed.
5410+
*
54085411
* At any given step, the currently extracted string may not necessarily be
54095412
* a valid URL, and more transformation steps may be needed to obtain a valid
54105413
* URL once all the steps are applied.
@@ -5423,7 +5426,11 @@ StaticNetFilteringEngine.prototype.transformRequest = function(fctxt, out = [])
54235426
*
54245427
* */
54255428

5426-
StaticNetFilteringEngine.prototype.urlSkip = function(fctxt, out = []) {
5429+
StaticNetFilteringEngine.prototype.urlSkip = function(
5430+
fctxt,
5431+
blocked,
5432+
out = []
5433+
) {
54275434
if ( fctxt.redirectURL !== undefined ) { return; }
54285435
const directives = this.matchAndFetchModifiers(fctxt, 'urlskip');
54295436
if ( directives === undefined ) { return; }
@@ -5435,7 +5442,7 @@ StaticNetFilteringEngine.prototype.urlSkip = function(fctxt, out = []) {
54355442
const urlin = fctxt.url;
54365443
const value = directive.value;
54375444
const steps = value.includes(' ') && value.split(/ +/) || [ value ];
5438-
const urlout = urlSkip(directive, urlin, steps);
5445+
const urlout = urlSkip(directive, urlin, blocked, steps);
54395446
if ( urlout === undefined ) { continue; }
54405447
if ( urlout === urlin ) { continue; }
54415448
fctxt.redirectURL = urlout;
@@ -5446,8 +5453,9 @@ StaticNetFilteringEngine.prototype.urlSkip = function(fctxt, out = []) {
54465453
return out;
54475454
};
54485455

5449-
function urlSkip(directive, url, steps) {
5456+
function urlSkip(directive, url, blocked, steps) {
54505457
try {
5458+
let redirectBlocked = false;
54515459
let urlout = url;
54525460
for ( const step of steps ) {
54535461
const urlin = urlout;
@@ -5481,6 +5489,11 @@ function urlSkip(directive, url, steps) {
54815489
urlout = self.decodeURIComponent(urlin);
54825490
continue;
54835491
}
5492+
// Enable skip of blocked requests
5493+
if ( step === '-blocked' ) {
5494+
redirectBlocked = true;
5495+
continue;
5496+
}
54845497
}
54855498
// Regex extraction from first capture group
54865499
if ( c0 === 0x2F ) { // /
@@ -5507,6 +5520,7 @@ function urlSkip(directive, url, steps) {
55075520
}
55085521
const urlfinal = new URL(urlout);
55095522
if ( urlfinal.protocol !== 'https:' ) { return; }
5523+
if ( blocked && redirectBlocked !== true ) { return; }
55105524
return urlout;
55115525
} catch(x) {
55125526
}

0 commit comments

Comments
 (0)