Skip to content

Commit

Permalink
Re-classify redirect= option as a modifier option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Nov 3, 2020
1 parent 1b44bf2 commit 157cef6
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 389 deletions.
4 changes: 2 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ const µBlock = (( ) => { // jshint ignore:line

// Read-only
systemSettings: {
compiledMagic: 30, // Increase when compiled format changes
selfieMagic: 30, // Increase when selfie format changes
compiledMagic: 31, // Increase when compiled format changes
selfieMagic: 31, // Increase when selfie format changes
},

// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501
Expand Down
8 changes: 7 additions & 1 deletion src/js/logger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,13 @@ const processLoggerEntries = function(response) {
if ( autoDeleteVoidedRows ) { continue; }
parsed.voided = true;
}
if ( parsed.type === 'main_frame' && parsed.aliased === false ) {
if (
parsed.type === 'main_frame' &&
parsed.aliased === false && (
parsed.filter === undefined ||
parsed.filter.source !== 'redirect'
)
) {
const separator = createLogSeparator(parsed, unboxed.url);
loggerEntries.unshift(separator);
if ( rowFilterer.filterOne(separator) ) {
Expand Down
43 changes: 28 additions & 15 deletions src/js/pagestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,22 +647,9 @@ const PageStore = class {
// Redirect non-blocked request?
if ( (fctxt.itype & fctxt.INLINE_ANY) === 0 ) {
if ( result === 1 ) {
if ( µb.hiddenSettings.ignoreRedirectFilters !== true ) {
const redirectURL = µb.redirectEngine.toURL(fctxt);
if ( redirectURL !== undefined ) {
fctxt.redirectURL = redirectURL;
this.internalRedirectionCount += 1;
fctxt.pushFilter({
source: 'redirect',
raw: µb.redirectEngine.resourceNameRegister
});
}
}
this.redirectBlockedRequest(fctxt);
} else if ( snfe.hasQuery(fctxt) ) {
const directives = snfe.filterQuery(fctxt);
if ( directives !== undefined && loggerEnabled ) {
fctxt.pushFilters(directives.map(a => a.logData()));
}
this.redirectNonBlockedRequest(fctxt);
}
}

Expand All @@ -675,6 +662,32 @@ const PageStore = class {
return result;
}

redirectBlockedRequest(fctxt) {
if ( µb.hiddenSettings.ignoreRedirectFilters === true ) { return; }
const directive = µb.staticNetFilteringEngine.redirectRequest(fctxt);
if ( directive === undefined ) { return; }
this.internalRedirectionCount += 1;
if ( µb.logger.enabled !== true ) { return; }
fctxt.pushFilter(directive.logData());
if ( fctxt.redirectURL === undefined ) { return; }
fctxt.pushFilter({
source: 'redirect',
raw: µb.redirectEngine.resourceNameRegister
});
}

redirectNonBlockedRequest(fctxt) {
const directives = µb.staticNetFilteringEngine.filterQuery(fctxt);
if ( directives === undefined ) { return; }
if ( µb.logger.enabled !== true ) { return; }
fctxt.pushFilters(directives.map(a => a.logData()));
if ( fctxt.redirectURL === undefined ) { return; }
fctxt.pushFilter({
source: 'redirect',
raw: fctxt.redirectURL
});
}

filterCSPReport(fctxt) {
if (
µb.sessionSwitches.evaluateZ(
Expand Down
Loading

0 comments on commit 157cef6

Please sign in to comment.