diff --git a/source b/source index 90c6259281b..483cdd18bd9 100644 --- a/source +++ b/source @@ -4993,7 +4993,10 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • TrustedScript
  • data
  • TrustedScriptURL
  • +
  • TrustedParserOptions
  • get trusted type compliant string
  • +
  • get trusted type compliant input
  • +
  • TrustedParserOptions sanitizer config
  • @@ -11634,7 +11637,7 @@ typedef (HTMLScriptElement or SVGScriptElement) LegacyOverrideBuiltIns] partial interface Document { - static Document parseHTMLUnsafe((TrustedHTML or DOMString) html, optional ParseHTMLUnsafeOptions options = {}); + static Document parseHTMLUnsafe((TrustedHTML or DOMString) html, optional (ParseHTMLUnsafeOptions or TrustedParserOptions) options = {}); static Document parseHTML(DOMString html, optional SetHTMLOptions options = {}); // resource metadata management @@ -125450,7 +125453,7 @@ document.body.appendChild(frame)
    partial interface Element {
       [CEReactions] undefined setHTML(DOMString html, optional SetHTMLOptions options = {});
    -  [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional SetHTMLUnsafeOptions options = {});
    +  [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional (SetHTMLUnsafeOptions or TrustedParserOptions) options = {});
       DOMString getHTML(optional GetHTMLOptions options = {});
     
       [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
    @@ -125460,7 +125463,7 @@ document.body.appendChild(frame)
    partial interface ShadowRoot { [CEReactions] undefined setHTML(DOMString html, optional SetHTMLOptions options = {}); - [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional SetHTMLUnsafeOptions options = {}); + [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html, optional (SetHTMLUnsafeOptions or TrustedParserOptions) options = {}); DOMString getHTML(optional GetHTMLOptions options = {}); [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML; @@ -125730,8 +125733,8 @@ enum DOMParserSupportedType {
  • Let target be this's template contents if this is a template element; otherwise this.

  • -
  • Set and filter HTML given target, html, - options, and true.

  • +
  • Set and filter HTML given target, html, and + options.

  • @@ -125741,8 +125744,8 @@ enum DOMParserSupportedType { steps are:

      -
    1. Set and filter HTML given this, html, - options, and true.

    2. +
    3. Set and filter HTML given this, html, and + options.

    @@ -125752,17 +125755,17 @@ enum DOMParserSupportedType { method steps are:

      -
    1. Let compliantHTML be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, html, "Element setHTMLUnsafe", and "script".

    2. +
    3. Let (compliantHTML, compliantOptions) be the result of invoking the + get trusted type compliant input algorithm with + this's relevant global object, html, options, and + "Element setHTMLUnsafe".

    4. Let target be this's template contents if this is a template element; otherwise this.

    5. Set and filter HTML given target, compliantHTML, - options, and false.

    6. + compliantOptions, and Unsafe.

    @@ -125772,14 +125775,14 @@ enum DOMParserSupportedType { options)
    method steps are:

      -
    1. Let compliantHTML be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, html, "ShadowRoot setHTMLUnsafe", and "script".

    2. +
    3. Let (compliantHTML, compliantOptions) be the result of invoking the + get trusted type compliant input algorithm with + this's relevant global object, html, options, an + "ShadowRoot setHTMLUnsafe".

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

    6. +
    7. Set and filter HTML given this, + compliantHTML, compliantOptions, and Unsafe.

    @@ -125810,8 +125813,8 @@ enum DOMParserSupportedType {
  • Let sanitizer be the result of calling get a sanitizer instance from options with options and true.

  • -
  • Call sanitize on document with sanitizer and - true.

  • +
  • If sanitizer is not null, then sanitize document with + sanitizer and true.

  • Return document.

  • @@ -125823,11 +125826,10 @@ enum DOMParserSupportedType { method steps are:

      -
    1. Let compliantHTML be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, html, "Document parseHTMLUnsafe", and "script".

    2. +
    3. Let (compliantHTML, compliantOptions) be the result of invoking the + get trusted type compliant input algorithm with + this's relevant global object, html, options, and + "Document parseHTMLUnsafe".

    4. Let document be a new Document, whose DOMParserSupportedType { compliantHTML.

    5. Let sanitizer be the result of calling get a sanitizer instance from - options with options and false.

    6. + options with compliantOptions and false.

      -
    7. Call sanitize on document with sanitizer and - false.

    8. +
    9. If sanitizer is not null, then sanitize document with + sanitizer and false.

    10. Return document.

    @@ -125958,23 +125960,115 @@ enum DOMParserSupportedType { +

    A fragment parser mode is one of the following:

    + +
    +
    Legacy
    +
    Unsafe elements and attributes are allowed, + while declarative shadow roots are ignored. + XML documents are parsed using the XML parser.
    + +
    Unsafe
    +
    Unsafe elements and attributes are allowed, + alongside declarative shadow roots. The + HTML parser is used regardless of the type of document.
    + +
    Normal
    +
    Unsafe elements and attributes are removed, + while declarative shadow roots are allowed. + The HTML parser is used regardless of the type of document.
    +
    + +
    +

    To set and filter HTML, given an Element or + DocumentFragment target, a string html, a dictionary or TrustedParserOptions object options, and an + optional fragment parser mode mode (default Normal):

    + +
      +
    1. Let fragment be the result of invoking the fragment parsing algorithm + steps given target, html, options, and + mode.

    2. + +
    3. If fragment is non-null, then replace + all with fragment within target.

    4. +
    +
    +

    The fragment parsing algorithm steps, given an Element or - DocumentFragment target, a string markup, and an optional - parser scripting mode scriptingMode (default Inert), are:

    + DocumentFragment target, a string markup, a dictionary or TrustedParserOptions object options, and a + fragment parser mode mode, are:

      -
    1. Assert: scriptingMode is either Inert or Fragment. +

    2. Let context be target if target is an + Element; otherwise target's host.

    3. -
    4. If target's node document is an XML - document, then return the result of invoking the XML fragment parsing - algorithm given target and markup.

    5. +
    6. Assert: context is non-null.

    7. -
    8. Return the result of the HTML fragment parsing algorithm given - target, markup, false, and scriptingMode.

    9. +
    10. +

      If all of the following are true:

      +
        +
      • mode is Normal;
      • +
      • context's local name is + "script"; and
      • context's namespace is the HTML namespace or the + SVG namespace,
      • +
      +

      then return null.

      +
    11. + +
    12. Let safe be true if mode is Normal; otherwise false.

    13. + +
    14. Let sanitizer be the result of calling getting a sanitizer from options given safe.

    15. + +
    16. Let scriptingMode be Inert.

    17. + +
    18. +

      If options["runScripts"] + is true:

      +
        +
      1. Assert: mode is not Normal.

      2. + +
      3. Set scriptingMode to Fragment.

      4. +
      +
    19. + +
    20. Let allowDeclarativeShadowRoots be false if mode is Legacy; otherwise true.

    21. + +
    22. +

      If mode is Legacy and + target's node document is an XML + document, then: + +

        +
      1. +

        If sanitizer is non-null, then throw a TypeError.

        + +

        Sanitization is only supported on HTML documents.

        +
      2. + +
      3. Return the result of invoking the XML fragment parsing algorithm given + target and markup.

      4. +
      +
    23. + +
    24. Let fragment be the result of the HTML fragment parsing algorithm + given target, markup, allowDeclarativeShadowRoots, and + scriptingMode.

    25. + +
    26. If sanitizer is not null, then sanitize fragment given + sanitizer and safe.

    27. + +
    28. Return fragment.

    @@ -125991,52 +126085,39 @@ enum DOMParserSupportedType {
    -

    Element's innerHTML setter steps - are:

    +

    Element's innerHTML setter steps given + value are:

      -
    1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, the given value, "Element innerHTML", and "script".

    2. - -
    3. Let target be this.

    4. +
    5. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + this's relevant global object, value, a new + SetHTMLUnsafeOptions dictionary, and "Element + innerHTML".

    6. -
    7. -

      If target is a template element, then set target to the - template element's template contents (a - DocumentFragment).

      - -

      Setting innerHTML on a - template element will replace all the nodes in its template contents - rather than its children.

      -
    8. - -
    9. Let fragment be the result of invoking the fragment parsing algorithm - steps with target and compliantString.

    10. +
    11. Let target be this's template contents if + this is a template element; otherwise this.

    12. -
    13. Replace all with fragment - within target.

    14. +
    15. Set and filter HTML given target, compliantString, + compliantOptions, and Legacy.

    -

    ShadowRoot's innerHTML setter - steps are:

    +

    ShadowRoot's innerHTML setter steps + given value are:

      -
    1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, the given value, "ShadowRoot innerHTML", and "script".

    2. +
    3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + this's relevant global object, value, a new + SetHTMLUnsafeOptions dictionary, and "ShadowRoot + innerHTML".

    4. -
    5. Let fragment be the result of invoking the fragment parsing algorithm - steps with this and compliantString.

    6. - -
    7. Replace all with fragment - within this.

    8. +
    9. Set and filter HTML given this, + compliantString, compliantOptions, and Legacy.

    @@ -126087,34 +126168,35 @@ enum DOMParserSupportedType {
    -

    Element's outerHTML setter steps - are:

    +

    Element's outerHTML setter steps given + value are:

      -
    1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, the given value, "Element outerHTML", and "script".

    2. +
    3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + this's relevant global object, value, a new + SetHTMLUnsafeOptions dictionary, and "Element + outerHTML".

    4. -
    5. Let parent be this's parent.

    6. +
    7. Let parent be this's parent.

    8. -
    9. If parent is null, return. There would be no way to obtain a - reference to the nodes created even if the remaining steps were run.

    10. +
    11. If parent is null, return. There would be no way to obtain a reference to the + nodes created even if the remaining steps were run.

    12. -
    13. If parent is a Document, throw a - "NoModificationAllowedError" DOMException.

    14. +
    15. If parent is a Document, throw a + "NoModificationAllowedError" DOMException.

    16. -
    17. If parent is a DocumentFragment, set parent to the - result of creating an element given this's - node document, "body", and the HTML - namespace.

    18. +
    19. If parent is a DocumentFragment, set parent to the + result of creating an element given this's + node document, "body", and the HTML + namespace.

    20. -
    21. Let fragment be the result of invoking the fragment parsing algorithm - steps given parent and compliantString.

    22. +
    23. Let fragment be the result of invoking the fragment parsing algorithm + steps given parent, compliantString, compliantOptions, + and Legacy.

    24. -
    25. Replace this with - fragment within this's parent.

    26. +
    27. Replace this with + fragment within this's parent.

    @@ -126168,11 +126250,11 @@ enum DOMParserSupportedType { string) method steps are:

      -
    1. Let compliantString be the result of invoking the get trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, string, "Element insertAdjacentHTML", and "script".

    2. +
    3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + this's relevant global object, string, a new + SetHTMLUnsafeOptions dictionary, and "Element + insertAdjacentHTML".

    4. Let context be null.

    5. @@ -126215,10 +126297,9 @@ enum DOMParserSupportedType { data-x="">body", and the HTML namespace.

      -
    6. -

      Let fragment be the result of invoking the fragment parsing algorithm - steps with context and compliantString.

      -
    7. +
    8. Let fragment be the result of invoking the fragment parsing algorithm + steps given context, compliantString, compliantOptions, + and Legacy.

    9. Use the first matching item from this list:
      @@ -126294,11 +126375,12 @@ enum DOMParserSupportedType { method steps are:

        -
      1. Let compliantString be the result of invoking the get - trusted type compliant string algorithm with TrustedHTML, this's relevant global - object, string, "Range createContextualFragment", and - "script".

      2. +
      3. Let (compliantString, compliantOptions) be the result of invoking + the get trusted type compliant input algorithm with + this's relevant global object, string, a new + SetHTMLUnsafeOptions whose runScripts is true, and "Range createContextualFragment".

      4. Let node be this's start node.

      5. @@ -126330,9 +126412,9 @@ enum DOMParserSupportedType { data-x="">body", and the HTML namespace.

        -
      6. Return the result of invoking the fragment parsing algorithm steps with - element, compliantString, and Fragment.

      7. +
      8. Return the result of invoking the fragment parsing algorithm steps given + element, compliantString, compliantOptions, and Legacy.

      @@ -127697,79 +127779,34 @@ dictionary SanitizerConfig {

      Sanitization algorithms

      +
      -

      To set and filter HTML, given an Element or - DocumentFragment target, a string html, a - dictionary options, and a boolean safe:

      +

      To get a sanitizer instance from options from a TrustedParserOptions or dictionary options, + given a boolean safe:

        -
      1. Let context be target if target is an - Element; otherwise target's host.

      2. - -
      3. Assert: context is non-null.

      4. - -
      5. -

        If all of the following are true:

        - -
          -
        • safe;

        • - -
        • context's local name is - "script"; and

        • - -
        • context's namespace is the - HTML namespace or the SVG namespace,

        • -
        - -

        then return.

        -
      6. - -
      7. Let sanitizer be the result of calling getting a sanitizer from options given safe.

      8. - -
      9. Let scriptingMode be Inert.

      10. +
      11. Let sanitizerSpec be "default".

      12. -

        If options["runScripts"] - is true:

        +

        If options is a TrustedParserOptions, then:

          -
        1. Assert: safe is false.

        2. +
        3. If options's sanitizer config is null, then return + null.

        4. -
        5. Set scriptingMode to Fragment.

          +
        6. Set sanitizerSpec to options's sanitizer config.

      13. -
      14. -

        Let fragment be the result of invoking the HTML fragment parsing - algorithm given target, html, true, and - scriptingMode.

        - -

        Scripts in fragment will only execute once inserted into - target.

        -
      15. - -
      16. Sanitize fragment given sanitizer and - safe.

      17. - -
      18. Replace all with fragment within - target.

      19. -
      -
      - -
      -

      To get a sanitizer instance from options from a dictionary options with a - boolean safe:

      - -
        -
      1. Let sanitizerSpec be "default".

      2. - -
      3. If options["sanitizer"] - exists, then set sanitizerSpec to - options["sanitizer"].

      4. +
      5. Otherwise, if options["sanitizer"] exists, + then set sanitizerSpec to options["sanitizer"].

      6. Assert: sanitizerSpec is either a Sanitizer instance, a SanitizerPresets member, or a SanitizerConfig dictionary.