From c7466336934d7d22378a10c7c9bb5d77a8f7d11b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 6 Oct 2024 14:27:55 -0400 Subject: [PATCH] Validate result type of XPath expressions Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3403 To ensure XPath expressions not meant to return a nodeset are discarded at compile time. --- src/js/static-filtering-parser.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 1249b07b8..8f95b88d6 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -4116,9 +4116,11 @@ class ExtSelectorCompiler { compileXpathExpression(s) { const r = this.unquoteString(s); if ( r.i !== s.length ) { return; } - if ( globalThis.document instanceof Object === false ) { return r.s; } + const doc = globalThis.document; + if ( doc instanceof Object === false ) { return r.s; } try { - globalThis.document.createExpression(r.s, null); + const expr = doc.createExpression(r.s, null); + expr.evaluate(doc, XPathResult.ANY_UNORDERED_NODE_TYPE); } catch (e) { return; }