From 7b8c096270a8fc7c9061bbbd36a2c4d196692542 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 5 Jan 2023 08:39:31 -0500 Subject: [PATCH] Better validate `:upward()` argument Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/2442#issuecomment-1371484554 --- src/js/static-filtering-parser.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index d29fc9088..6f2da5def 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1587,15 +1587,8 @@ Parser.prototype.SelectorCompiler = class { break; case 'not': { if ( this.astHasType(args, 'Combinator', 0) === false ) { break; } - const selectors = this.astSelectorsFromSelectorList(args); - if ( Array.isArray(selectors) === false || selectors.length === 0 ) { + if ( this.astIsValidSelectorList(args) !== true ) { data.type = 'Error'; - break; - } - for ( const selector of selectors ) { - if ( this.astIsValidSelector(selector) ) { continue; } - data.type = 'Error'; - break; } break; } @@ -1865,6 +1858,17 @@ Parser.prototype.SelectorCompiler = class { return true; } + astIsValidSelectorList(args) { + const selectors = this.astSelectorsFromSelectorList(args); + if ( Array.isArray(selectors) === false || selectors.length === 0 ) { + return false; + } + for ( const selector of selectors ) { + if ( this.astIsValidSelector(selector) !== true ) { return false; } + } + return true; + } + translateAdguardCSSInjectionFilter(suffix) { const matches = /^(.*)\s*\{([^}]+)\}\s*$/.exec(suffix); if ( matches === null ) { return ''; } @@ -2071,6 +2075,7 @@ Parser.prototype.SelectorCompiler = class { const i = this.compileInteger(s, 1, 256); if ( i !== undefined ) { return i; } const parts = this.astFromRaw(s, 'selectorList' ); + if ( this.astIsValidSelectorList(parts) !== true ) { return; } if ( this.astHasType(parts, 'ProceduralSelector') ) { return; } if ( this.astHasType(parts, 'ActionSelector') ) { return; } if ( this.astHasType(parts, 'Error') ) { return; }