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.
This commit is contained in:
Raymond Hill 2024-10-06 14:27:55 -04:00
parent 447476ab9b
commit c746633693
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 4 additions and 2 deletions

View File

@ -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;
}