Skip to content

Commit

Permalink
Upstream Trusted Types enforcement in EnsureCSPDoesNotBlockStringComp…
Browse files Browse the repository at this point in the history
…ilation
  • Loading branch information
lukewarlow committed May 14, 2024
1 parent e0e7778 commit 1685c24
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,45 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/
returns normally if string compilation is allowed, and throws an "`EvalError`"
if not:

1. If |compilationType| is `*TIMER*`, then:

1. Let |sourceString| be |source|.

1. Else:

1. Let |compilationSink| be `"Function"` if |compilationType| is `*FUNCTION*`, otherwise `"Eval"`.

1. Let |isTrusted| be `true`.

1. If |bodyArg| is not a {{TrustedScript}} object, set |isTrusted| to `false`.

1. If |isTrusted| is `true` then:

1. If |bodyString| is not equal to |bodyArg|'s [=TrustedScript/data=], set |isTrusted| to `false`.

1. If |isTrusted| is `true`, then:

1. For each |arg| in |parameterArgs|:

1. Let |index| be the index of |arg| in |parameterArgs|.

1. If |arg| is not a {{TrustedScript}} object, set |isTrusted| to `false`.

1. If |isTrusted| is `true`, then:

1. if |parameterStrings|[|index|] is not equal to |arg|'s [=TrustedScript/data=], set |isTrusted| to `false`.

1. If |isTrusted| is `true`, let |sourceToValidate| be a new instance of
the {{TrustedScript}} interface, with its [=TrustedScript/data=]
set to |source|. Otherwise, let |sourceToValidate| be |source|.

1. Let |sourceString| be the result of executing the [$Get Trusted Type compliant string$] algorithm, with
{{TrustedScript}}, |realm|, |sourceToValidate|, |compilationSink|, and `'script'`.

1. If the algorithm throws an error, throw an {{EvalError}}.

1. If |sourceString| is not equal to |source|, throw an {{EvalError}}.

1. Let |result| be "`Allowed`".

2. Let |global| be |realm|'s [=realm/global object=].
Expand All @@ -1475,7 +1514,7 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/

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

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

Expand All @@ -1484,8 +1523,6 @@ spec: WebRTC; urlPrefix: https://www.w3.org/TR/webrtc/

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

Note: |parameterStrings|, |parameterArgs|, |bodyArg| and |bodyString| are currently unused. They are included for future use.

<h3 id="wasm-integration">Integration with WebAssembly</h3>

WebAssembly defines the {{HostEnsureCanCompileWasmBytes()}} abstract operation
Expand Down

0 comments on commit 1685c24

Please sign in to comment.