diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 34828bc7a..491cf0368 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1299,6 +1299,7 @@ export class AstFilterParser { let modifierType = 0; let requestTypeCount = 0; let unredirectableTypeCount = 0; + let badfilter = false; for ( let i = 0, n = this.nodeTypeRegisterPtr; i < n; i++ ) { const type = this.nodeTypeRegister[i]; const targetNode = this.nodeTypeLookupTable[type]; @@ -1322,6 +1323,8 @@ export class AstFilterParser { realBad = hasValue; break; case NODE_TYPE_NET_OPTION_NAME_BADFILTER: + badfilter = true; + /* falls through */ case NODE_TYPE_NET_OPTION_NAME_NOOP: realBad = isNegated || hasValue; break; @@ -1462,6 +1465,9 @@ export class AstFilterParser { this.addFlags(AST_FLAG_HAS_ERROR); } } + const requiresTrustedSource = ( ) => + this.options.trustedSource !== true && + isException === false && badfilter === false; switch ( modifierType ) { case NODE_TYPE_NET_OPTION_NAME_CNAME: realBad = abstractTypeCount || behaviorTypeCount || requestTypeCount; @@ -1489,7 +1495,7 @@ export class AstFilterParser { case NODE_TYPE_NET_OPTION_NAME_REPLACE: { realBad = abstractTypeCount || behaviorTypeCount || unredirectableTypeCount; if ( realBad ) { break; } - if ( isException !== true && this.options.trustedSource !== true ) { + if ( requiresTrustedSource() ) { this.astError = AST_ERROR_UNTRUSTED_SOURCE; realBad = true; break; @@ -1504,7 +1510,7 @@ export class AstFilterParser { case NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM: { realBad = abstractTypeCount || behaviorTypeCount || unredirectableTypeCount; if ( realBad ) { break; } - if ( isException !== true && this.options.trustedSource !== true ) { + if ( requiresTrustedSource() ) { this.astError = AST_ERROR_UNTRUSTED_SOURCE; realBad = true; break;