Skip to content

Commit ce17e10

Browse files
authored
Upstream Trusted Types enforcement in EnsureCSPDoesNotBlockStringCompilation (#659)
* Upstream Trusted Types enforcement in EnsureCSPDoesNotBlockStringCompilation - Also update the violation object resource definition.
1 parent d768218 commit ce17e10

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

index.bs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/
751751

752752
Each <a>violation</a> has a
753753
<dfn for="violation" id="violation-resource" export>resource</dfn>, which is
754-
either null, "`inline`", "`eval`", "`wasm-eval`", or a {{URL}}. It represents the resource
755-
which violated the policy.
754+
either null, "`inline`", "`eval`", "`wasm-eval`", "`trusted-types-policy`", "`trusted-types-sink`" or a {{URL}}.
755+
It represents the resource which violated the policy.
756756

757757
Note: The value null for a <a>violation</a>'s <a
758758
for="violation">resource</a> is only allowed while the <a>violation</a> is
@@ -1452,6 +1452,44 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/
14521452
returns normally if string compilation is allowed, and throws an "`EvalError`"
14531453
if not:
14541454

1455+
1. If |compilationType| is "`TIMER`", then:
1456+
1457+
1. Let |sourceString| be |codeString|.
1458+
1459+
1. Else:
1460+
1461+
1. Let |compilationSink| be "Function" if |compilationType| is "`FUNCTION`", and "Eval" otherwise.
1462+
1463+
1. Let |isTrusted| be `true` if |bodyArg| [=implements=] {{TrustedScript}}, and `false` otherwise.
1464+
1465+
1. If |isTrusted| is `true` then:
1466+
1467+
1. If |bodyString| is not equal to |bodyArg|'s [=TrustedScript/data=], set |isTrusted| to `false`.
1468+
1469+
1. If |isTrusted| is `true`, then:
1470+
1471+
1. Assert: |parameterArgs|' [list/size=] is equal to [parameterStrings]' [=list/size=].
1472+
1473+
1. [=list/iterate|For each=] |index| of [=the range=] 0 to |parameterArgs]' [list/size=]:
1474+
1. Let |arg| be |parameterArgs|[|index|].
1475+
1476+
1. If |arg| [=implements=] {{TrustedScript}}, then:
1477+
1478+
1. if |parameterStrings|[|index|] is not equal to |arg|'s [=TrustedScript/data=], set |isTrusted| to `false`.
1479+
1480+
1. Otherwise, set |isTrusted| to `false`.
1481+
1482+
1. Let |sourceToValidate| be a [=new=] {{TrustedScript}} object created in |realm|
1483+
whose [=TrustedScript/data=] is set to |codeString| if |isTrusted| is `true`, and
1484+
|codeString| otherwise.
1485+
1486+
1. Let |sourceString| be the result of executing the [$Get Trusted Type compliant string$] algorithm, with
1487+
{{TrustedScript}}, |realm|, |sourceToValidate|, |compilationSink|, and `'script'`.
1488+
1489+
1. If the algorithm throws an error, throw an {{EvalError}}.
1490+
1491+
1. If |sourceString| is not equal to |codeString|, throw an {{EvalError}}.
1492+
14551493
1. Let |result| be "`Allowed`".
14561494

14571495
2. Let |global| be |realm|'s [=realm/global object=].
@@ -1477,7 +1515,7 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/
14771515

14781516
3. If |source-list| [=list/contains=] the expression
14791517
"<a grammar>`'report-sample'`</a>", then set |violation|'s [=violation/sample=] to
1480-
the substring of |codeString| containing its first 40 characters.
1518+
the substring of |sourceString| containing its first 40 characters.
14811519

14821520
4. Execute [[#report-violation]] on |violation|.
14831521

@@ -1486,8 +1524,6 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/
14861524

14871525
4. If |result| is "`Blocked`", throw an `EvalError` exception.
14881526

1489-
Note: |parameterStrings|, |bodyString|, |compilationType|, |parameterArgs|, and |bodyArg| are currently unused. They are included for future use.
1490-
14911527
<h3 id="wasm-integration">Integration with WebAssembly</h3>
14921528

14931529
WebAssembly defines the {{HostEnsureCanCompileWasmBytes()}} abstract operation
@@ -3693,10 +3729,10 @@ this algorithm returns normally if compilation is allowed, and throws a
36933729

36943730
3. If |directive|'s <a for="directive">value</a> contains
36953731
"<a grammar>`'strict-dynamic'`</a>":
3696-
3732+
36973733
1. If |request|'s <a for="request">parser metadata</a> is not
36983734
<a>"parser-inserted"</a>, return "`Allowed`".
3699-
3735+
37003736
Otherwise, return "`Blocked`".
37013737

37023738
4. If the result of executing [[#match-response-to-source-list]] on

0 commit comments

Comments
 (0)