Skip to content

Conversation

@hamishwillee
Copy link
Collaborator

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.

@hamishwillee hamishwillee requested a review from a team as a code owner October 26, 2025 23:53
@hamishwillee hamishwillee requested review from sideshowbarker and removed request for a team October 26, 2025 23:53
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Oct 26, 2025
@github-actions
Copy link
Contributor

@sideshowbarker sideshowbarker merged commit 7cd06b2 into mdn:main Oct 26, 2025
7 checks passed
@hamishwillee hamishwillee deleted the sethtml_improvements branch October 27, 2025 00:03
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.
Copy link
Member

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.

Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants