Skip to content

Commit 94aafa9

Browse files
committed
Upstream Trusted Types enforcement in EnsureCSPDoesNotBlockStringCompilation
- Also update the violation object resource definition.
1 parent 15443fe commit 94aafa9

1 file changed

Lines changed: 44 additions & 7 deletions

File tree

index.bs

Lines changed: 44 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,45 @@ 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*`, otherwise `"Eval"`.
1462+
1463+
1. Let |isTrusted| be `true`.
1464+
1465+
1. If |bodyArg| is not a {{TrustedScript}} object, set |isTrusted| to `false`.
1466+
1467+
1. If |isTrusted| is `true` then:
1468+
1469+
1. If |bodyString| is not equal to |bodyArg|'s [=TrustedScript/data=], set |isTrusted| to `false`.
1470+
1471+
1. If |isTrusted| is `true`, then:
1472+
1473+
1. For each |arg| in |parameterArgs|:
1474+
1475+
1. Let |index| be the index of |arg| in |parameterArgs|.
1476+
1477+
1. If |arg| is not a {{TrustedScript}} object, set |isTrusted| to `false`.
1478+
1479+
1. If |isTrusted| is `true`, then:
1480+
1481+
1. if |parameterStrings|[|index|] is not equal to |arg|'s [=TrustedScript/data=], set |isTrusted| to `false`.
1482+
1483+
1. If |isTrusted| is `true`, let |sourceToValidate| be a new instance of
1484+
the {{TrustedScript}} interface, with its [=TrustedScript/data=]
1485+
set to |codeString|. Otherwise, let |sourceToValidate| be |codeString|.
1486+
1487+
1. Let |sourceString| be the result of executing the [$Get Trusted Type compliant string$] algorithm, with
1488+
{{TrustedScript}}, |realm|, |sourceToValidate|, |compilationSink|, and `'script'`.
1489+
1490+
1. If the algorithm throws an error, throw an {{EvalError}}.
1491+
1492+
1. If |sourceString| is not equal to |codeString|, throw an {{EvalError}}.
1493+
14551494
1. Let |result| be "`Allowed`".
14561495

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

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

14821521
4. Execute [[#report-violation]] on |violation|.
14831522

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

14871526
4. If |result| is "`Blocked`", throw an `EvalError` exception.
14881527

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

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

36943731
3. If |directive|'s <a for="directive">value</a> contains
36953732
"<a grammar>`'strict-dynamic'`</a>":
3696-
3733+
36973734
1. If |request|'s <a for="request">parser metadata</a> is not
36983735
<a>"parser-inserted"</a>, return "`Allowed`".
3699-
3736+
37003737
Otherwise, return "`Blocked`".
37013738

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

0 commit comments

Comments
 (0)