Skip to content

Commit 3819963

Browse files
authored
Revert "Change Script Enforcement Mechanism to use flags (#533)" (#565)
This reverts commit a71f29c.
1 parent f97dbe9 commit 3819963

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

spec/index.bs

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ 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
130132
type: dfn; text: get the text steps; url: get-the-text-steps
131133
type: dfn; text: set the inner text steps; url: set-the-inner-text-steps
132134
type: dfn; text: src; url: attr-script-src
@@ -1065,6 +1067,20 @@ Given a {{TrustedType}} type (|expectedType|), a [=realm/global object=] (|globa
10651067
1. Return a new instance of an interface with a type
10661068
name |trustedTypeName|, with its associated data value set to |dataString|.
10671069

1070+
## <dfn abstract-op>Prepare the script text</dfn> ## {#prepare-script-text}
1071+
1072+
Given an {{HTMLScriptElement}} (|script|), this algorithm performs the following steps:
1073+
1074+
1. If |script|'s [=script text=] value is not equal to its [=child text content=],
1075+
set |script|'s [=script text=] to the result of executing [$Get Trusted Type compliant string$], with the following arguments:
1076+
* {{TrustedScriptURL}} as |expectedType|,
1077+
* |script|'s {{Document}}'s [=relevant global object=] as |global|,
1078+
* |script|'s [=child text content=] attribute value,
1079+
* `HTMLScriptElement text` as |sink|,
1080+
* `'script'` as |sinkGroup|.
1081+
1082+
If the algorithm threw an error, rethrow the error.
1083+
10681084
## Get Trusted Types-compliant attribute value ## {#validate-attribute-mutation}
10691085
To <dfn abstract-op export>get Trusted Types-compliant attribute value</dfn> on {{Attr}} |attribute| with {{Element}} |element| and {{TrustedType}} or a string |newValue|, perform the following steps:
10701086

@@ -1155,17 +1171,12 @@ partial interface HTMLScriptElement {
11551171

11561172
#### Slots with trusted values #### {#slots-with-trusted-values}
11571173

1158-
An {{HTMLScriptElement}} and {{SVGScriptElement}} have:
1159-
1160-
: an associated boolean <dfn export for="HTMLScriptElement,SVGScriptElement">is trusted</dfn>.
1161-
:: A boolean indicating whether a script element is considered trustworthy for execution.
1162-
Initially true.
1163-
1164-
Note: This boolean is initially true so that parsed scripts are trusted.
1174+
This document modifies {{HTMLScriptElement}}s. Each script has:
11651175

1166-
: an associated boolean <dfn export for="HTMLScriptElement,SVGScriptElement">changed by trusted sink</dfn>.
1167-
:: A boolean indicating whether a script element has been modified by a trusted sink.
1168-
Initially false.
1176+
: an associated string <dfn export for="HTMLScriptElement">script text</dfn>.
1177+
:: A string, containing the body of the script to execute that was set
1178+
through a compliant sink. Equivalent to script's
1179+
[=child text content=]. Initially an empty string.
11691180

11701181
#### The {{HTMLScriptElement/innerText}} IDL attribute #### {#the-innerText-idl-attribute}
11711182

@@ -1174,7 +1185,7 @@ The {{HTMLScriptElement/innerText}} setter steps are:
11741185
1. Let |value| be the result of calling [$Get Trusted Type compliant string$] with
11751186
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement innerText`, and
11761187
`script`.
1177-
1. Set [=this=]'s [=HTMLScriptElement/changed by trusted sink=] to true.
1188+
1. Set [=this=]'s [=script text=] value to |value|.
11781189
1. Run [=set the inner text steps=] with [=this=] and |value|.
11791190

11801191
The {{HTMLScriptElement/innerText}} getter steps are:
@@ -1189,7 +1200,7 @@ empty string instead, and then do as described below:
11891200
1. Let |value| be the result of calling [$Get Trusted Type compliant string$] with
11901201
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement textContent`, and
11911202
`script`.
1192-
1. Set [=this=]'s [=HTMLScriptElement/changed by trusted sink=] to true.
1203+
1. Set [=this=]'s [=script text=] value to |value|.
11931204
1. Run [=set text content=] with [=this=] and |value|.
11941205

11951206
The {{HTMLScriptElement/textContent}} getter steps are:
@@ -1203,7 +1214,7 @@ Update the {{HTMLScriptElement/text}} setter steps algorithm as follows.
12031214
1. <ins>Let |value| be the result of calling [$Get Trusted Type compliant string$] with
12041215
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement text`, and
12051216
`script`.</ins>
1206-
1. Set [=this=]'s [=HTMLScriptElement/changed by trusted sink=] to true.
1217+
1. <ins>Set [=this=]'s [=script text=] value to the given value.</ins>
12071218
1. [=String replace all=] with the given value within [=this=].
12081219

12091220

@@ -1216,25 +1227,29 @@ The {{HTMLScriptElement/src}} setter steps are:
12161227
`script`.</ins>
12171228
1. <ins>Set [=this=]'s [=src=] content attribute to |value|.</ins>
12181229

1219-
#### Script children changed steps #### {#script-children-changed-steps}
1230+
#### Setting slot values from parser #### {#setting-slot-values-from-parser}
12201231

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

1223-
1. Set [=this=]'s [=HTMLScriptElement/is trusted=] to false.
1234+
Modify the [=The text insertion mode=] algorithm as follows:
12241235

1225-
1. If [=this=]'s [=HTMLScriptElement/changed by trusted sink=] is true, set [=this=]'s [=HTMLScriptElement/is trusted=] to true.
1236+
<dl class="switch">
1237+
<dt id="scriptEndTag">An end tag whose tag name is "script"</dt>
1238+
<dd>
1239+
<p>...</p>
12261240

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

1229-
Note: This relies on the children changed steps never being called by the parser.
1243+
<p>If the <span>active speculative HTML parser</span> is null, then <span>prepare the script
1244+
element</span> <var>script</var>. This might cause some script to execute, which might cause
1245+
<span data-x="dom-document-write">new characters to be inserted into the tokenizer</span>, and
1246+
might cause the tokenizer to output more tokens, resulting in a [=reentrant invocation of the parser=].</p>
12301247

1231-
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.
1248+
<p>...</p>
1249+
</dd>
1250+
</dl>
12321251

1233-
This document modifies the [=children changed steps=] for {{SVGScriptElement}} as follows:
1234-
1235-
1. Set [=this=]'s [=SVGScriptElement/is trusted=] to false.
1236-
1237-
Note: This relies on the children changed steps never being called by the parser.
1252+
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).
12381253

12391254
#### Slot value verification #### {#slot-value-verification}
12401255

@@ -1255,22 +1270,11 @@ The first few steps of the [=prepare the script element=] algorithm are modified
12551270
<p class=note>This is done so that if a parser-inserted <code id=script-processing-model:the-script-element-28><a href=https://html.spec.whatwg.org/#the-script-element>script</a></code> element fails to
12561271
run when the parser tries to run it, but it is later executed after a script dynamically
12571272
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>
1258-
1259-
<li><p>Let <var>source text</var> be <var>el</var>'s <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>.
1260-
1261-
<li><ins>
1262-
<p>If <var>el</var>'s [=HTMLScriptElement/is trusted=] is false:
1263-
<ol>
1264-
<li><p>Set <var>source text</var> to the result of executing [$Get Trusted Type compliant string$], with
1265-
{{TrustedScript}}, <var>el</var>'s [=relevant global object=], <var>source text</var>, `'HTMLScriptElement text'`,
1266-
and `'script'`.
1267-
<p>If that algorithm threw an error, then return.
1268-
</ol></ins>
1273+
<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>
1274+
<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>
12691275
<li>...
12701276
</ol>
12711277

1272-
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.
1273-
12741278
## Integration with DOM ## {#integration-with-dom}
12751279

12761280
Note: See [https://github.com/whatwg/dom/pull/1268](https://github.com/whatwg/dom/pull/1268) which upstreams this integration.

0 commit comments

Comments
 (0)