Skip to content

Commit

Permalink
Validate result type of XPath expressions
Browse files Browse the repository at this point in the history
Related issue:
uBlockOrigin/uBlock-issues#3403

To ensure XPath expressions not meant to return a nodeset are
discarded at compile time.
  • Loading branch information
gorhill committed Oct 6, 2024
1 parent 447476a commit c746633
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c746633

Please sign in to comment.