Skip to content

Commit 0bb4813

Browse files
committed
JavaScript: Add setHTMLUnsafe and parseHTMLUnsafe as XSS sinks
Add support for two new HTML Sanitizer API methods that interpret arguments as HTML without sanitization: - `Element.setHTMLUnsafe(html)`: Added to `interpretsArgumentsAsHtml` in DOM.qll, following the same pattern as `insertAdjacentHTML` and `document.write`. Receiver validation via `isDomNode` is inherited from `DomMethodCallNode`. - `Document.parseHTMLUnsafe(html)`: Added to `HtmlParserSink` in DomBasedXssCustomizations.qll, following the same `GlobalVarRefNode` pattern as `DOMParser.parseFromString`. This is a static method on the `Document` class. Both methods are part of the HTML Sanitizer API and are shipping in browsers (Chrome 124+, Firefox 148+). Unlike their safe counterparts (`setHTML`, `parseHTML`), these methods do not sanitize input and are therefore XSS sinks. References: - https://developer.mozilla.org/en-US/docs/Web/API/Element/setHTMLUnsafe - https://developer.mozilla.org/en-US/docs/Web/API/Document/parseHTMLUnsafe_static
1 parent fb8b569 commit 0bb4813

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/DOM.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class DomMethodCallNode extends DataFlow::MethodCallNode {
5858
name = "createElement" and argPos = 0
5959
or
6060
name = "appendChild" and argPos = 0
61+
or
62+
name = "setHTMLUnsafe" and argPos = 0
6163
)
6264
}
6365

javascript/ql/lib/semmle/javascript/security/dataflow/DomBasedXssCustomizations.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ module DomBasedXss {
196196
ccf.getMethodName() = "createContextualFragment" and
197197
this = ccf.getArgument(0)
198198
)
199+
or
200+
exists(DataFlow::GlobalVarRefNode doc |
201+
doc.getName() = "Document" and
202+
this = doc.getAMethodCall("parseHTMLUnsafe").getArgument(0)
203+
)
199204
}
200205
}
201206

0 commit comments

Comments
 (0)