Skip to content

Commit

Permalink
Remove trusted-source requireement when using badfilter
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Feb 28, 2024
1 parent ad03f7d commit 3c299b8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/js/static-filtering-parser.js
Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 3c299b8

Please sign in to comment.