Skip to content

Commit 0c7d33e

Browse files
committed
Change Script Enforcement Mechanism to use flags
Also add SVGScriptElement to spec
1 parent cf78f7e commit 0c7d33e

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

spec/index.bs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ spec:ECMA-262; urlPrefix: https://tc39.github.io/ecma262/
127127
type:dfn; text:current realm record; url: current-realm
128128
spec: HTML; urlPrefix: https://html.spec.whatwg.org/
129129
type: dfn; text: prepare the script element; url: prepare-the-script-element
130-
type: dfn; text: The text insertion mode; url: parsing-main-incdata
131-
type: dfn; text: reentrant invocation of the parser; url: nestedParsing
132130
type: dfn; text: get the text steps; url: get-the-text-steps
133131
type: dfn; text: set the inner text steps; url: set-the-inner-text-steps
134132
type: dfn; text: src; url: attr-script-src
@@ -1077,8 +1075,8 @@ Given a {{TrustedType}} type (|expectedType|), a [=realm/global object=] (|globa
10771075

10781076
Given an {{HTMLScriptElement}} (|script|), this algorithm performs the following steps:
10791077

1080-
1. If |script|'s [=script text=] value is not equal to its [=child text content=],
1081-
set |script|'s [=script text=] to the result of executing [$Get Trusted Type compliant string$], with the following arguments:
1078+
1. If |script|'s [=HTMLScriptElement/is trusted=] is false,
1079+
set |script|'s [=HTMLScriptElement/script text=] to the result of executing [$Get Trusted Type compliant string$], with the following arguments:
10821080
* {{TrustedScriptURL}} as |expectedType|,
10831081
* |script|'s {{Document}}'s [=relevant global object=] as |global|,
10841082
* |script|'s [=child text content=] attribute value,
@@ -1179,10 +1177,19 @@ partial interface HTMLScriptElement {
11791177

11801178
This document modifies {{HTMLScriptElement}}s. Each script has:
11811179

1182-
: an associated string <dfn export for="HTMLScriptElement">script text</dfn>.
1183-
:: A string, containing the body of the script to execute that was set
1184-
through a compliant sink. Equivalent to script's
1185-
[=child text content=]. Initially an empty string.
1180+
: an associated boolean <dfn export for="HTMLScriptElement">is trusted</dfn>.
1181+
:: A boolean indicating whether a script element is considered trustworthy for execution.
1182+
Initially true.
1183+
1184+
: an associated boolean <dfn export for="HTMLScriptElement">changed by trusted sink</dfn>.
1185+
:: A boolean indicating whether a script element has been modified by a trusted sink.
1186+
Initially false.
1187+
1188+
This document also modifies {{SVGScriptElement}}s. Each script has:
1189+
1190+
: an associated boolean <dfn export for="SVGScriptElement">is trusted</dfn>.
1191+
:: A boolean indicating whether a script element is considered trustworthy for execution.
1192+
Initially true.
11861193

11871194
#### The {{HTMLScriptElement/innerText}} IDL attribute #### {#the-innerText-idl-attribute}
11881195

@@ -1191,7 +1198,7 @@ The {{HTMLScriptElement/innerText}} setter steps are:
11911198
1. Let |value| be the result of calling [$Get Trusted Type compliant string$] with
11921199
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement innerText`, and
11931200
`script`.
1194-
1. Set [=this=]'s [=script text=] value to |value|.
1201+
1. Set [=this=]'s [=HTMLScriptElement/changed by trusted sink=] to true.
11951202
1. Run [=set the inner text steps=] with [=this=] and |value|.
11961203

11971204
The {{HTMLScriptElement/innerText}} getter steps are:
@@ -1206,8 +1213,8 @@ empty string instead, and then do as described below:
12061213
1. Let |value| be the result of calling [$Get Trusted Type compliant string$] with
12071214
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement textContent`, and
12081215
`script`.
1209-
1. Set [=this=]'s [=script text=] value to |value|.
12101216
1. Run [=set text content=] with [=this=] and |value|.
1217+
1. Set [=this=]'s [=HTMLScriptElement/changed by trusted sink=] to true.
12111218

12121219
The {{HTMLScriptElement/textContent}} getter steps are:
12131220

@@ -1220,8 +1227,8 @@ Update the {{HTMLScriptElement/text}} setter steps algorithm as follows.
12201227
1. <ins>Let |value| be the result of calling [$Get Trusted Type compliant string$] with
12211228
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement text`, and
12221229
`script`.</ins>
1223-
1. <ins>Set [=this=]'s [=script text=] value to the given value.</ins>
12241230
1. [=String replace all=] with the given value within [=this=].
1231+
1. Set [=this=]'s [=HTMLScriptElement/changed by trusted sink=] to true.
12251232

12261233

12271234
#### The {{HTMLScriptElement/src}} IDL attribute #### {#the-src-idl-attribute}
@@ -1233,29 +1240,21 @@ The {{HTMLScriptElement/src}} setter steps are:
12331240
`script`.</ins>
12341241
1. <ins>Set [=this=]'s [=src=] content attribute to |value|.</ins>
12351242

1236-
#### Setting slot values from parser #### {#setting-slot-values-from-parser}
1243+
#### Script children changed steps #### {#script-children-changed-steps}
12371244

1238-
This document modifies the HTML parser to set the [=script text=] value when the script is created.
1245+
This document modifies the [=children changed steps=] for {{HTMLScriptElement}} as follows:
12391246

1240-
Modify the [=The text insertion mode=] algorithm as follows:
1247+
1. If <var ignore=''>parserChange</var> is false, set [=this=]'s [=HTMLScriptElement/is trusted=] to false.
12411248

1242-
<dl class="switch">
1243-
<dt id="scriptEndTag">An end tag whose tag name is "script"</dt>
1244-
<dd>
1245-
<p>...</p>
1249+
1. If [=this=]'s [=HTMLScriptElement/changed by trusted sink=] is true, set [=this=]'s [=HTMLScriptElement/is trusted=] to false.
12461250

1247-
<ins><p>Set <var>script</var>'s [=script text=] value to its [=child text content=].</p></ins>
1251+
1. Set [=this=]'s [=HTMLScriptElement/changed by trusted sink=] to false.
12481252

1249-
<p>If the <span>active speculative HTML parser</span> is null, then <span>prepare the script
1250-
element</span> <var>script</var>. This might cause some script to execute, which might cause
1251-
<span data-x="dom-document-write">new characters to be inserted into the tokenizer</span>, and
1252-
might cause the tokenizer to output more tokens, resulting in a [=reentrant invocation of the parser=].</p>
1253+
Issue: Need to double check how [part of script element's spec](https://html.spec.whatwg.org/#prepare-the-script-element:~:text=When%20a%20script%20element%20el%20that%20is%20not%20parser%2Dinserted%20experiences) fits into this. These steps need to happen before prepare the script is called.
12531254

1254-
<p>...</p>
1255-
</dd>
1256-
</dl>
1255+
This document modifies the [=children changed steps=] for {{SVGScriptElement}} as follows:
12571256

1258-
Issue: The above algorithm doesn't account for the case when the script element's content is changed mid-parse. Implementors should ensure they protect against this case. See [https://github.com/w3c/trusted-types/issues/507](https://github.com/w3c/trusted-types/issues/507).
1257+
1. If <var ignore=''>parserChange</var> is false, set [=this=]'s [=SVGScriptElement/is trusted=] to false.
12591258

12601259
#### Slot value verification #### {#slot-value-verification}
12611260

@@ -1277,10 +1276,12 @@ The first few steps of the [=prepare the script element=] algorithm are modified
12771276
run when the parser tries to run it, but it is later executed after a script dynamically
12781277
updates it, it will execute in an async fashion even if the <code id=script-processing-model:attr-script-async-5><a href=https://html.spec.whatwg.org/#attr-script-async>async</a></code> attribute isn't set.</p>
12791278
<li><ins><p>Execute the [$Prepare the script text$] algorithm on <var>el</var>. If that algorithm threw an error, then return.</p></ins></li>
1280-
<li><p>Let <var ignore="">source text</var> be <var>el</var>'s <del><a id=script-processing-model:child-text-content href=https://dom.spec.whatwg.org/#concept-child-text-content data-x-internal=child-text-content>child text content</a>.</del> <ins>[=script text=] value.</ins>
1279+
<li><p>Let <var ignore="">source text</var> be <var>el</var>'s <del><a id=script-processing-model:child-text-content href=https://dom.spec.whatwg.org/#concept-child-text-content data-x-internal=child-text-content>child text content</a>.</del> <ins>[=HTMLScriptElement/script text=] value.</ins>
12811280
<li>...
12821281
</ol>
12831282

1283+
Issue: There's no proper definition for the processing of SVG script elements. However, you should apply a similar change to the processing of {{SVGScriptElement}}s.
1284+
12841285
## Integration with DOM ## {#integration-with-dom}
12851286

12861287
Note: See [https://github.com/whatwg/dom/pull/1258](https://github.com/whatwg/dom/pull/1258) and [https://github.com/whatwg/dom/pull/1268](https://github.com/whatwg/dom/pull/1268) which upstream this integration.

0 commit comments

Comments
 (0)