Skip to content

Commit 766d36f

Browse files
authored
Added support for 'trusted-types *' to align better with other CSP directives. (#267)
"trusted-types *" does not imply 'allow-duplicates'.`
1 parent aaf9b74 commit 766d36f

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

dist/spec/index.html

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@
12141214
</style>
12151215
<meta content="Bikeshed version 0dd2bba6dfda6c3168490a3a3044dd1d0b1ef8e0" name="generator">
12161216
<link href="https://w3c.github.io/webappsec-trusted-types/dist/spec/" rel="canonical">
1217-
<meta content="db82179c1fb92cb256cb3bf32886480e4b23cb17" name="document-revision">
1217+
<meta content="aaf9b745a15eb5952b7fbcada1d917f2788241fb" name="document-revision">
12181218
<style>/* style-md-lists */
12191219

12201220
/* This is a weird hack for me not yet following the commonmark spec
@@ -1461,7 +1461,7 @@
14611461
<div class="head">
14621462
<p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
14631463
<h1 class="p-name no-ref" id="title">Trusted Types</h1>
1464-
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2020-03-09">9 March 2020</time></span></h2>
1464+
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2020-03-11">11 March 2020</time></span></h2>
14651465
<div data-fill-with="spec-metadata">
14661466
<dl>
14671467
<dt>This version:
@@ -3101,7 +3101,8 @@ <h4 class="heading settled" data-level="4.5.2" id="trusted-types-csp-directive">
31013101
<pre>directive-name = "trusted-types"
31023102
directive-value = <a data-link-type="dfn" href="#serialized-tt-configuration" id="ref-for-serialized-tt-configuration">serialized-tt-configuration</a>
31033103
<dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="serialized-tt-configuration">serialized-tt-configuration</dfn> = ( <a data-link-type="dfn" href="#tt-expression" id="ref-for-tt-expression">tt-expression</a> *( <a href="https://w3c.github.io/webappsec-csp/#grammardef-required-ascii-whitespace">required-ascii-whitespace</a> <a data-link-type="dfn" href="#tt-expression" id="ref-for-tt-expression①">tt-expression</a> ) )
3104-
<dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="tt-expression">tt-expression</dfn> = <a data-link-type="dfn" href="#tt-policy-name" id="ref-for-tt-policy-name">tt-policy-name</a> / <a data-link-type="dfn" href="#tt-keyword" id="ref-for-tt-keyword">tt-keyword</a>
3104+
<dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="tt-expression">tt-expression</dfn> = <a data-link-type="dfn" href="#tt-policy-name" id="ref-for-tt-policy-name">tt-policy-name</a> / <a data-link-type="dfn" href="#tt-keyword" id="ref-for-tt-keyword">tt-keyword</a> / <a data-link-type="dfn" href="#tt-wildcard" id="ref-for-tt-wildcard">tt-wildcard</a>
3105+
<dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="tt-wildcard">tt-wildcard</dfn> = "*"
31053106
<dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="tt-policy-name">tt-policy-name</dfn> = 1*( <a href="https://tools.ietf.org/html/rfc5234#appendix-B.1">ALPHA</a> / <a href="https://tools.ietf.org/html/rfc5234#appendix-B.1">DIGIT</a> / "-" / "#" / "=" / "_" / "/" / "@" / "." / "%")
31063107
<dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="tt-keyword">tt-keyword</dfn> = "'allow-duplicates'"
31073108
</pre>
@@ -3186,7 +3187,8 @@ <h4 class="heading settled" data-level="4.5.4" id="should-block-create-policy"><
31863187
duplicated names.</p>
31873188
<li data-md>
31883189
<p>If <var>directive</var>’s <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-value" id="ref-for-directive-value⑤">value</a> does not contain a <a data-link-type="dfn" href="#tt-policy-name" id="ref-for-tt-policy-name①">tt-policy-name</a>,
3189-
which value is <var>policyName</var>, set <var>createViolation</var> to true.</p>
3190+
which value is <var>policyName</var>, and <var>directive</var>’s <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-value" id="ref-for-directive-value⑥">value</a> does not contain a <a data-link-type="dfn" href="#tt-wildcard" id="ref-for-tt-wildcard①">tt-wildcard</a>, set <var>createViolation</var> to true.</p>
3191+
<p class="note" role="note"><span>Note:</span> <code>trusted-types *</code> allows authors to create policies with any unique names. To allow for multiple policies with the same name, use <code>trusted-types * 'allow-duplicates'</code> or don’t set the <code>trusted-types</code> directive at all.</p>
31903192
<li data-md>
31913193
<p>If <var>createViolation</var> is false, skip to the next <var>policy</var>.</p>
31923194
<li data-md>
@@ -3266,9 +3268,9 @@ <h4 class="heading settled" data-level="4.5.6" id="csp-eval"><span class="secno"
32663268
<p>Let <var>source-list</var> be <code>null</code>.</p>
32673269
<li data-md>
32683270
<p>If <var>policy</var> contains a <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directives" id="ref-for-directives⑧">directive</a> whose <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-name" id="ref-for-directive-name③">name</a> is "<code>script-src</code>", then
3269-
set <var>source-list</var> to that <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directives" id="ref-for-directives⑨">directive</a>'s <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-value" id="ref-for-directive-value">value</a>.</p>
3271+
set <var>source-list</var> to that <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directives" id="ref-for-directives⑨">directive</a>'s <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-value" id="ref-for-directive-value">value</a>.</p>
32703272
<p>Otherwise if <var>policy</var> contains a <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directives" id="ref-for-directives①⓪">directive</a> whose <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-name" id="ref-for-directive-name④">name</a> is
3271-
"<code>default-src</code>", then set <var>source-list</var> to that directive’s <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-value" id="ref-for-directive-value">value</a>.</p>
3273+
"<code>default-src</code>", then set <var>source-list</var> to that directive’s <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-value" id="ref-for-directive-value">value</a>.</p>
32723274
<li data-md>
32733275
<p>If <var>source-list</var> is not <code>null</code>, and does not contain a <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#source-expression" id="ref-for-source-expression">source expression</a> which is
32743276
an <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#ascii-case-insensitive" id="ref-for-ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<a data-link-type="grammar" href="https://w3c.github.io/webappsec-csp/#grammardef-unsafe-eval" id="ref-for-grammardef-unsafe-eval"><code>'unsafe-eval'</code></a>" then:</p>
@@ -3539,6 +3541,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
35393541
<li><a href="#tt-expression">tt-expression</a><span>, in §4.5.2</span>
35403542
<li><a href="#tt-keyword">tt-keyword</a><span>, in §4.5.2</span>
35413543
<li><a href="#tt-policy-name">tt-policy-name</a><span>, in §4.5.2</span>
3544+
<li><a href="#tt-wildcard">tt-wildcard</a><span>, in §4.5.2</span>
35423545
<li><a href="#dom-document-write">write()</a><span>, in §4.1.2</span>
35433546
<li><a href="#dom-document-writeln">writeln()</a><span>, in §4.1.2</span>
35443547
<li><a href="#dom-document-writeln">writeln(...text)</a><span>, in §4.1.2</span>
@@ -3657,8 +3660,8 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
36573660
<li><a href="#ref-for-directive-value">4.5.1. require-trusted-types-for directive</a>
36583661
<li><a href="#ref-for-directive-value①">4.5.2. trusted-types directive</a> <a href="#ref-for-directive-value②">(2)</a>
36593662
<li><a href="#ref-for-directive-value③">4.5.3. Should sink type mismatch violation be blocked by Content Security Policy?</a>
3660-
<li><a href="#ref-for-directive-value④">4.5.4. Should Trusted Type policy creation be blocked by Content Security Policy?</a> <a href="#ref-for-directive-value⑤">(2)</a>
3661-
<li><a href="#ref-for-directive-value">4.5.6. Support for eval(TrustedScript)</a> <a href="#ref-for-directive-value">(2)</a>
3663+
<li><a href="#ref-for-directive-value④">4.5.4. Should Trusted Type policy creation be blocked by Content Security Policy?</a> <a href="#ref-for-directive-value⑤">(2)</a> <a href="#ref-for-directive-value⑥">(3)</a>
3664+
<li><a href="#ref-for-directive-value">4.5.6. Support for eval(TrustedScript)</a> <a href="#ref-for-directive-value">(2)</a>
36623665
</ul>
36633666
</aside>
36643667
<aside class="dfn-panel" data-for="term-for-violation">
@@ -4864,6 +4867,13 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
48644867
<li><a href="#ref-for-tt-expression">4.5.2. trusted-types directive</a> <a href="#ref-for-tt-expression①">(2)</a>
48654868
</ul>
48664869
</aside>
4870+
<aside class="dfn-panel" data-for="tt-wildcard">
4871+
<b><a href="#tt-wildcard">#tt-wildcard</a></b><b>Referenced in:</b>
4872+
<ul>
4873+
<li><a href="#ref-for-tt-wildcard">4.5.2. trusted-types directive</a>
4874+
<li><a href="#ref-for-tt-wildcard①">4.5.4. Should Trusted Type policy creation be blocked by Content Security Policy?</a>
4875+
</ul>
4876+
</aside>
48674877
<aside class="dfn-panel" data-for="tt-policy-name">
48684878
<b><a href="#tt-policy-name">#tt-policy-name</a></b><b>Referenced in:</b>
48694879
<ul>

spec/index.bs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,8 @@ ABNF:
16501650
directive-name = "trusted-types"
16511651
directive-value = <a>serialized-tt-configuration</a>
16521652
<dfn>serialized-tt-configuration</dfn> = ( <a>tt-expression</a> *( <a href="https://w3c.github.io/webappsec-csp/#grammardef-required-ascii-whitespace">required-ascii-whitespace</a> <a>tt-expression</a> ) )
1653-
<dfn>tt-expression</dfn> = <a>tt-policy-name</a> / <a>tt-keyword</a>
1653+
<dfn>tt-expression</dfn> = <a>tt-policy-name</a> / <a>tt-keyword</a> / <a>tt-wildcard</a>
1654+
<dfn>tt-wildcard</dfn> = "*"
16541655
<dfn>tt-policy-name</dfn> = 1*( <a href="https://tools.ietf.org/html/rfc5234#appendix-B.1">ALPHA</a> / <a href="https://tools.ietf.org/html/rfc5234#appendix-B.1">DIGIT</a> / "-" / "#" / "=" / "_" / "/" / "@" / "." / "%")
16551656
<dfn>tt-keyword</dfn> = "'allow-duplicates'"
16561657
</pre>
@@ -1736,7 +1737,10 @@ strings (|createdPolicyNames|), this algorithm returns `"Blocked"` if the
17361737
Note: `trusted-types policyA policyB 'allow-duplicates'` allows authors to create policies with
17371738
duplicated names.
17381739
1. If |directive|'s [=directive/value=] does not contain a <a>tt-policy-name</a>,
1739-
which value is |policyName|, set |createViolation| to true.
1740+
which value is |policyName|, and |directive|'s [=directive/value=] does not contain a <a>tt-wildcard</a>, set |createViolation| to true.
1741+
1742+
Note: `trusted-types *` allows authors to create policies with any unique names. To allow for multiple policies with the same name, use
1743+
`trusted-types * 'allow-duplicates'` or don't set the `trusted-types` directive at all.
17401744
1. If |createViolation| is false, skip to the next |policy|.
17411745
1. Let |violation| be the result of executing
17421746
[[CSP#create-violation-for-global|Create a violation object for global, policy, and directive]] on |global|, |policy| and

0 commit comments

Comments
 (0)