Skip to content

Commit ed97730

Browse files
committed
Add strict-dynamic-url
1 parent 5c242db commit ed97730

File tree

1 file changed

+78
-8
lines changed

1 file changed

+78
-8
lines changed

index.bs

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
392392
metadata which is listed in the current policy. Details in
393393
[[#external-hash]].
394394

395-
11. Reports generated for inline violations will contain a <a for="violation">sample</a>
395+
11. Hash-based source expressions may now match scripts based on their URL hashes.
396+
397+
12. Hash-based source expressions may now allow `eval()` execution based on the hash of
398+
the content of the eval.
399+
400+
13. Reports generated for inline violations will contain a <a for="violation">sample</a>
396401
attribute if the relevant directive contains the <a grammar>`'report-sample'`</a>
397402
expression.
398403
</section>
@@ -692,7 +697,7 @@ spec:SRI; urlPrefix: https://w3c.github.io/webappsec-subresource-integrity
692697

693698
; Keywords:
694699
<dfn>keyword-source</dfn> = "<dfn>'self'</dfn>" / "<dfn>'unsafe-inline'</dfn>" / "<dfn>'unsafe-eval'</dfn>"
695-
/ "<dfn>'strict-dynamic'</dfn>" / "<dfn>'unsafe-hashes'</dfn>"
700+
/ "<dfn>'strict-dynamic'</dfn>" / "<dfn>'strict-dynamic-url'</dfn>" / "<dfn>'unsafe-hashes'</dfn>"
696701
/ "<dfn>'report-sample'</dfn>" / "<dfn>'unsafe-allow-redirects'</dfn>"
697702
/ "<dfn>'wasm-unsafe-eval'</dfn>" / "<dfn>'trusted-types-eval'</dfn>"
698703
/ "<dfn>'report-sha256'</dfn>" / "<dfn>'report-sha384'</dfn>"
@@ -3796,12 +3801,16 @@ Content-Type: application/reports+json
37963801

37973802
5. If |directive|'s <a for="directive">value</a> does not contain a
37983803
<a>source expression</a> that is a match for the
3799-
"<a grammar>`'url-hash-source'`</a>" grammar:
3804+
"<a grammar>`url-hash-source`</a>" grammar:
38003805

38013806
1. If the result of executing [[#match-request-to-source-list]] on
38023807
|request|, |directive|'s <a for="directive">value</a>, and
38033808
|policy|, is "`Does Not Match`", return "`Blocked`".
38043809

3810+
Note: "<a grammar>`'strict-dynamic-url'`</a>" doesn't ignore <a grammar>`host-source`</a>
3811+
and <a grammar>`scheme-source`</a> expressions, unlike "<a grammar>`'strict-dynamic'`</a>"
3812+
and "<a grammar>`url-hash-source`</a>".
3813+
38053814
2. Return "`Allowed`".
38063815

38073816
<h5 algorithm id="script-post-request">
@@ -3834,7 +3843,8 @@ Content-Type: application/reports+json
38343843

38353844
1. If |directive|'s <a for="directive">value</a> contains a <a>source
38363845
expression</a> that is an <a>ASCII case-insensitive</a> match for
3837-
the "<a grammar>`'strict-dynamic'`</a>" <a grammar>keyword-source</a>:
3846+
the "<a grammar>`'strict-dynamic'`</a>" or
3847+
"<a grammar>`'strict-dynamic-url'`</a>" <a grammar>keyword-source</a>s:
38383848

38393849
1. If the |request|'s <a for="request">parser metadata</a> is
38403850
<a>"parser-inserted"</a>, return "`Blocked`".
@@ -4340,10 +4350,12 @@ Content-Type: application/reports+json
43404350

43414351
2. If |type| is "`script`", "`script attribute`" or "`navigation`"
43424352
and |expression| matches the <a grammar>keyword-source</a>
4343-
"<a grammar>`'strict-dynamic'`</a>", return "`Does Not Allow`".
4353+
"<a grammar>`'strict-dynamic'`</a>" or
4354+
"<a grammar>`'strict-dynamic-url'`</a>", return "`Does Not Allow`".
43444355

4345-
Note: `'strict-dynamic'` only applies to scripts, not other resource
4346-
types. Usage is explained in more detail in [[#strict-dynamic-usage]].
4356+
Note: `'strict-dynamic'` and `'strict-dynamic-url'` only apply to
4357+
scripts, not other resource types. Usage is explained in more detail
4358+
in [[#strict-dynamic-usage]].
43474359

43484360
3. If |expression| is an <a>ASCII case-insensitive</a> match for the
43494361
<a grammar>`keyword-source`</a> "<a grammar>`'unsafe-inline'`</a>",
@@ -4373,13 +4385,17 @@ Content-Type: application/reports+json
43734385
<a>Source lists</a> that do not
43744386
<a for="source list">allow all inline behavior</a> when |type| is
43754387
'`script`' or '`script attribute`' due to the presence of
4376-
'`strict-dynamic`', but <a for="source list">allow all inline behavior</a>
4388+
'`strict-dynamic`' or '`strict-dynamic-url`', but
4389+
<a for="source list">allow all inline behavior</a>
43774390
otherwise:
43784391

43794392
<pre>
43804393
'unsafe-inline' 'strict-dynamic'
4394+
'unsafe-inline' 'strict-dynamic-url'
4395+
43814396
http://example.com 'strict-dynamic' 'unsafe-inline'
43824397
</pre>
4398+
43834399
</div>
43844400

43854401
<h5 id="match-element-to-source-list" algorithm>
@@ -5072,6 +5088,60 @@ Content-Type: application/reports+json
50725088
untrusted data. This includes applications or frameworks that tend to determine
50735089
script locations at runtime.
50745090

5091+
Similarly, the "<a grammar>`'strict-dynamic-url'`</a>" source expression allows
5092+
you to deploy a policy based on "<a grammar>`url-hash-source`</a>"s in a
5093+
backwards compatible way.
5094+
5095+
If present in a <a>`script-src`</a> or <a>`default-src`</a> directive,
5096+
"<a grammar>`'strict-dynamic-url'`</a>" has two main effects:
5097+
5098+
1. "<a grammar>`'unsafe-inline'`</a>" <a grammar>keyword-source</a> will be
5099+
ignored when loading script.
5100+
5101+
2. Script requests which are triggered by non-<a>"parser-inserted"</a>
5102+
<{script}> elements are allowed.
5103+
5104+
"<a grammar>`'strict-dynamic-url'`</a>" doesn't ignore
5105+
<a grammar>host-source</a>, <a grammar>scheme-source</a> and
5106+
<a grammar>`'self'`</a>. However, <a grammar>`url-hash-source`</a>s ignore
5107+
these expressions.
5108+
5109+
This allows you to deploy <a grammar>`url-hash-source`</a>s in a
5110+
backwards compatible way, without requiring user-agent sniffing.
5111+
5112+
<div class="example">
5113+
Suppose MegaCorp, Inc. presently deploys the following lax policy:
5114+
5115+
<pre>
5116+
<a http-header>Content-Security-Policy</a>: <a>script-src</a> https: 'unsafe-inline'
5117+
</pre>
5118+
5119+
And serves the following HTML with that policy active:
5120+
5121+
<pre highlight="html">
5122+
...
5123+
&lt;script src="https://example.com/script.js" &gt;&lt;/script&gt;
5124+
...
5125+
</pre>
5126+
5127+
MegaCorp, Inc. now wants to deploy a more strict policy using <a grammar>`url-hash-source`</a>s:
5128+
5129+
<pre>
5130+
<a http-header>Content-Security-Policy</a>: <a>script-src</a> https: 'unsafe-inline' 'strict-dynamic-url' 'url-hash-EAaArVRs5qV39C9S3zO0z9ynVoWeZkuNfeMpsVDQnOk='
5131+
</pre>
5132+
5133+
User agents that understand <a grammar>`url-hash-source`</a>s will allow
5134+
the script and any non-parser inserted scripts it loads.
5135+
5136+
User agents that don't understand <a grammar>`url-hash-source`</a>s will
5137+
see the policy as "`https: 'unsafe-inline'`". This lax policy will also
5138+
allow the script to be loaded.
5139+
5140+
Note: This policy can't use "<a grammar>`'strict-dynamic'`</a>" because
5141+
older user agents that need to receive a lax fallback policy will ignore the
5142+
`https:` source expression due to "<a grammar>`'strict-dynamic'`</a>".
5143+
</div>
5144+
50755145
<section>
50765146
<h3 id="unsafe-hashes-usage">
50775147
Usage of "`'unsafe-hashes'`"

0 commit comments

Comments
 (0)