Skip to content

Commit affe7a7

Browse files
authored
Add trusted-types-eval source expression for script-src (#665)
This new keyword allows enabling eval only when trusted types are enforced. Such that in browsers that don't support trusted types no eval is allowed.
1 parent 268bdff commit affe7a7

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

index.bs

+17-8
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
490490
<ol class="algorithm">
491491
1. If |serialized| is a [=byte sequence=], then set |serialized| to be the result of
492492
[=isomorphic decoding=] |serialized|.
493-
493+
494494
2. Let |policy| be a new [=/policy=] with an empty [=policy/directive set=], a [=policy/source=]
495495
of |source|, and a [=policy/disposition=] of |disposition|.
496496

@@ -693,8 +693,9 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
693693
<dfn>keyword-source</dfn> = "<dfn>'self'</dfn>" / "<dfn>'unsafe-inline'</dfn>" / "<dfn>'unsafe-eval'</dfn>"
694694
/ "<dfn>'strict-dynamic'</dfn>" / "<dfn>'unsafe-hashes'</dfn>"
695695
/ "<dfn>'report-sample'</dfn>" / "<dfn>'unsafe-allow-redirects'</dfn>"
696-
/ "<dfn>'wasm-unsafe-eval'</dfn>" / "<dfn>'report-sha256'</dfn>"
697-
/ "<dfn>'report-sha384'</dfn>" / "<dfn>'report-sha512'</dfn>"
696+
/ "<dfn>'wasm-unsafe-eval'</dfn>" / "<dfn>'trusted-types-eval'</dfn>"
697+
/ "<dfn>'report-sha256'</dfn>" / "<dfn>'report-sha384'</dfn>"
698+
/ "<dfn>'report-sha512'</dfn>"
698699

699700
ISSUE: Bikeshed `unsafe-allow-redirects`.
700701

@@ -1539,9 +1540,17 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
15391540
Otherwise if |policy| contains a [=directive=] whose [=directive/name=] is
15401541
"`default-src`", then set |source-list| to that directive's [=directive/value=].
15411542

1542-
3. If |source-list| is not null, and does not contain a [=source expression=] which is
1543-
an [=ASCII case-insensitive=] match for the string "<a grammar>`'unsafe-eval'`</a>",
1544-
then:
1543+
1. If |source-list| is not null:
1544+
1545+
1. Let |trustedTypesRequired| be the result of executing [$Does sink type require trusted types?$], with
1546+
|realm|, `'script'`, and `false`.
1547+
1548+
1. If |trustedTypesRequired| is `true` and |source-list| contains a [=source expression=] which is an
1549+
[=ASCII case-insensitive=] match for the string "<a grammar>`'trusted-types-eval'`</a>", then skip the
1550+
following steps.
1551+
1552+
1. If |source-list| contains a [=source expression=] which is an [=ASCII case-insensitive=] match for the
1553+
string "<a grammar>`'unsafe-eval'`</a>", then skip the following steps.
15451554

15461555
1. Let |violation| be the result of executing [[#create-violation-for-global]] on
15471556
|global|, |policy|, and "`script-src`".
@@ -2861,8 +2870,8 @@ Content-Type: application/reports+json
28612870
<a grammar>nonce-source</a> or a <a grammar>hash-source</a> that matches
28622871
the inline block.
28632872

2864-
4. The following JavaScript execution sinks are gated on the "`unsafe-eval`"
2865-
source expression:
2873+
4. The following JavaScript execution sinks are gated on the "`unsafe-eval`" and "`trusted-types-eval`"
2874+
source expressions:
28662875

28672876
* {{eval()}}
28682877
* {{Function()}}

0 commit comments

Comments
 (0)