From aa3fe7e2fccf48ba09776b8ec964408171bf86ef Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 24 Apr 2025 13:32:52 +0100 Subject: [PATCH 1/8] Trusted Types --- dom.bs | 93 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/dom.bs b/dom.bs index e61c3fc0..50b6ab1e 100644 --- a/dom.bs +++ b/dom.bs @@ -50,9 +50,11 @@ spec:html; type:element

This specification depends on the Infra Standard. [[!INFRA]]

Some of the terms used in this specification are defined in Encoding, -Selectors, Web IDL, XML, and Namespaces in XML. +Selectors, Trusted Types, Web IDL, XML, and +Namespaces in XML. [[!ENCODING]] [[!SELECTORS4]] +[[!TRUSTED-TYPES]] [[!WEBIDL]] [[!XML]] [[!XML-NAMES]] @@ -6633,8 +6635,8 @@ interface Element : Node { sequence<DOMString> getAttributeNames(); DOMString? getAttribute(DOMString qualifiedName); DOMString? getAttributeNS(DOMString? namespace, DOMString localName); - [CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value); - [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value); + [CEReactions] undefined setAttribute(DOMString qualifiedName, (TrustedType or DOMString) value); + [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, (TrustedType or DOMString) value); [CEReactions] undefined removeAttribute(DOMString qualifiedName); [CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName); [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force); @@ -7063,6 +7065,14 @@ steps: value. +

To verify attribute value given a {{TrustedType}} or string value, an +attribute attribute, and an Element element: + +

    +
  1. Return the result of calling get Trusted Types-compliant attribute value + given attribute, with element, and value. [[!TRUSTED-TYPES]] +

+
@@ -7115,6 +7125,10 @@ string namespace (default null):

attribute attr and an element element:
    +
  1. Let verifiedValue be the result of + verifying an attribute value given attr's + value, attr, and element. +

  2. If attr's element is neither null nor element, throw an "{{InUseAttributeError!!exception}}" {{DOMException}}. @@ -7130,6 +7144,8 @@ string namespace (default null):

  3. Otherwise, append attr to element. +

  4. Set attr's value to verifiedValue. +

  5. Return oldAttr.

@@ -7141,18 +7157,32 @@ an optional null or string prefix (default null), and an optional nul namespace (default null):
    -
  1. Let attribute be the result of +
  2. Let attribute be the result of getting an attribute given namespace, localName, and element. -

  3. If attribute is null, create an attribute whose namespace is - namespace, namespace prefix is prefix, - local name is localName, value is value, and - node document is element's node document, then - append this attribute to element, and then - return. +
  4. If attribute is null, then set attribute to an attribute whose + namespace is namespace, namespace prefix is + prefix, local name is localName, value is + value, and node document is element's + node document. + +

  5. Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and element. -

  6. Change attribute to value. +

  7. Set attribute to the result of + getting an attribute given + namespace, localName, and element. + +

  8. If attribute is null, create an attribute whose namespace + is namespace, namespace prefix is prefix, + local name is localName, value is + verifiedValue, and node document is element's + node document, then append this attribute to + element, and then return. + +

  9. Change attribute to verifiedValue.

@@ -7417,14 +7447,26 @@ method steps are:
  • Let attribute be the first attribute in this's attribute list whose qualified name is qualifiedName, and null otherwise. - + +

  • If attribute is null, then set attribute to an attribute + whose local name is qualifiedName, value is + value, and node document is this's node document. + +

  • Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and this. + +

  • Set attribute to the first attribute in this's + attribute list whose qualified name is qualifiedName, + and null otherwise.

  • If attribute is null, create an attribute whose local name is qualifiedName, value is - value, and node document is this's node document, - then append this attribute to this, and then return. + verifiedValue, and node document is this's + node document, then append this attribute + to this, and then return. -

  • Change attribute to value. +

  • Change attribute to verifiedValue.

    The @@ -7437,7 +7479,7 @@ method steps are: qualifiedName given "element".

  • Set an attribute value for this using localName, value, - and also prefix and namespace. + prefix, namespace and true.

    The @@ -8028,7 +8070,24 @@ string value, run these steps:

  • If attribute's element is null, then set attribute's value to value. -

  • Otherwise, change attribute to value. +

  • +

    Otherwise: + +

      +
    1. Let originalElement be attribute's element. + +

    2. Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and this. + +

    3. If attribute's element is null, then set attribute's + value to verifiedValue, and return. + +

    4. If attribute's element is not originalElement, then + return. + +

    5. Change attribute to verifiedValue. +

    The {{Attr/value}} setter steps are to set an existing attribute value with this From 526f42291faaf40b127e5e8541305fbff68a44e3 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 24 Apr 2025 13:42:02 +0100 Subject: [PATCH 2/8] Revert change to "set an attribute value" --- dom.bs | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/dom.bs b/dom.bs index 50b6ab1e..e03c9f0d 100644 --- a/dom.bs +++ b/dom.bs @@ -7157,32 +7157,18 @@ an optional null or string prefix (default null), and an optional nul namespace (default null):

      -
    1. Let attribute be the result of +

    2. Let attribute be the result of getting an attribute given namespace, localName, and element. -
    3. If attribute is null, then set attribute to an attribute whose - namespace is namespace, namespace prefix is - prefix, local name is localName, value is - value, and node document is element's - node document. - -

    4. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and element. - -

    5. Set attribute to the result of - getting an attribute given - namespace, localName, and element. - -

    6. If attribute is null, create an attribute whose namespace - is namespace, namespace prefix is prefix, - local name is localName, value is - verifiedValue, and node document is element's - node document, then append this attribute to - element, and then return. +

    7. If attribute is null, create an attribute whose namespace is + namespace, namespace prefix is prefix, + local name is localName, value is value, and + node document is element's node document, then + append this attribute to element, and then + return. -
    8. Change attribute to verifiedValue. +

    9. Change attribute to value.

    From 00d0eaadffaf32ad98076893dc3c6d2a52541181 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 24 Apr 2025 14:11:53 +0100 Subject: [PATCH 3/8] Update setAttributeNS to include TT check --- dom.bs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index e03c9f0d..bccae19c 100644 --- a/dom.bs +++ b/dom.bs @@ -7464,8 +7464,32 @@ method steps are: [=validate and extract|validating and extracting=] namespace and qualifiedName given "element". -
  • Set an attribute value for this using localName, value, - prefix, namespace and true. +

  • Let attribute be the result of + getting an attribute given + namespace, localName, and element. + +

  • If attribute is null, then set attribute to an attribute whose + namespace is namespace, namespace prefix is + prefix, local name is localName, value is + value, and node document is element's + node document. + +

  • Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and element. + +

  • Set attribute to the result of + getting an attribute given + namespace, localName, and element. + +

  • If attribute is null, create an attribute whose namespace + is namespace, namespace prefix is prefix, + local name is localName, value is + verifiedValue, and node document is element's + node document, then append this attribute to + element, and then return. + +

  • Change attribute to verifiedValue.

    The From f5e3984bb8a536ac64e5dcee92ace1210952eda0 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Wed, 25 Jun 2025 15:19:13 +0100 Subject: [PATCH 4/8] Remove extra algorithm that called through to TT and call TT directly from the various algorithms, also update call signature to match changes in TT. --- dom.bs | 56 ++++++++++++++++---------------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/dom.bs b/dom.bs index bccae19c..9ad411ec 100644 --- a/dom.bs +++ b/dom.bs @@ -7065,14 +7065,6 @@ steps: value. -

    To verify attribute value given a {{TrustedType}} or string value, an -attribute attribute, and an Element element: - -

      -
    1. Return the result of calling get Trusted Types-compliant attribute value - given attribute, with element, and value. [[!TRUSTED-TYPES]] -

    -
    @@ -7125,9 +7117,10 @@ string namespace (default null):

    attribute attr and an element element:
      -
    1. Let verifiedValue be the result of - verifying an attribute value given attr's - value, attr, and element. +

    2. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with attr's local name, + attr's namespace, element, and attr's + value. [[!TRUSTED-TYPES]]

    3. If attr's element is neither null nor element, throw an "{{InUseAttributeError!!exception}}" {{DOMException}}. @@ -7430,19 +7423,11 @@ method steps are: HTML document, then set qualifiedName to qualifiedName in ASCII lowercase. -

    4. Let attribute be the first attribute in this's - attribute list whose qualified name is qualifiedName, - and null otherwise. - -

    5. If attribute is null, then set attribute to an attribute - whose local name is qualifiedName, value is - value, and node document is this's node document. - -

    6. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and this. +

    7. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with qualifiedName, null, this, and + value. [[!TRUSTED-TYPES]] -

    8. Set attribute to the first attribute in this's +

    9. Let attribute be the first attribute in this's attribute list whose qualified name is qualifiedName, and null otherwise. @@ -7464,21 +7449,11 @@ method steps are: [=validate and extract|validating and extracting=] namespace and qualifiedName given "element". -

    10. Let attribute be the result of - getting an attribute given - namespace, localName, and element. - -

    11. If attribute is null, then set attribute to an attribute whose - namespace is namespace, namespace prefix is - prefix, local name is localName, value is - value, and node document is element's - node document. - -

    12. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and element. +

    13. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with localName, namespace, + element, and value. [[!TRUSTED-TYPES]] -

    14. Set attribute to the result of +

    15. Let attribute be the result of getting an attribute given namespace, localName, and element. @@ -8086,9 +8061,10 @@ string value, run these steps:

      1. Let originalElement be attribute's element. -

      2. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and this. +

      3. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with attribute's + local name, attribute's namespace, this, + and value. [[!TRUSTED-TYPES]]

      4. If attribute's element is null, then set attribute's value to verifiedValue, and return. From df2bccd1f43d361c262620d26e5b496adf29f30c Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 3 Jul 2025 10:02:09 +0100 Subject: [PATCH 5/8] Revert larger change to setAttributeNs as its no longer neccessary. --- dom.bs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/dom.bs b/dom.bs index 9ad411ec..40691488 100644 --- a/dom.bs +++ b/dom.bs @@ -7453,18 +7453,8 @@ method steps are: Trusted Types-compliant attribute value with localName, namespace, element, and value. [[!TRUSTED-TYPES]] -

      5. Let attribute be the result of - getting an attribute given - namespace, localName, and element. - -

      6. If attribute is null, create an attribute whose namespace - is namespace, namespace prefix is prefix, - local name is localName, value is - verifiedValue, and node document is element's - node document, then append this attribute to - element, and then return. - -

      7. Change attribute to verifiedValue. +

      8. Set an attribute value for this using localName, + verifiedValue, and also prefix and namespace.

      The From eb1b5463767bcc0ac5d7317e56cea531dbad3e7a Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 3 Jul 2025 13:34:36 +0100 Subject: [PATCH 6/8] Set attr's value to verifiedValue before attribute change steps are fired. --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 40691488..9418efde 100644 --- a/dom.bs +++ b/dom.bs @@ -7132,13 +7132,13 @@ string namespace (default null):

    16. If oldAttr is attr, return attr. +

    17. Set attr's value to verifiedValue. +

    18. If oldAttr is non-null, then replace oldAttr with attr.

    19. Otherwise, append attr to element. -

    20. Set attr's value to verifiedValue. -

    21. Return oldAttr.

    From 1e3cef84935091e44985cb3d34d138cda1b98959 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 30 Sep 2025 21:13:03 +0100 Subject: [PATCH 7/8] Replace this with originalElement inside set an existing attribute value --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 9418efde..4f300a1e 100644 --- a/dom.bs +++ b/dom.bs @@ -8053,8 +8053,8 @@ string value, run these steps:
  • Let verifiedValue be the result of calling get Trusted Types-compliant attribute value with attribute's - local name, attribute's namespace, this, - and value. [[!TRUSTED-TYPES]] + local name, attribute's namespace, + originalElement, and value. [[!TRUSTED-TYPES]]

  • If attribute's element is null, then set attribute's value to verifiedValue, and return. From 6fe40a326ffbd63890a5422f2c38faf63978f64c Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 30 Sep 2025 21:46:04 +0100 Subject: [PATCH 8/8] Rename originalElement to just element --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 4f300a1e..b5f167fe 100644 --- a/dom.bs +++ b/dom.bs @@ -8049,17 +8049,17 @@ string value, run these steps:

    Otherwise:

      -
    1. Let originalElement be attribute's element. +

    2. Let element be attribute's element.

    3. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value with attribute's local name, attribute's namespace, - originalElement, and value. [[!TRUSTED-TYPES]] + element, and value. [[!TRUSTED-TYPES]]

    4. If attribute's element is null, then set attribute's value to verifiedValue, and return. -

    5. If attribute's element is not originalElement, then +

    6. If attribute's element is not element, then return.

    7. Change attribute to verifiedValue.