Skip to content

Commit 157cef6

Browse files
committed
Re-classify redirect= option as a modifier option
This commit moves the parsing, compiling and enforcement of the `redirect=` and `redirect-rule=` network filter options into the static network filtering engine as modifier options -- just like `csp=` and `queryprune=`. This solves the two following issues: - #3590 - uBlockOrigin/uBlock-issues#1008 (comment) Additionally, `redirect=` option is not longer afflicted by static network filtering syntax quirks, `redirect=` filters can be used with any other static filtering modifier options, can be excepted using `@@` and can be badfilter-ed. Since more than one `redirect=` directives could be found to apply to a single network request, the concept of redirect priority is introduced. By default, `redirect=` directives have an implicit priority of 0. Filter authors can declare an explicit priority by appending `:[integer]` to the token of the `redirect=` option, for example: ||example.com/*.js$1p,script,redirect=noopjs:100 The priority dictates which redirect token out of many will be ultimately used. Cases of multiple `redirect=` directives applying to a single blocked network request are expected to be rather unlikely. Explicit redirect priority should be used if and only if there is a case of redirect ambiguity to solve.
1 parent 1b44bf2 commit 157cef6

File tree

7 files changed

+140
-389
lines changed

7 files changed

+140
-389
lines changed

src/js/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ const µBlock = (( ) => { // jshint ignore:line
139139

140140
// Read-only
141141
systemSettings: {
142-
compiledMagic: 30, // Increase when compiled format changes
143-
selfieMagic: 30, // Increase when selfie format changes
142+
compiledMagic: 31, // Increase when compiled format changes
143+
selfieMagic: 31, // Increase when selfie format changes
144144
},
145145

146146
// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501

src/js/logger-ui.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,13 @@ const processLoggerEntries = function(response) {
302302
if ( autoDeleteVoidedRows ) { continue; }
303303
parsed.voided = true;
304304
}
305-
if ( parsed.type === 'main_frame' && parsed.aliased === false ) {
305+
if (
306+
parsed.type === 'main_frame' &&
307+
parsed.aliased === false && (
308+
parsed.filter === undefined ||
309+
parsed.filter.source !== 'redirect'
310+
)
311+
) {
306312
const separator = createLogSeparator(parsed, unboxed.url);
307313
loggerEntries.unshift(separator);
308314
if ( rowFilterer.filterOne(separator) ) {

src/js/pagestore.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -647,22 +647,9 @@ const PageStore = class {
647647
// Redirect non-blocked request?
648648
if ( (fctxt.itype & fctxt.INLINE_ANY) === 0 ) {
649649
if ( result === 1 ) {
650-
if ( µb.hiddenSettings.ignoreRedirectFilters !== true ) {
651-
const redirectURL = µb.redirectEngine.toURL(fctxt);
652-
if ( redirectURL !== undefined ) {
653-
fctxt.redirectURL = redirectURL;
654-
this.internalRedirectionCount += 1;
655-
fctxt.pushFilter({
656-
source: 'redirect',
657-
raw: µb.redirectEngine.resourceNameRegister
658-
});
659-
}
660-
}
650+
this.redirectBlockedRequest(fctxt);
661651
} else if ( snfe.hasQuery(fctxt) ) {
662-
const directives = snfe.filterQuery(fctxt);
663-
if ( directives !== undefined && loggerEnabled ) {
664-
fctxt.pushFilters(directives.map(a => a.logData()));
665-
}
652+
this.redirectNonBlockedRequest(fctxt);
666653
}
667654
}
668655

@@ -675,6 +662,32 @@ const PageStore = class {
675662
return result;
676663
}
677664

665+
redirectBlockedRequest(fctxt) {
666+
if ( µb.hiddenSettings.ignoreRedirectFilters === true ) { return; }
667+
const directive = µb.staticNetFilteringEngine.redirectRequest(fctxt);
668+
if ( directive === undefined ) { return; }
669+
this.internalRedirectionCount += 1;
670+
if ( µb.logger.enabled !== true ) { return; }
671+
fctxt.pushFilter(directive.logData());
672+
if ( fctxt.redirectURL === undefined ) { return; }
673+
fctxt.pushFilter({
674+
source: 'redirect',
675+
raw: µb.redirectEngine.resourceNameRegister
676+
});
677+
}
678+
679+
redirectNonBlockedRequest(fctxt) {
680+
const directives = µb.staticNetFilteringEngine.filterQuery(fctxt);
681+
if ( directives === undefined ) { return; }
682+
if ( µb.logger.enabled !== true ) { return; }
683+
fctxt.pushFilters(directives.map(a => a.logData()));
684+
if ( fctxt.redirectURL === undefined ) { return; }
685+
fctxt.pushFilter({
686+
source: 'redirect',
687+
raw: fctxt.redirectURL
688+
});
689+
}
690+
678691
filterCSPReport(fctxt) {
679692
if (
680693
µb.sessionSwitches.evaluateZ(

0 commit comments

Comments
 (0)