Skip to content

Commit

Permalink
Fix plain exceptions not overriding block filters using header= option
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Aug 17, 2024
1 parent 8de454c commit 1cb660b
Showing 1 changed file with 64 additions and 73 deletions.
137 changes: 64 additions & 73 deletions src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,15 @@
Home: https://github.com/gorhill/uBlock
*/

/* globals vAPI */

'use strict';
import * as sfp from './static-filtering-parser.js';

/******************************************************************************/
import { domainFromHostname, hostnameFromNetworkURL } from './uri-utils.js';
import { dropTask, queueTask } from './tasks.js';

import { queueTask, dropTask } from './tasks.js';
import BidiTrieContainer from './biditrie.js';
import HNTrieContainer from './hntrie.js';
import { CompiledListReader } from './static-filtering-io.js';
import * as sfp from './static-filtering-parser.js';

import {
domainFromHostname,
hostnameFromNetworkURL,
} from './uri-utils.js';

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
//
// This import would be best done dynamically, but since dynamic imports are
// not supported by older browsers, for now a static import is necessary.
import { FilteringContext } from './filtering-context.js';
import HNTrieContainer from './hntrie.js';

/******************************************************************************/

Expand Down Expand Up @@ -3423,63 +3410,63 @@ class FilterCompiler {

processOptionWithValue(parser, id) {
switch ( id ) {
case sfp.NODE_TYPE_NET_OPTION_NAME_CSP:
if ( this.processCspOption(parser.getNetOptionValue(id)) === false ) { return false; }
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_DENYALLOW:
this.denyallowOpt = this.processHostnameList(
parser.getNetFilterDenyallowOptionIterator(),
);
if ( this.denyallowOpt === '' ) { return false; }
this.optionUnitBits |= DENYALLOW_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_FROM:
this.fromDomainOpt = this.processHostnameList(
parser.getNetFilterFromOptionIterator(),
this.fromDomainOptList
);
if ( this.fromDomainOpt === '' ) { return false; }
this.optionUnitBits |= FROM_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_HEADER: {
this.headerOpt = parser.getNetOptionValue(id) || '';
this.optionUnitBits |= HEADER_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_CSP:
if ( this.processCspOption(parser.getNetOptionValue(id)) === false ) { return false; }
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_DENYALLOW:
this.denyallowOpt = this.processHostnameList(
parser.getNetFilterDenyallowOptionIterator(),
);
if ( this.denyallowOpt === '' ) { return false; }
this.optionUnitBits |= DENYALLOW_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_FROM:
this.fromDomainOpt = this.processHostnameList(
parser.getNetFilterFromOptionIterator(),
this.fromDomainOptList
);
if ( this.fromDomainOpt === '' ) { return false; }
this.optionUnitBits |= FROM_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_HEADER: {
this.headerOpt = parser.getNetOptionValue(id) || '';
this.optionUnitBits |= HEADER_BIT;
break;
}
case sfp.NODE_TYPE_NET_OPTION_NAME_METHOD:
this.processMethodOption(parser.getNetOptionValue(id));
this.optionUnitBits |= METHOD_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_PERMISSIONS:
case sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECTRULE:
case sfp.NODE_TYPE_NET_OPTION_NAME_REMOVEPARAM:
case sfp.NODE_TYPE_NET_OPTION_NAME_REPLACE:
case sfp.NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM:
if ( this.processModifierOption(id, parser.getNetOptionValue(id)) === false ) {
return false;
}
case sfp.NODE_TYPE_NET_OPTION_NAME_METHOD:
this.processMethodOption(parser.getNetOptionValue(id));
this.optionUnitBits |= METHOD_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_PERMISSIONS:
case sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECTRULE:
case sfp.NODE_TYPE_NET_OPTION_NAME_REMOVEPARAM:
case sfp.NODE_TYPE_NET_OPTION_NAME_REPLACE:
case sfp.NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM:
if ( this.processModifierOption(id, parser.getNetOptionValue(id)) === false ) {
return false;
}
this.optionUnitBits |= MODIFY_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECT: {
const actualId = this.action === ALLOW_REALM
? sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECTRULE
: id;
if ( this.processModifierOption(actualId, parser.getNetOptionValue(id)) === false ) {
return false;
}
this.optionUnitBits |= MODIFY_BIT;
break;
this.optionUnitBits |= MODIFY_BIT;
break;
case sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECT: {
const actualId = this.action === ALLOW_REALM
? sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECTRULE
: id;
if ( this.processModifierOption(actualId, parser.getNetOptionValue(id)) === false ) {
return false;
}
case sfp.NODE_TYPE_NET_OPTION_NAME_TO:
this.toDomainOpt = this.processHostnameList(
parser.getNetFilterToOptionIterator(),
this.toDomainOptList
);
if ( this.toDomainOpt === '' ) { return false; }
this.optionUnitBits |= TO_BIT;
break;
default:
break;
this.optionUnitBits |= MODIFY_BIT;
break;
}
case sfp.NODE_TYPE_NET_OPTION_NAME_TO:
this.toDomainOpt = this.processHostnameList(
parser.getNetFilterToOptionIterator(),
this.toDomainOptList
);
if ( this.toDomainOpt === '' ) { return false; }
this.optionUnitBits |= TO_BIT;
break;
default:
break;
}
return true;
}
Expand Down Expand Up @@ -3798,7 +3785,7 @@ class FilterCompiler {
isJustOrigin() {
if ( this.optionUnitBits !== FROM_BIT ) { return false; }
if ( this.isRegex ) { return false; }
if ( /[\/~]/.test(this.fromDomainOpt) ) { return false; }
if ( /[/~]/.test(this.fromDomainOpt) ) { return false; }
if ( this.pattern === '*' ) { return true; }
if ( this.anchor !== 0b010 ) { return false; }
if ( /^(?:http[s*]?:(?:\/\/)?)$/.test(this.pattern) ) { return true; }
Expand Down Expand Up @@ -5156,6 +5143,10 @@ StaticNetFilteringEngine.prototype.matchHeaders = function(fctxt, headers) {
if ( r !== 0 && $isBlockImportant !== true ) {
if ( this.realmMatchString(HEADERS_REALM | ALLOW_REALM, typeBits, partyBits) ) {
r = 2;
} else if ( this.realmMatchString(ALLOW_REALM, typeBits, partyBits) ) {
r = 2;
}
if ( r === 2 ) {
if ( this.realmMatchString(HEADERS_REALM | BLOCKIMPORTANT_REALM, typeBits, partyBits) ) {
r = 1;
}
Expand Down

0 comments on commit 1cb660b

Please sign in to comment.