diff --git a/source b/source index 631f655f890..622cd551b1d 100644 --- a/source +++ b/source @@ -4788,7 +4788,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • TrustedScript
  • data
  • TrustedScriptURL
  • -
  • Get Trusted Type compliant string
  • +
  • get trusted type compliant string
  • +
  • should sink type mismatch violation be blocked by content security policy?
  • @@ -35426,7 +35427,7 @@ interface HTMLIFrameElement : HTMLElement {
    1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, the given value, "HTMLIFrameElement srcdoc", and "script".

    2. @@ -123378,7 +123379,7 @@ document.body.appendChild(frame)
    3. If isTrusted is false, set string to the result of invoking the - Get Trusted Type compliant string algorithm with + get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, string, sink, and "script".

    4. @@ -123478,7 +123479,7 @@ document.body.appendChild(frame)

      DOM parsing and serialization APIs

      -
      partial interface Element {
      +  
      partial interface Element {
         [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html);
         DOMString getHTML(optional GetHTMLOptions options = {});
       
      @@ -123487,7 +123488,7 @@ document.body.appendChild(frame)
      [CEReactions] undefined insertAdjacentHTML(DOMString position, (TrustedHTML or DOMString) string); }; -partial interface ShadowRoot { +partial interface ShadowRoot { [CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html); DOMString getHTML(optional GetHTMLOptions options = {}); @@ -123567,7 +123568,7 @@ enum DOMParserSupportedType {
      1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, string, "DOMParser parseFromString", and "script".

      2. @@ -123713,7 +123714,7 @@ enum DOMParserSupportedType {
        1. Let compliantHTML be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, html, "Element setHTMLUnsafe", and "script".

        2. @@ -123733,7 +123734,7 @@ enum DOMParserSupportedType {
          1. Let compliantHTML be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, html, "ShadowRoot setHTMLUnsafe", and "script".

          2. @@ -123771,7 +123772,7 @@ enum DOMParserSupportedType {
            1. Let compliantHTML be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, html, "Document parseHTMLUnsafe", and "script".

            2. @@ -123946,7 +123947,7 @@ enum DOMParserSupportedType {
              1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, the given value, "Element innerHTML", and "script".

              2. @@ -123977,7 +123978,7 @@ enum DOMParserSupportedType {
                1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, the given value, "ShadowRoot innerHTML", and "script".

                2. @@ -124045,7 +124046,7 @@ enum DOMParserSupportedType {
                  1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, the given value, "Element outerHTML", and "script".

                  2. @@ -124122,7 +124123,7 @@ enum DOMParserSupportedType {
                    1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedHTML, this's relevant global object, string, "Element insertAdjacentHTML", and "script".

                    2. @@ -124357,6 +124358,105 @@ interface XMLSerializer { +

                      Patching

                      + +

                      TODO: introduction, what's all this?

                      + +
                      partial interface Element {
                      +  WritableStream streamHTMLUnsafe(optional StreamHTMLUnsafeOptions options = {});
                      +};
                      +
                      +partial interface ShadowRoot {
                      +  WritableStream streamHTMLUnsafe(optional StreamHTMLUnsafeOptions options = {});
                      +};
                      +
                      +dictionary StreamHTMLUnsafeOptions {
                      +  boolean runScripts = false;
                      +};
                      + +
                      + +
                      +

                      Element's streamHTMLUnsafe(options) method steps + are:

                      + +
                        +
                      1. Let disposition be the result of invoking the should sink type mismatch violation be blocked by content security + policy? algorithm given this's relevant global object, + "Element streamHTMLUnsafe", "script", and "".

                      2. + +
                      3. If disposition is not "Allowed", throw a TypeError.

                      4. + +
                      5. Let writable be a new WritableStream.

                      6. + +
                      7. +

                        👋 Sketch of the streams setup:

                        + +
                          +
                        1. Incoming chunks must all be of the same type, either strings or a trusted types + wrapper. Check this on every chunk and treat mixing as an error.

                        2. + +
                        3. If the first chunk is not a trusted types wrapper and there is a default TT policy, + create a transform stream using createTransformStream from the default + policy. Then pipe chunks through that transform stream.

                        4. + +
                        5. For trusted types handled "outside" (not by the internal transform stream) check that + the chunks are in the same order and not duplicated/filtered/reordered.

                        6. +
                        +
                      8. + +
                      9. +

                        👋 Sketch of the parser setup:

                        + +
                          +
                        1. Let parser be a new fragment parser.

                        2. + +
                        3. Add this to the stack of open elements.

                        4. + +
                        5. If options["runScripts"], + don't mark scripts as already executed.

                        6. + +
                        7. Write chunks into the parser as they are written to writable.

                        8. +
                        +
                      10. + +
                      11. Return writable.

                      12. +
                      +
                      + +
                      +

                      Do a thing like this:

                      +
                      const policy = trustedTypes.createPolicy("my-policy", {
                      +  createTransformStream() {
                      +    return new TransformStream({
                      +      transform(chunk, controller) {
                      +        // TODO: some buffering
                      +        controller.enqueue(sanitize(chunk));
                      +      }
                      +    });
                      +  }
                      +});
                      +
                      +const response = await fetch('/fragments/something');
                      +const transform = policy.createTransformStream();
                      +const writable = element.streamHTMLUnsafe();
                      +await response.body.pipeThrough(transform).pipeTo(writable);
                      +
                      + +
                      +

                      ShadowRoot's streamHTMLUnsafe(options) method steps + are:

                      + +
                        +
                      1. TODO
                      2. +
                      +
                      + +
                      +

                      Timers

                      The setTimeout() and XMLSerializer { methodName.

                    3. Set handler to the result of invoking the Get Trusted Type compliant string algorithm with + data-x="tt-getcompliantstring">get trusted type compliant string algorithm with TrustedScript, global, handler, sink, and "script".

                    @@ -131081,7 +131181,7 @@ enum WorkerType { "classic", "module" };
                    1. Let compliantScriptURL be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedScriptURL, this's relevant global object, scriptURL, "Worker constructor", and "script".

                    2. @@ -131206,7 +131306,7 @@ interface SharedWorker : EventTarget {
                      1. Let compliantScriptURL be the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedScriptURL, this's relevant global object, scriptURL, "SharedWorker constructor", and "script".

                      2. @@ -131444,7 +131544,7 @@ interface SharedWorker : EventTarget {
                        1. Append the result of invoking the Get Trusted Type compliant string algorithm with get trusted type compliant string algorithm with TrustedScriptURL, this's relevant global object, url, "WorkerGlobalScope importScripts", and "script" to urlStrings.