From affe7a7d41712fda84498d60f3bd8ef29fb1be29 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Wed, 15 Jan 2025 18:11:33 +0000 Subject: [PATCH] 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. --- index.bs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/index.bs b/index.bs index 3808b5b67e..32b4dc62ff 100644 --- a/index.bs +++ b/index.bs @@ -490,7 +490,7 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
    1. If |serialized| is a [=byte sequence=], then set |serialized| to be the result of [=isomorphic decoding=] |serialized|. - + 2. Let |policy| be a new [=/policy=] with an empty [=policy/directive set=], a [=policy/source=] of |source|, and a [=policy/disposition=] of |disposition|. @@ -693,8 +693,9 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity keyword-source = "'self'" / "'unsafe-inline'" / "'unsafe-eval'" / "'strict-dynamic'" / "'unsafe-hashes'" / "'report-sample'" / "'unsafe-allow-redirects'" - / "'wasm-unsafe-eval'" / "'report-sha256'" - / "'report-sha384'" / "'report-sha512'" + / "'wasm-unsafe-eval'" / "'trusted-types-eval'" + / "'report-sha256'" / "'report-sha384'" + / "'report-sha512'" ISSUE: Bikeshed `unsafe-allow-redirects`. @@ -1539,9 +1540,17 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity Otherwise if |policy| contains a [=directive=] whose [=directive/name=] is "`default-src`", then set |source-list| to that directive's [=directive/value=]. - 3. If |source-list| is not null, and does not contain a [=source expression=] which is - an [=ASCII case-insensitive=] match for the string "`'unsafe-eval'`", - then: + 1. If |source-list| is not null: + + 1. Let |trustedTypesRequired| be the result of executing [$Does sink type require trusted types?$], with + |realm|, `'script'`, and `false`. + + 1. If |trustedTypesRequired| is `true` and |source-list| contains a [=source expression=] which is an + [=ASCII case-insensitive=] match for the string "`'trusted-types-eval'`", then skip the + following steps. + + 1. If |source-list| contains a [=source expression=] which is an [=ASCII case-insensitive=] match for the + string "`'unsafe-eval'`", then skip the following steps. 1. Let |violation| be the result of executing [[#create-violation-for-global]] on |global|, |policy|, and "`script-src`". @@ -2861,8 +2870,8 @@ Content-Type: application/reports+json nonce-source or a hash-source that matches the inline block. - 4. The following JavaScript execution sinks are gated on the "`unsafe-eval`" - source expression: + 4. The following JavaScript execution sinks are gated on the "`unsafe-eval`" and "`trusted-types-eval`" + source expressions: * {{eval()}} * {{Function()}}