Skip to content

Commit 6da6326

Browse files
committed
Add script protection mechanisms to SVGScriptElement
1 parent a1862e5 commit 6da6326

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

spec/index.bs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ spec:ECMA-262; urlPrefix: https://tc39.github.io/ecma262/
122122
spec: HTML; urlPrefix: https://html.spec.whatwg.org/
123123
type: dfn; text: prepare the script element; url: prepare-the-script-element
124124
type: dfn; text: The text insertion mode; url: parsing-main-incdata
125+
type: dfn; text: The rules for parsing tokens in foreign content; url: parsing-main-inforeign
125126
type: dfn; text: reentrant invocation of the parser; url: nestedParsing
126127
type: dfn; text: get the text steps; url: get-the-text-steps
127128
type: dfn; text: set the inner text steps; url: set-the-inner-text-steps
@@ -1070,8 +1071,8 @@ Given a {{TrustedType}} type (|expectedType|), a [=realm/global object=] (|globa
10701071

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

1073-
1. If |script|'s [=script text=] value is not equal to its [=child text content=],
1074-
set |script|'s [=script text=] to the result of executing [$Get Trusted Type compliant string$], with the following arguments:
1074+
1. If |script|'s [=HTMLScriptElement/script text=] value is not equal to its [=child text content=],
1075+
set |script|'s [=HTMLScriptElement/script text=] to the result of executing [$Get Trusted Type compliant string$], with the following arguments:
10751076
* {{TrustedScriptURL}} as |expectedType|,
10761077
* |script|'s {{Document}}'s [=relevant global object=] as |global|,
10771078
* |script|'s [=child text content=] attribute value,
@@ -1177,14 +1178,21 @@ This document modifies {{HTMLScriptElement}}s. Each script has:
11771178
through a compliant sink. Equivalent to script's
11781179
[=child text content=]. Initially an empty string.
11791180

1181+
This document also modifies {{SVGScriptElement}}s. Each script has:
1182+
1183+
: an associated string <dfn export for="SVGScriptElement">script text</dfn>.
1184+
:: A string, containing the body of the script to execute that was set
1185+
through a compliant sink. Equivalent to script's
1186+
[=child text content=]. Initially an empty string.
1187+
11801188
#### The {{HTMLScriptElement/innerText}} IDL attribute #### {#the-innerText-idl-attribute}
11811189

11821190
The {{HTMLScriptElement/innerText}} setter steps are:
11831191

11841192
1. Let |value| be the result of calling [$Get Trusted Type compliant string$] with
11851193
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement innerText`, and
11861194
`script`.
1187-
1. Set [=this=]'s [=script text=] value to |value|.
1195+
1. Set [=this=]'s [=HTMLScriptElement/script text=] value to |value|.
11881196
1. Run [=set the inner text steps=] with [=this=] and |value|.
11891197

11901198
The {{HTMLScriptElement/innerText}} getter steps are:
@@ -1199,7 +1207,7 @@ empty string instead, and then do as described below:
11991207
1. Let |value| be the result of calling [$Get Trusted Type compliant string$] with
12001208
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement textContent`, and
12011209
`script`.
1202-
1. Set [=this=]'s [=script text=] value to |value|.
1210+
1. Set [=this=]'s [=HTMLScriptElement/script text=] value to |value|.
12031211
1. Run [=set text content=] with [=this=] and |value|.
12041212

12051213
The {{HTMLScriptElement/textContent}} getter steps are:
@@ -1213,7 +1221,7 @@ Update the {{HTMLScriptElement/text}} setter steps algorithm as follows.
12131221
1. <ins>Let |value| be the result of calling [$Get Trusted Type compliant string$] with
12141222
{{TrustedScript}}, [=this=]'s [=relevant global object=], the given value, `HTMLScriptElement text`, and
12151223
`script`.</ins>
1216-
1. <ins>Set [=this=]'s [=script text=] value to the given value.</ins>
1224+
1. <ins>Set [=this=]'s [=HTMLScriptElement/script text=] value to the given value.</ins>
12171225
1. [=String replace all=] with the given value within [=this=].
12181226

12191227

@@ -1228,7 +1236,7 @@ The {{HTMLScriptElement/src}} setter steps are:
12281236

12291237
#### Setting slot values from parser #### {#setting-slot-values-from-parser}
12301238

1231-
This document modifies the HTML parser to set the [=script text=] value when the script is created.
1239+
This document modifies the HTML parser to set the [=HTMLScriptElement/script text=] value when the script is created.
12321240

12331241
Modify the [=The text insertion mode=] algorithm as follows:
12341242

@@ -1237,7 +1245,7 @@ Modify the [=The text insertion mode=] algorithm as follows:
12371245
<dd>
12381246
<p>...</p>
12391247

1240-
<ins><p>Set <var>script</var>'s [=script text=] value to its [=child text content=].</p></ins>
1248+
<ins><p>Set <var>script</var>'s [=HTMLScriptElement/script text=] value to its [=child text content=].</p></ins>
12411249

12421250
<p>If the <span>active speculative HTML parser</span> is null, then <span>prepare the script
12431251
element</span> <var>script</var>. This might cause some script to execute, which might cause
@@ -1248,7 +1256,27 @@ Modify the [=The text insertion mode=] algorithm as follows:
12481256
</dd>
12491257
</dl>
12501258

1251-
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).
1259+
This document also modifies the HTML parser to set the [=SVGScriptElement/script text=] value when the script is created.
1260+
1261+
Modify the [=The rules for parsing tokens in foreign content=] as follows:
1262+
1263+
<dl class="switch">
1264+
<dt id="scriptForeignEndTag">An end tag whose tag name is "script", if the <span>current
1265+
node</span> is an <span>SVG <code>script</code></span> element</dt>
1266+
<dd>
1267+
<p>...</p>
1268+
1269+
<ins><p>Set <var>script</var>'s [=SVGScriptElement/script text=] value to its [=child text content=].</p></ins>
1270+
1271+
<p>If the <span>active speculative HTML parser</span> is null and the user agent supports SVG,
1272+
then <a href="https://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process the
1273+
SVG <code data-x="">script</code> element</a> according to the SVG rules.
1274+
1275+
<p>...</p>
1276+
</dd>
1277+
</dl>
1278+
1279+
Issue: The above algorithms don'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).
12521280

12531281
#### Slot value verification #### {#slot-value-verification}
12541282

@@ -1270,10 +1298,12 @@ The first few steps of the [=prepare the script element=] algorithm are modified
12701298
run when the parser tries to run it, but it is later executed after a script dynamically
12711299
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>
12721300
<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>
1273-
<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>
1301+
<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>
12741302
<li>...
12751303
</ol>
12761304

1305+
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.
1306+
12771307
### HostEnsureCanCompileStrings ### {#host-ensure-can-compile-strings}
12781308

12791309
JavaScript contains an <span>implementation-defined</span> <a href="https://tc39.es/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</a>(<var>realm</var>, <ins><var>parameterStrings</var>,

0 commit comments

Comments
 (0)