From 844456655493197e60e7657cc11f8dfcb505372f Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 28 May 2024 14:50:27 +0100 Subject: [PATCH] Add `trusted-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. --- index.bs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index 859bcb58a7..fdab8f5ce5 100644 --- a/index.bs +++ b/index.bs @@ -697,7 +697,7 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/ keyword-source = "'self'" / "'unsafe-inline'" / "'unsafe-eval'" / "'strict-dynamic'" / "'unsafe-hashes'" / / "'report-sample'" / "'unsafe-allow-redirects'" - / "'wasm-unsafe-eval'" + / "'wasm-unsafe-eval'" / "'trusted-eval'" ISSUE: Bikeshed `unsafe-allow-redirects`. @@ -1454,6 +1454,8 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/ 1. Let |sourceString| be |source|. + 1. Let |requireTrustedTypes| be `false`. + 1. Else: 1. Let |compilationSink| be `"Function"` if |compilationType| is `*FUNCTION*`, otherwise `"Eval"`. @@ -1503,9 +1505,17 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/ 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-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`". @@ -2781,8 +2791,8 @@ this algorithm returns normally if compilation is allowed, and throws a 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-eval`" + source expressions: * {{eval()}} * {{Function()}}