Skip to content

Commit d23e034

Browse files
committed
Added 'trusted-types' CSP keyword integration for javascript:
navigations.
1 parent a617a78 commit d23e034

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

dist/spec/index.html

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,12 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
15701570
<li><a href="#should-block-sink-type-mismatch"><span class="secno">4.5.2</span> <span class="content"><span>Should sink type mismatch violation be blocked by Content Security Policy?</span></span></a>
15711571
<li><a href="#should-block-create-policy"><span class="secno">4.5.3</span> <span class="content"><span>Should Trusted Type policy creation be blocked by Content Security Policy?</span></span></a>
15721572
<li><a href="#csp-violation-object-hdr"><span class="secno">4.5.4</span> <span class="content">Violation object changes</span></a>
1573-
<li><a href="#trusted-script-csp-keyword"><span class="secno">4.5.5</span> <span class="content">'trusted-script' keyword</span></a>
1573+
<li>
1574+
<a href="#trusted-script-csp-keyword"><span class="secno">4.5.5</span> <span class="content">'trusted-script' keyword</span></a>
1575+
<ol class="toc">
1576+
<li><a href="#csp-trusted-script-eval"><span class="secno">4.5.5.1</span> <span class="content">'trusted-script' support for eval</span></a>
1577+
<li><a href="#csp-trusted-script-javascript-url"><span class="secno">4.5.5.2</span> <span class="content">'trusted-script' support for javascript: URLs</span></a>
1578+
</ol>
15741579
<li><a href="#is-source-exempt-algorithm"><span class="secno">4.5.6</span> <span class="content"><span>IsSourceExempt</span> Algorithm</span></a>
15751580
</ol>
15761581
</ol>
@@ -2795,6 +2800,7 @@ <h4 class="heading settled" data-level="4.5.5" id="trusted-script-csp-keyword"><
27952800
/ "'strict-dynamic'" / "'unsafe-hashes'" / "'report-sample'"
27962801
/ "'unsafe-allow-redirects'" <ins>/ "<dfn class="dfn-paneled" data-dfn-type="grammar" data-export id="grammardef-trusted-script">'trusted-script'</dfn>"</ins>
27972802
</pre>
2803+
<h5 class="heading settled" data-level="4.5.5.1" id="csp-trusted-script-eval"><span class="secno">4.5.5.1. </span><span class="content">'trusted-script' support for eval</span><a class="self-link" href="#csp-trusted-script-eval"></a></h5>
27982804
<p>This document modifies the <a href="https://www.w3.org/TR/CSP3/#can-compile-strings">EnsureCSPDoesNotBlockStringCompilation</a> which is reproduced in its entirety below with additions and deletions.</p>
27992805
<p>
28002806
Given two <a href="https://tc39.github.io/ecma262/#realm">realms</a> (<var>callerRealm</var> and <var>calleeRealm</var>), and a
@@ -2897,8 +2903,16 @@ <h4 class="heading settled" data-level="4.5.5" id="trusted-script-csp-keyword"><
28972903
<p class="note" role="note"><span>Note:</span> The previous algorithm reports violations via both report-uris where
28982904
callerRealm != calleeRealm. If <a data-link-type="abstract-op" href="#abstract-opdef-get-trusted-type-compliant-string" id="ref-for-abstract-opdef-get-trusted-type-compliant-string⑧">Get Trusted Type compliant string</a> reports an
28992905
error, it only reports it via its <var>calleeRealm</var>’s report-uri.</p>
2906+
<h5 class="heading settled" data-level="4.5.5.2" id="csp-trusted-script-javascript-url"><span class="secno">4.5.5.2. </span><span class="content">'trusted-script' support for javascript: URLs</span><a class="self-link" href="#csp-trusted-script-javascript-url"></a></h5>
2907+
<p>This document modifies the <a href="https://www.w3.org/TR/CSP3/#match-element-to-source-list">Does element match source list for type and source?</a> algorithm, for it to recognize the 'trusted-script' keyword for <code>javascript:</code> navigations.</p>
2908+
<p>Add the following step after step 1:</p>
2909+
<ol start="2">
2910+
<li data-md>
2911+
<p>If <var>type</var> is <code>"navigation"</code>, <var>list</var> <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#list-contain" id="ref-for-list-contain①">contains</a> 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="#grammardef-trusted-script" id="ref-for-grammardef-trusted-script①"><code>'trusted-script'</code></a>" and <a data-link-type="abstract-op" href="#abstract-opdef-issourceexempt" id="ref-for-abstract-opdef-issourceexempt①">IsSourceExempt</a> algorithm executed on <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#active-document" id="ref-for-active-document">active document</a>'s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/dom.html#concept-document-csp-list" id="ref-for-concept-document-csp-list③">CSP list</a> returns true,
2912+
return <code>"Matches"</code>.</p>
2913+
</ol>
29002914
<h4 class="heading settled" data-level="4.5.6" id="is-source-exempt-algorithm"><span class="secno">4.5.6. </span><span class="content"><dfn class="dfn-paneled" data-dfn-type="abstract-op" data-export id="abstract-opdef-issourceexempt">IsSourceExempt</dfn> Algorithm</span><a class="self-link" href="#is-source-exempt-algorithm"></a></h4>
2901-
<p>The IsSourceExempt algorithm takes a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/dom.html#concept-document-csp-list" id="ref-for-concept-document-csp-list">CSP List</a> (<var>cspList</var>) and executes
2915+
<p>The IsSourceExempt algorithm takes a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/dom.html#concept-document-csp-list" id="ref-for-concept-document-csp-list">CSP List</a> (<var>cspList</var>) and executes
29022916
the following steps:</p>
29032917
<ol>
29042918
<li data-md>
@@ -3390,6 +3404,12 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
33903404
<li><a href="#ref-for-windowproxy">4.5.1.1. trusted-types Pre-Navigation check</a>
33913405
</ul>
33923406
</aside>
3407+
<aside class="dfn-panel" data-for="term-for-active-document">
3408+
<a href="https://html.spec.whatwg.org/multipage/browsers.html#active-document">https://html.spec.whatwg.org/multipage/browsers.html#active-document</a><b>Referenced in:</b>
3409+
<ul>
3410+
<li><a href="#ref-for-active-document">4.5.5.2. 'trusted-script' support for javascript: URLs</a>
3411+
</ul>
3412+
</aside>
33933413
<aside class="dfn-panel" data-for="term-for-browsing-context">
33943414
<a href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context">https://html.spec.whatwg.org/multipage/browsers.html#browsing-context</a><b>Referenced in:</b>
33953415
<ul>
@@ -3402,7 +3422,8 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
34023422
<li><a href="#ref-for-concept-document-csp-list">3.4. Get Trusted Type compliant string</a>
34033423
<li><a href="#ref-for-concept-document-csp-list①">4.5.2. Should sink type mismatch violation be blocked by Content Security Policy?</a>
34043424
<li><a href="#ref-for-concept-document-csp-list②">4.5.3. Should Trusted Type policy creation be blocked by Content Security Policy?</a>
3405-
<li><a href="#ref-for-concept-document-csp-list③">4.5.6. IsSourceExempt Algorithm</a>
3425+
<li><a href="#ref-for-concept-document-csp-list③">4.5.5.2. 'trusted-script' support for javascript: URLs</a>
3426+
<li><a href="#ref-for-concept-document-csp-list④">4.5.6. IsSourceExempt Algorithm</a>
34063427
</ul>
34073428
</aside>
34083429
<aside class="dfn-panel" data-for="term-for-concept-realm-global">
@@ -3412,7 +3433,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
34123433
<li><a href="#ref-for-concept-realm-global①">3.4. Get Trusted Type compliant string</a>
34133434
<li><a href="#ref-for-concept-realm-global②">4.5.2. Should sink type mismatch violation be blocked by Content Security Policy?</a>
34143435
<li><a href="#ref-for-concept-realm-global③">4.5.3. Should Trusted Type policy creation be blocked by Content Security Policy?</a>
3415-
<li><a href="#ref-for-concept-realm-global④">4.5.5. 'trusted-script' keyword</a> <a href="#ref-for-concept-realm-global⑤">(2)</a>
3436+
<li><a href="#ref-for-concept-realm-global④">4.5.5.1. 'trusted-script' support for eval</a> <a href="#ref-for-concept-realm-global⑤">(2)</a>
34163437
</ul>
34173438
</aside>
34183439
<aside class="dfn-panel" data-for="term-for-dom-innertext">
@@ -3448,7 +3469,8 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
34483469
<aside class="dfn-panel" data-for="term-for-ascii-case-insensitive">
34493470
<a href="https://infra.spec.whatwg.org/#ascii-case-insensitive">https://infra.spec.whatwg.org/#ascii-case-insensitive</a><b>Referenced in:</b>
34503471
<ul>
3451-
<li><a href="#ref-for-ascii-case-insensitive">4.5.5. 'trusted-script' keyword</a> <a href="#ref-for-ascii-case-insensitive①">(2)</a>
3472+
<li><a href="#ref-for-ascii-case-insensitive">4.5.5.1. 'trusted-script' support for eval</a> <a href="#ref-for-ascii-case-insensitive①">(2)</a>
3473+
<li><a href="#ref-for-ascii-case-insensitive②">4.5.5.2. 'trusted-script' support for javascript: URLs</a>
34523474
</ul>
34533475
</aside>
34543476
<aside class="dfn-panel" data-for="term-for-ascii-lowercase">
@@ -3468,7 +3490,8 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
34683490
<aside class="dfn-panel" data-for="term-for-list-contain">
34693491
<a href="https://infra.spec.whatwg.org/#list-contain">https://infra.spec.whatwg.org/#list-contain</a><b>Referenced in:</b>
34703492
<ul>
3471-
<li><a href="#ref-for-list-contain">4.5.5. 'trusted-script' keyword</a>
3493+
<li><a href="#ref-for-list-contain">4.5.5.1. 'trusted-script' support for eval</a>
3494+
<li><a href="#ref-for-list-contain①">4.5.5.2. 'trusted-script' support for javascript: URLs</a>
34723495
</ul>
34733496
</aside>
34743497
<aside class="dfn-panel" data-for="term-for-html-namespace">
@@ -3527,7 +3550,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
35273550
<aside class="dfn-panel" data-for="term-for-exceptiondef-evalerror">
35283551
<a href="https://heycam.github.io/webidl/#exceptiondef-evalerror">https://heycam.github.io/webidl/#exceptiondef-evalerror</a><b>Referenced in:</b>
35293552
<ul>
3530-
<li><a href="#ref-for-exceptiondef-evalerror">4.5.5. 'trusted-script' keyword</a>
3553+
<li><a href="#ref-for-exceptiondef-evalerror">4.5.5.1. 'trusted-script' support for eval</a>
35313554
</ul>
35323555
</aside>
35333556
<aside class="dfn-panel" data-for="term-for-Exposed">
@@ -3678,6 +3701,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
36783701
<li><span class="dfn-paneled" id="term-for-window" style="color:initial">Window</span>
36793702
<li><span class="dfn-paneled" id="term-for-windoworworkerglobalscope" style="color:initial">WindowOrWorkerGlobalScope</span>
36803703
<li><span class="dfn-paneled" id="term-for-windowproxy" style="color:initial">WindowProxy</span>
3704+
<li><span class="dfn-paneled" id="term-for-active-document" style="color:initial">active document</span>
36813705
<li><span class="dfn-paneled" id="term-for-browsing-context" style="color:initial">browsing context</span>
36823706
<li><span class="dfn-paneled" id="term-for-concept-document-csp-list" style="color:initial">csp list</span>
36833707
<li><span class="dfn-paneled" id="term-for-concept-realm-global" style="color:initial">global object</span>
@@ -3967,7 +3991,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
39673991
<li><a href="#ref-for-trustedscript①①">4.1.6. Enforcement in event handler content attributes</a>
39683992
<li><a href="#ref-for-trustedscript①②">4.2. Integration with SVG</a>
39693993
<li><a href="#ref-for-trustedscript①③">4.5.1.1. trusted-types Pre-Navigation check</a>
3970-
<li><a href="#ref-for-trustedscript①④">4.5.5. 'trusted-script' keyword</a>
3994+
<li><a href="#ref-for-trustedscript①④">4.5.5.1. 'trusted-script' support for eval</a>
39713995
</ul>
39723996
</aside>
39733997
<aside class="dfn-panel" data-for="trustedscripturl">
@@ -4133,7 +4157,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
41334157
<li><a href="#ref-for-default-policy">3.2. Get default policy</a>
41344158
<li><a href="#ref-for-default-policy①">4.5.1. trusted-types directive</a>
41354159
<li><a href="#ref-for-default-policy②">4.5.1.1. trusted-types Pre-Navigation check</a>
4136-
<li><a href="#ref-for-default-policy③">4.5.5. 'trusted-script' keyword</a> <a href="#ref-for-default-policy④">(2)</a>
4160+
<li><a href="#ref-for-default-policy③">4.5.5.1. 'trusted-script' support for eval</a> <a href="#ref-for-default-policy④">(2)</a>
41374161
<li><a href="#ref-for-default-policy⑤">6.1. Vendor-specific Extensions and Addons</a>
41384162
</ul>
41394163
</aside>
@@ -4187,7 +4211,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
41874211
<li><a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string③">4.1.5. Enforcement in timer functions</a>
41884212
<li><a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string④">4.1.6. Enforcement in event handler content attributes</a>
41894213
<li><a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑤">4.2. Integration with SVG</a>
4190-
<li><a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑥">4.5.5. 'trusted-script' keyword</a> <a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑦">(2)</a> <a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑧">(3)</a>
4214+
<li><a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑥">4.5.5.1. 'trusted-script' support for eval</a> <a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑦">(2)</a> <a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑧">(3)</a>
41914215
<li><a href="#ref-for-abstract-opdef-get-trusted-type-compliant-string⑨">4.5.6. IsSourceExempt Algorithm</a>
41924216
</ul>
41934217
</aside>
@@ -4317,13 +4341,15 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
43174341
<aside class="dfn-panel" data-for="grammardef-trusted-script">
43184342
<b><a href="#grammardef-trusted-script">#grammardef-trusted-script</a></b><b>Referenced in:</b>
43194343
<ul>
4320-
<li><a href="#ref-for-grammardef-trusted-script">4.5.5. 'trusted-script' keyword</a>
4344+
<li><a href="#ref-for-grammardef-trusted-script">4.5.5.1. 'trusted-script' support for eval</a>
4345+
<li><a href="#ref-for-grammardef-trusted-script①">4.5.5.2. 'trusted-script' support for javascript: URLs</a>
43214346
</ul>
43224347
</aside>
43234348
<aside class="dfn-panel" data-for="abstract-opdef-issourceexempt">
43244349
<b><a href="#abstract-opdef-issourceexempt">#abstract-opdef-issourceexempt</a></b><b>Referenced in:</b>
43254350
<ul>
4326-
<li><a href="#ref-for-abstract-opdef-issourceexempt">4.5.5. 'trusted-script' keyword</a>
4351+
<li><a href="#ref-for-abstract-opdef-issourceexempt">4.5.5.1. 'trusted-script' support for eval</a>
4352+
<li><a href="#ref-for-abstract-opdef-issourceexempt①">4.5.5.2. 'trusted-script' support for javascript: URLs</a>
43274353
</ul>
43284354
</aside>
43294355
<script>/* script-dfn-panel */

spec/index.bs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,8 @@ This document modifies the grammar for [[CSP3#keyword-source]]:
13431343
/ "'unsafe-allow-redirects'" <ins>/ "<dfn>'trusted-script'</dfn>"</ins>
13441344
</pre>
13451345

1346+
#### 'trusted-script' support for eval #### {#csp-trusted-script-eval}
1347+
13461348
This document modifies the [[CSP3#can-compile-strings|EnsureCSPDoesNotBlockStringCompilation]]
13471349
which is reproduced in its entirety below with additions and deletions.
13481350

@@ -1425,6 +1427,17 @@ Note: The previous algorithm reports violations via both report-uris where
14251427
callerRealm != calleeRealm. If [$Get Trusted Type compliant string$] reports an
14261428
error, it only reports it via its |calleeRealm|'s report-uri.
14271429

1430+
#### 'trusted-script' support for javascript: URLs #### {#csp-trusted-script-javascript-url}
1431+
1432+
This document modifies the [[CSP3#match-element-to-source-list|Does element match source list for type and source?]]
1433+
algorithm, for it to recognize the 'trusted-script' keyword for `javascript:` navigations.
1434+
1435+
Add the following step after step 1:
1436+
1437+
2. If |type| is `"navigation"`, |list| [=list/contains=] an [=ASCII case-insensitive=]
1438+
match for the string "<a grammar>`'trusted-script'`</a>" and [$IsSourceExempt$] algorithm executed on [=active document=]'s <a>CSP list</a> returns true,
1439+
return `"Matches"`.
1440+
14281441

14291442
### <dfn abstract-op>IsSourceExempt</dfn> Algorithm ### {#is-source-exempt-algorithm}
14301443

0 commit comments

Comments
 (0)