From 97232baee3c214e13a32cf5b2bbaa0a4c9f0e9a9 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 8 Nov 2021 11:17:47 -0500 Subject: [PATCH] Forbid multiple and unexpected CSS style declarations Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1806#issuecomment-963278382 --- src/js/static-filtering-parser.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 98301f3da..16b9c3704 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1437,12 +1437,17 @@ Parser.prototype.SelectorCompiler = class { // https://github.com/uBlockOrigin/uBlock-issues/issues/1751 // Do not rely on matches() or querySelector() to test whether a // selector is declarative or not. + // https://github.com/uBlockOrigin/uBlock-issues/issues/1806#issuecomment-963278382 + // Forbid multiple and unexpected CSS style declarations. sheetSelectable(s) { if ( this.reSimpleSelector.test(s) ) { return true; } if ( this.stylesheet === null ) { return true; } try { this.stylesheet.insertRule(`${s}{color:red}`); - if ( this.stylesheet.cssRules.length === 0 ) { return false; } + if ( this.stylesheet.cssRules.length !== 1 ) { return false; } + const style = this.stylesheet.cssRules[0].style; + if ( style.length !== 1 ) { return false; } + if ( style.getPropertyValue('color') !== 'red' ) { return false; } this.stylesheet.deleteRule(0); } catch (ex) { return false;