From d1a1667210ec4972a8676c5ded378cb69c14e185 Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Wed, 25 Mar 2026 17:24:52 +0100 Subject: [PATCH 1/2] Upstream the Sanitizer API See https://github.com/WICG/sanitizer-api/issues/291 --- source | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 9 deletions(-) diff --git a/source b/source index 1d533952b9f..db1863cb925 100644 --- a/source +++ b/source @@ -11413,7 +11413,8 @@ typedef (HTMLScriptElement or SVGScriptElement) LegacyOverrideBuiltIns] partial interface Document { - static Document parseHTMLUnsafe((TrustedHTML or DOMString) html); + static Document parseHTMLUnsafe((TrustedHTML or DOMString) html, optional SetHTMLUnsafeOptions options = {}); + static Document parseHTML((TrustedHTML or DOMString) html, optional SetHTMLOptions options = {}); // resource metadata management [PutForwards=href, LegacyUnforgeable] readonly attribute Location? location; @@ -124514,7 +124515,8 @@ document.body.appendChild(frame)

DOM parsing and serialization APIs

partial interface Element {
-  [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html);
+  [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional SetHTMLUnsafeOptions options = {});
+  [CEReactions] undefined setHTML(DOMString html, optional SetHTMLOptions options = {});
   DOMString getHTML(optional GetHTMLOptions options = {});
 
   [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
@@ -124523,12 +124525,21 @@ document.body.appendChild(frame)
}; partial interface ShadowRoot { - [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html); + [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional SetHTMLUnsafeOptions options = {}); + [CEReactions] undefined setHTML(DOMString html, optional SetHTMLOptions options = {}); DOMString getHTML(optional GetHTMLOptions options = {}); [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML; }; +enum SanitizerPresets { "default" }; +dictionary SetHTMLOptions { + (Sanitizer or SanitizerConfig or SanitizerPresets) sanitizer = "default"; +}; +dictionary SetHTMLUnsafeOptions { + (Sanitizer or SanitizerConfig or SanitizerPresets) sanitizer = {}; +}; + dictionary GetHTMLOptions { boolean serializableShadowRoots = false; sequence<ShadowRoot> shadowRoots = []; @@ -124706,10 +124717,10 @@ enum DOMParserSupportedType {
element.setHTMLUnsafe(html)
+ data-x="dom-Element-setHTMLUnsafe">setHTMLUnsafe(html, options)
-

Parses html using the HTML parser, and replaces the children of element +

Parses html using the HTML parser with options options, and replaces the children of element with the result. element provides context for the HTML parser.

@@ -124717,16 +124728,16 @@ enum DOMParserSupportedType { data-x="dom-ShadowRoot-setHTMLUnsafe">setHTMLUnsafe(html)
-

Parses html using the HTML parser, and replaces the children of +

Parses html using the HTML parser with options options, and replaces the children of shadowRoot with the result. shadowRoot's host provides context for the HTML parser.

doc = Document.parseHTMLUnsafe(html)
+ data-x="dom-parseHTMLUnsafe">parseHTMLUnsafe(html, options)
-

Parses html using the HTML parser, and returns the resulting +

Parses html using the HTML parser with options options, and returns the resulting Document.

Note that script elements are not evaluated during parsing, and the resulting @@ -124802,7 +124813,7 @@ enum DOMParserSupportedType {

The static parseHTMLUnsafe(html) method steps are:

+ data-x="dom-parseHTMLUnsafe">parseHTMLUnsafe(html, options) method steps are:

  1. Let compliantHTML be the result of invoking the DOMParserSupportedType {

  2. Parse HTML from a string given document and compliantHTML.

  3. +
  4. Let sanitizer be the result of calling get a sanitizer instance from options + with options and false.

  5. + +
  6. Call sanitize on document with sanitizer and false.

  7. +
  8. Return document.

+ + +

Safe HTML parsing methods

+ +
+ +
+ +
+ +
partial interface Element {
+};
+ +
+ +

HTML serialization methods

@@ -125381,6 +125413,80 @@ interface XMLSerializer { +

HTML sanitization

+ +

The Sanitizer interface

+ +
[Exposed=Window]
+interface Sanitizer {
+  constructor(optional (SanitizerConfig or SanitizerPresets) configuration = "default");
+
+  // Query configuration:
+  SanitizerConfig get();
+
+  // Modify a Sanitizer's lists and fields:
+  boolean allowElement(SanitizerElementWithAttributes element);
+  boolean removeElement(SanitizerElement element);
+  boolean replaceElementWithChildren(SanitizerElement element);
+  boolean allowAttribute(SanitizerAttribute attribute);
+  boolean removeAttribute(SanitizerAttribute attribute);
+  boolean setComments(boolean allow);
+  boolean setDataAttributes(boolean allow);
+
+  // Remove markup that executes script.
+  boolean removeUnsafe();
+};
+ + TODO + +

Sanitizer configuration

+ +
dictionary SanitizerElementNamespace {
+  required DOMString name;
+  DOMString? _namespace = "http://www.w3.org/1999/xhtml";
+};
+
+// Used by "elements"
+dictionary SanitizerElementNamespaceWithAttributes : SanitizerElementNamespace {
+  sequence attributes;
+  sequence removeAttributes;
+};
+
+typedef (DOMString or SanitizerElementNamespace) SanitizerElement;
+typedef (DOMString or SanitizerElementNamespaceWithAttributes) SanitizerElementWithAttributes;
+
+dictionary SanitizerAttributeNamespace {
+  required DOMString name;
+  DOMString? _namespace = null;
+};
+typedef (DOMString or SanitizerAttributeNamespace) SanitizerAttribute;
+
+dictionary SanitizerConfig {
+  sequence elements;
+  sequence removeElements;
+  sequence replaceWithChildrenElements;
+
+  sequence attributes;
+  sequence removeAttributes;
+
+  boolean comments;
+  boolean dataAttributes;
+};
+ + TODO + +
Configuration invariants
+ + TODO + +

Processing model

+ + TODO ("Algorithms" section) + +

Security consideration

+ + TODO +

Timers

The setTimeout() and Date: Thu, 9 Apr 2026 11:45:16 +0200 Subject: [PATCH 2/2] Fix build errors, update steps for setHTMLUnsafe --- source | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/source b/source index db1863cb925..33228230670 100644 --- a/source +++ b/source @@ -124725,7 +124725,7 @@ enum DOMParserSupportedType {

shadowRoot.setHTMLUnsafe(html)
+ data-x="dom-ShadowRoot-setHTMLUnsafe">setHTMLUnsafe(html, options)

Parses html using the HTML parser with options options, and replaces the children of @@ -124754,7 +124754,7 @@ enum DOMParserSupportedType {

Element's setHTMLUnsafe(html) method steps + data-x="dom-Element-setHTMLUnsafe">setHTMLUnsafe(html, options) method steps are:

    @@ -124767,14 +124767,14 @@ enum DOMParserSupportedType {
  1. Let target be this's template contents if this is a template element; otherwise this.

  2. -
  3. Unsafely set HTML given target, this, and - compliantHTML.

  4. +
  5. Set and filter HTML given target, this, + compliantHTML, options, and false.

ShadowRoot's setHTMLUnsafe(html) method steps + data-x="dom-ShadowRoot-setHTMLUnsafe">setHTMLUnsafe(html, options) method steps are:

    @@ -124784,8 +124784,8 @@ enum DOMParserSupportedType { object, html, "ShadowRoot setHTMLUnsafe", and "script".

    -
  1. Unsafely set HTML given this, this's shadow host, and compliantHTML.

  2. +
  3. Set and filter HTML given this, this's shadow host, compliantHTML, options, and false.

@@ -124852,6 +124852,21 @@ enum DOMParserSupportedType { + +

Safe HTML parsing methods

@@ -124860,8 +124875,8 @@ enum DOMParserSupportedType {
-
partial interface Element {
-};
+
+
@@ -125413,7 +125428,7 @@ interface XMLSerializer { -

HTML sanitization

+

HTML sanitization

The Sanitizer interface

@@ -125448,8 +125463,8 @@ interface Sanitizer { // Used by "elements" dictionary SanitizerElementNamespaceWithAttributes : SanitizerElementNamespace { - sequence attributes; - sequence removeAttributes; + sequence<SanitizerAttribute> attributes; + sequence<SanitizerAttribute> removeAttributes; }; typedef (DOMString or SanitizerElementNamespace) SanitizerElement; @@ -125462,12 +125477,12 @@ dictionary SanitizerAttributeNamespace { typedef (DOMString or SanitizerAttributeNamespace) SanitizerAttribute; dictionary SanitizerConfig { - sequence elements; - sequence removeElements; - sequence replaceWithChildrenElements; + sequence<SanitizerElementWithAttributes> elements; + sequence<SanitizerElement> removeElements; + sequence<SanitizerElement> replaceWithChildrenElements; - sequence attributes; - sequence removeAttributes; + sequence<SanitizerAttribute> attributes; + sequence<SanitizerAttribute> removeAttributes; boolean comments; boolean dataAttributes;