-
Notifications
You must be signed in to change notification settings - Fork 23k
Slight rework of setHTML to clarify removed elements #41695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| The **`setHTML()`** method of the {{domxref("Element")}} interface provides an XSS-safe method to parse and sanitize a string of HTML and insert it into the DOM as a subtree of the element. | ||
|
|
||
| The method removes any elements and attributes that are considered XSS-unsafe, even if allowed by a passed sanitizer. | ||
| Notably, the following elements are always removed: {{HTMLElement("script")}}, {{HTMLElement("frame")}}, {{HTMLElement("iframe")}}, {{HTMLElement("object")}}, {{SVGElement("use")}}, event handler attributes, and data attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it remove data attributes always? Reading the spec https://wicg.github.io/sanitizer-api/#sanitizerconfig-remove-unsafe, I only see the baseline config (which btw includes 6 distinct elements; <embed> is missed here) plus event handler attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your care. Correct - the data attributes are removed by the default sanitizer but are not always removed. I tidied this up in #41715
This follows #41677 with some tweaks.
Specifically the issue made the valid point that it is useful to highlight/overview what elements are considered XSS unsafe. But then it applied that information alongside the sanitizer options. That's not the right place, because the method ignores any unsafe values in the sanitizer configuration.