Skip to content

Commit 918ebc0

Browse files
authored
Integrate Trusted Types enforcement into attribute handling
This adds the necessary integration with Trusted Types to ensure attribute values are protected. See #789 for context.
1 parent eb29661 commit 918ebc0

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

dom.bs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ spec:html; type:element
5050
<p>This specification depends on the Infra Standard. [[!INFRA]]
5151

5252
<p>Some of the terms used in this specification are defined in <cite>Encoding</cite>,
53-
<cite>Selectors</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and <cite>Namespaces in XML</cite>.
53+
<cite>Selectors</cite>, <cite>Trusted Types</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and
54+
<cite>Namespaces in XML</cite>.
5455
[[!ENCODING]]
5556
[[!SELECTORS4]]
57+
[[!TRUSTED-TYPES]]
5658
[[!WEBIDL]]
5759
[[!XML]]
5860
[[!XML-NAMES]]
@@ -6633,8 +6635,8 @@ interface Element : Node {
66336635
sequence&lt;DOMString> getAttributeNames();
66346636
DOMString? getAttribute(DOMString qualifiedName);
66356637
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
6636-
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
6637-
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
6638+
[CEReactions] undefined setAttribute(DOMString qualifiedName, (TrustedType or DOMString) value);
6639+
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, (TrustedType or DOMString) value);
66386640
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
66396641
[CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
66406642
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
@@ -7115,6 +7117,11 @@ string <var>namespace</var> (default null):</p>
71157117
<a for=/>attribute</a> <var>attr</var> and an <a for=/>element</a> <var>element</var>:
71167118

71177119
<ol>
7120+
<li><p>Let <var>verifiedValue</var> be the result of calling
7121+
<a>get trusted type compliant attribute value</a> with <var>attr</var>'s
7122+
<a for=Attr>local name</a>, <var>attr</var>'s <a for=Attr>namespace</a>, <var>element</var>, and
7123+
<var>attr</var>'s <a for=Attr>value</a>. [[!TRUSTED-TYPES]]
7124+
71187125
<li><p>If <var>attr</var>'s <a for=Attr>element</a> is neither null nor <var>element</var>,
71197126
<a>throw</a> an "{{InUseAttributeError!!exception}}" {{DOMException}}.
71207127

@@ -7125,6 +7132,8 @@ string <var>namespace</var> (default null):</p>
71257132

71267133
<li><p>If <var>oldAttr</var> is <var>attr</var>, return <var>attr</var>.
71277134

7135+
<li><p>Set <var>attr</var>'s <a for=Attr>value</a> to <var>verifiedValue</var>.
7136+
71287137
<li><p>If <var>oldAttr</var> is non-null, then <a lt="replace an attribute">replace</a>
71297138
<var>oldAttr</var> with <var>attr</var>.
71307139

@@ -7414,17 +7423,22 @@ method steps are:
74147423
<a>HTML document</a>, then set <var>qualifiedName</var> to <var>qualifiedName</var> in
74157424
<a>ASCII lowercase</a>.
74167425

7426+
<li><p>Let <var>verifiedValue</var> be the result of calling
7427+
<a>get trusted type compliant attribute value</a> with <var>qualifiedName</var>, null, <a>this</a>,
7428+
and <var>value</var>. [[!TRUSTED-TYPES]]
7429+
74177430
<li><p>Let <var>attribute</var> be the first <a>attribute</a> in <a>this</a>'s
74187431
<a for=Element>attribute list</a> whose <a for=Attr>qualified name</a> is <var>qualifiedName</var>,
74197432
and null otherwise.
7420-
<!-- This is step 2 of "get an attribute by name", modified as appropriate -->
74217433

7422-
<li><p>If <var>attribute</var> is null, create an <a>attribute</a> whose
7423-
<a for=Attr>local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is
7424-
<var>value</var>, and <a for=Node>node document</a> is <a>this</a>'s <a for=Node>node document</a>,
7425-
then <a lt="append an attribute">append</a> this <a>attribute</a> to <a>this</a>, and then return.
7434+
<li><p>If <var>attribute</var> is non-null, then <a lt="change an attribute">change</a>
7435+
<var>attribute</var> to <var>verifiedValue</var> and return.
74267436

7427-
<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>value</var>.
7437+
<li><p>Set <var>attribute</var> to a new <a>attribute</a> whose <a for=Attr>local name</a> is
7438+
<var>qualifiedName</var>, <a for=Attr>value</a> is <var>verifiedValue</var>, and
7439+
<a for=Node>node document</a> is <a>this</a>'s <a for=Node>node document</a>.
7440+
7441+
<li><p><a lt="append an attribute">Append</a> <var>attribute</var> to <a>this</a>.
74287442
</ol>
74297443

74307444
<p>The
@@ -7436,8 +7450,12 @@ method steps are:
74367450
[=validate and extract|validating and extracting=] <var>namespace</var> and
74377451
<var>qualifiedName</var> given "<code>element</code>".
74387452

7439-
<li><p><a>Set an attribute value</a> for <a>this</a> using <var>localName</var>, <var>value</var>,
7440-
and also <var>prefix</var> and <var>namespace</var>.
7453+
<li><p>Let <var>verifiedValue</var> be the result of calling
7454+
<a>get trusted type compliant attribute value</a> with <var>localName</var>, <var>namespace</var>,
7455+
<a>this</a>, and <var>value</var>. [[!TRUSTED-TYPES]]
7456+
7457+
<li><p><a>Set an attribute value</a> for <a>this</a> using <var>localName</var>,
7458+
<var>verifiedValue</var>, <var>prefix</var>, and <var>namespace</var>.
74417459
</ol>
74427460

74437461
<p>The
@@ -8027,9 +8045,19 @@ string <var>value</var>, run these steps:
80278045

80288046
<ol>
80298047
<li><p>If <var>attribute</var>'s <a for=Attr>element</a> is null, then set <var>attribute</var>'s
8030-
<a for=Attr>value</a> to <var>value</var>.
8048+
<a for=Attr>value</a> to <var>value</var> and return.
8049+
8050+
<li><p>Let <var>element</var> be <var>attribute</var>'s <a for=Attr>element</a>.
8051+
8052+
<li><p>Let <var>verifiedValue</var> be the result of calling
8053+
<a>get trusted type compliant attribute value</a> with <var>attribute</var>'s
8054+
<a for=Attr>local name</a>, <var>attribute</var>'s <a for=Attr>namespace</a>, <var>element</var>,
8055+
and <var>value</var>. [[!TRUSTED-TYPES]]
8056+
8057+
<li><p>If <var>attribute</var>'s <a for=Attr>element</a> is null, then set <var>attribute</var>'s
8058+
<a for=Attr>value</a> to <var>verifiedValue</var> and return.
80318059

8032-
<li><p>Otherwise, <a lt="change an attribute">change</a> <var>attribute</var> to <var>value</var>.
8060+
<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>verifiedValue</var>.
80338061
</ol>
80348062

80358063
<p>The {{Attr/value}} setter steps are to <a>set an existing attribute value</a> with <a>this</a>

0 commit comments

Comments
 (0)