Skip to content

Commit b6e3a19

Browse files
committed
Add trusted-types-eval source expression for script-src
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 b6e3a19

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

index.bs

Lines changed: 19 additions & 8 deletions
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

@@ -1491,6 +1492,8 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
14911492

14921493
1. Let |sourceString| be |codeString|.
14931494

1495+
1. Let |requireTrustedTypes| be `false`.
1496+
14941497
1. Else:
14951498

14961499
1. Let |compilationSink| be "Function" if |compilationType| is "`FUNCTION`", and "eval" otherwise.
@@ -1539,9 +1542,17 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
15391542
Otherwise if |policy| contains a [=directive=] whose [=directive/name=] is
15401543
"`default-src`", then set |source-list| to that directive's [=directive/value=].
15411544

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

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

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

28672878
* {{eval()}}
28682879
* {{Function()}}

0 commit comments

Comments
 (0)