Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trusted types attributes #1268

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6d4b27d
Draft integration with Trusted Types, take 2.
koto Jan 23, 2024
98ba2fe
Added integration in 'set an attribute value'.
koto Jan 24, 2024
ce190dd
Removed stringification.
koto Jan 24, 2024
a751131
Fixed formatting.
koto Jan 25, 2024
a4463f2
Fixed copy-paste error in setAttribute() and indentation.
koto Jan 25, 2024
3475f8f
Fix build
lukewarlow Mar 28, 2024
d446134
Change code to pass sink values through to TT code.
lukewarlow Mar 28, 2024
d835bc4
Move validate and set attribute into append an attribute
lukewarlow Apr 10, 2024
3fe269c
Remove sink values from spec
lukewarlow Apr 11, 2024
6958b06
Revert changes to setAttributeNode and setAttributeNodeNS method steps
lukewarlow Apr 22, 2024
90b3abb
Remove throw from set an attribute and move TT check down to replace …
lukewarlow Apr 22, 2024
3efbaa8
Revert unneeded changes
lukewarlow Apr 22, 2024
20564e4
Address comment
lukewarlow Apr 22, 2024
e3803db
Add missing and
lukewarlow Apr 22, 2024
0e0516f
Address some comments
lukewarlow May 7, 2024
1c71c66
Re-add early return
lukewarlow May 7, 2024
0f0ed54
Change dfn to use given rather than with
lukewarlow May 7, 2024
55af76e
Update how the enforcement is done
lukewarlow May 16, 2024
6e40964
Add tentative enforcement for toggleAttribute
lukewarlow May 16, 2024
2f00466
Update enforcement for toggleAttribute to match behaviour observed in…
lukewarlow May 16, 2024
08f47c8
Revert "Update enforcement for toggleAttribute to match behaviour obs…
lukewarlow Jun 11, 2024
03384b2
Revert "Add tentative enforcement for toggleAttribute"
lukewarlow Jun 11, 2024
1ec907b
Add verify flag to set an attribute value that is default false and t…
lukewarlow Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 80 additions & 19 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -6080,8 +6080,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);
Expand Down Expand Up @@ -6457,6 +6457,16 @@ steps:
<a for=Attr>value</a>.
</ol>

<p>To <dfn>verify attribute value</dfn>
{{TrustedType}} or string <var>value</var> for an <a>attribute</a> <var>attribute</var>, given an
<a for=/>Element</a> <var>element</var>:

<ol>
<li><p>Return the result of calling
<a abstract-op>get Trusted Types-compliant attribute value</a> for <var>attribute</var>, with
<var>element</var>, <var>value</var>. [[!TRUSTED-TYPES]]
</ol>

<hr>

<div algorithm>
Expand Down Expand Up @@ -6519,6 +6529,11 @@ string <var>namespace</var> (default null):</p>

<li><p>If <var>oldAttr</var> is <var>attr</var>, return <var>attr</var>.
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved

<li><p>Let <var>verifiedValue</var> be the result of calling <a>verify attribute value</a>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers, setAttributeNode, setAttributeNodeNS, setNamedItem and setNamedItemNS

<var>attr</var>'s <a for=Attr>value</a> for <var>attr</var>, with <var>element</var>.

<li><p>Set <var>attr</var>'s <a for=Attr>value</a> to <var>verifiedValue</var>.

<li><p>If <var>oldAttr</var> is non-null, then <a lt="replace an attribute">replace</a>
<var>oldAttr</var> with <var>attr</var>.

Expand All @@ -6530,23 +6545,46 @@ string <var>namespace</var> (default null):</p>

<div algorithm>
<p>To <dfn export id=concept-element-attributes-set-value>set an attribute value</dfn> given an
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This algorithm covers setAttributeNS

<a for=/>element</a> <var>element</var>, a string <var>localName</var>, a string <var>value</var>,
an optional null or string <var>prefix</var> (default null), and an optional null or string
<var>namespace</var> (default null):
<a for=/>element</a> <var>element</var>, a string <var>localName</var>, a string or {{TrustedType}}
<var>value</var>, an optional null or string <var>prefix</var> (default null), an optional null
or string <var>namespace</var> (default null), and an optional boolean <var>verify</var>
(default false):

<ol>
<li>Let <var>attribute</var> be the result of
<a lt="get an attribute by namespace and local name">getting an attribute</a> given
<var>namespace</var>, <var>localName</var>, and <var>element</var>.

<li>If <var>attribute</var> is null, create an <a>attribute</a> whose <a for=Attr>namespace</a> is
<var>namespace</var>, <a for=Attr>namespace prefix</a> is <var>prefix</var>,
<a for=Attr>local name</a> is <var>localName</var>, <a for=Attr>value</a> is <var>value</var>, and
<a for=Node>node document</a> is <var>element</var>'s <a for=Node>node document</a>, then
<a lt="append an attribute">append</a> this <a>attribute</a> to <var>element</var>, and then
return.
<li><p>Let <var>attributeExists</var> be false if <var>attribute</var> is null, and true otherwise.

<li><p>If <var>attributeExists</var> is false, set <var>attribute</var> to an <a>attribute</a>
whose <a for=Attr>namespace</a> is <var>namespace</var>, <a for=Attr>namespace prefix</a> is
<var>prefix</var>, <a for=Attr>local name</a> is <var>localName</var>, <a for=Attr>value</a> is
<var>value</var>, and <a for=Node>node document</a> is <var>element</var>'s <a for=Node>node
document</a>.

<li><p>Let <var>verifiedValue</var> be <var>value</var>.

<li><p>If <var>verify</var> is true:
<ol>
<li><p>Set <var>verifiedValue</var> to the result of calling <a>verify attribute value</a>
<var>value</var> for <var>attribute</var>, with <var>element</var>.

<li><p>Set <var>attributeExists</var> to true if <var>element</var> <a lt="has an attribute">has
an attribute</a> <var>attribute</var>; otherwise false.
</ol>
</li>

<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>value</var>.
<li><p>If <var>attributeExists</var> is true, <a lt="change an attribute">change</a>
<var>attribute</var> to <var>verifiedValue</var>.

<li><p>Otherwise:
<ol>
<li><p>Set <var>attribute</var>'s <a for=Attr>value</a> to <var>verifiedValue</var>.

<li><p><a lt="append an attribute">Append</a> this <a>attribute</a> to
<var>element</var>.
</ol>
</ol>
</div>

Expand Down Expand Up @@ -6807,12 +6845,29 @@ method steps are:
and null otherwise.
<!-- This is step 2 of "get an attribute by name", modified as appropriate -->

<li><p>If <var>attribute</var> is null, create an <a>attribute</a> whose
<a for=Attr>local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is
<var>value</var>, and <a for=Node>node document</a> is <a>this</a>'s <a for=Node>node document</a>,
then <a lt="append an attribute">append</a> this <a>attribute</a> to <a>this</a>, and then return.
<li><p>Let <var>attributeExists</var> be false if <var>attribute</var> is null, and true otherwise.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This algorithm covers setAttribute


<li><p>If <var>attributeExists</var> is false, set <var>attribute</var> to an <a>attribute</a>
whose <a for=Attr>local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is
<var>value</var>, and <a for=Node>node document</a> is <a>this</a>'s <a for=Node>node
document</a>.

<li><p>Let <var>verifiedValue</var> be the result of calling <a>verify attribute value</a>
<var>value</var> for <var>attribute</var>, with <a>this</a>.

<li><p>Set <var>attributeExists</var> to true if <a>this</a> <a lt="has an attribute">has an
attribute</a> <var>attribute</var>; otherwise false.

<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>value</var>.
<li><p>If <var>attributeExists</var> is true, <a lt="change an attribute">change</a>
<var>attribute</var> to <var>verifiedValue</var>.

<li><p>Otherwise:
<ol>
<li><p>Set <var>attribute</var>'s <a for=Attr>value</a> to <var>verifiedValue</var>.

<li><p><a lt="append an attribute">Append</a> this <a>attribute</a> to
<var>element</var>.
</ol>
</ol>

<p>The
Expand All @@ -6824,7 +6879,7 @@ method steps are:
passing <var>namespace</var> and <var>qualifiedName</var> to <a>validate and extract</a>.

<li><p><a>Set an attribute value</a> for <a>this</a> using <var>localName</var>, <var>value</var>,
and also <var>prefix</var> and <var>namespace</var>.
<var>prefix</var>, <var>namespace</var> and true.
</ol>

<p>The
Expand Down Expand Up @@ -7382,7 +7437,13 @@ string <var>value</var>, run these steps:
<li><p>If <var>attribute</var>'s <a for=Attr>element</a> is null, then set <var>attribute</var>'s
<a for=Attr>value</a> to <var>value</var>.

<li><p>Otherwise, <a lt="change an attribute">change</a> <var>attribute</var> to <var>value</var>.
<li><p>Otherwise:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers attr.nodeValue, attr.value, and attr.textContent.

<ol>
<li><p>Let <var>verifiedValue</var> be the result of calling <a>verify attribute value</a>
<var>value</var> for <var>attribute</var>, with <a>this</a>.

<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>verifiedValue</var>.
</ol>
</ol>

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