-
Notifications
You must be signed in to change notification settings - Fork 148
/
2014-07-03-CSP-2-LCWD.html
3472 lines (2835 loc) · 249 KB
/
2014-07-03-CSP-2-LCWD.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html lang=en><head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>Content Security Policy Level 2</title>
<link href=./default.css rel=stylesheet type=text/css>
<link href=https://www.w3.org/StyleSheets/TR/W3C-LC rel=stylesheet type=text/css>
<style>
table {
text-align: left;
margin: 20px;
width: 100%;
border-collapse: collapse;
}
tbody tr:nth-child(odd) {
background-color: #EEE;
}
th {
border-bottom: 1px solid #999;
padding: 0.5em;
}
td:first-child {
width: 30%;
padding-right: 1em;
}
td {
vertical-align: top;
padding: 0.5em;
}
tbody th {
border: 0;
background-color: #FFF;
}
tr.section {
border-top: 1px solid #999;
vertical-align: top;
}
</style>
</head>
<body class=h-entry>
<div class=head>
<p data-fill-with=logo><a class=logo href=http://www.w3.org/>
<img alt=W3C height=48 src=https://www.w3.org/Icons/w3c_home width=72>
</a>
</p>
<h1 class="p-name no-ref" id=title>Content Security Policy Level 2</h1>
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>W3C Last Call Working Draft,
<span class=dt-updated><span class=value-title title=20140703>03 July 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl><dt>Feedback:<dd><a href="mailto:public-webappsec@w3.org?subject=%5BCSP%5D%20feedback">public-webappsec@w3.org</a>
with subject line
“<kbd>[CSP] <var>… message topic …</var></kbd>”(<a U00027="" href=http://lists.w3.org/Archives/Public/public-webappsec/ rel=discussion>archives</a>)<dt>Editor’s Draft:<dd><a href=https://w3c.github.io/webappsec/specs/content-security-policy/>https://w3c.github.io/webappsec/specs/content-security-policy/</a><dt>Former Editors:<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:brandon@hackmill.com>Brandon Sterne</a> (<span class="p-org org">formerly of Mozilla Corporation</span>)<dt>Editors:<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:mkwst@google.com>Mike West</a> (<span class="p-org org">Google Inc.</span>)<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:w3c@adambarth.com>Adam Barth</a> (<span class="p-org org">Google Inc.</span>)<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:dveditz@mozilla.com>Dan Veditz</a> (<span class="p-org org">Mozilla Corporation</span>)<dt>Latest version:<dd><a href=http://www.w3c.org/TR/CSP/>http://www.w3c.org/TR/CSP/</a><dt>This version:<dd><a class=u-url href=http://www.w3.org/TR/2014/WD-CSP-2-20140703/>http://www.w3.org/TR/2014/WD-CSP-2-20140703/</a></dl></div>
<div data-fill-with=warning></div>
<p class=copyright data-fill-with=copyright><a href=http://www.w3.org/Consortium/Legal/ipr-notice#Copyright>Copyright</a> © 2014
<a href=http://www.w3.org/><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup>
(<a href=http://www.csail.mit.edu/><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>,
<a href=http://www.ercim.eu/><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href=http://www.keio.ac.jp/>Keio</a>, <a href=http://ev.buaa.edu.cn/>Beihang</a>),
All Rights Reserved.
<abbr title="World Wide Web Consortium">W3C</abbr> <a href=http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer>liability</a>,
<a href=http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks>trademark</a> and
<a href=http://www.w3.org/Consortium/Legal/copyright-documents>document use</a>
rules apply.
</p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled heading" id=abstract><span class=content>Abstract</span></h2>
<p class=p-summary data-fill-with=abstract><p>This document defines a policy language used to declare a set of content restrictions for a web resource, and a mechanism for transmitting the policy from a server to a client where the policy is enforced.</p>
</p>
<h2 class="no-num no-toc no-ref heading settled heading" id=status><span class=content>Status of this document</span></h2>
<div data-fill-with=status><p>
<em>This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the <a href=http://www.w3.org/TR/>W3C technical reports
index at http://www.w3.org/TR/.</a></em>
<p>
This document was published by the
<a href=http://www.w3.org/2011/webappsec/>Web Application Security Working Group</a>
as a Working Draft. This document is intended to become a W3C Recommendation.
<p>
The (<a href=http://lists.w3.org/Archives/Public/public-webappsec/>archived</a>) public mailing list
<a href="mailto:public-webappsec@w3.org?Subject=%5BCSP%5D%20PUT%20SUBJECT%20HERE">public-webappsec@w3.org</a>
(see <a href=http://www.w3.org/Mail/Request>instructions</a>)
is preferred for discussion of this specification.
When sending e-mail,
please put the text “CSP” in the subject,
preferably like this:
“[CSP] <em>…summary of comment…</em>”
<p>
Publication as a Last Call Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite this
document as other than work in progress.
<p>
This document was produced by the
<a href=http://www.w3.org/2011/webappsec/>Web Application Security Working Group</a>.
<p>
This document was produced by a group operating under
the <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/>5 February 2004 W3C Patent Policy</a>.
W3C maintains a <a href=http://www.w3.org/2004/01/pp-impl/32061/status rel=disclosure>public list of any patent disclosures</a>
made in connection with the deliverables of the group;
that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent which the individual believes contains <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential>Essential Claim(s)</a>
must disclose the information in accordance with <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure>section 6 of the W3C Patent Policy</a>.
<p>
This specification is a <strong>Last Call Working Draft</strong>. All
persons are encouraged to review this document and <strong>send comments
to the <a href=http://lists.w3.org/Archives/Public/public-webappsec/>public-webappsec</a>
mailing list</strong> as described above. The <strong>deadline for
comments</strong> is <strong>13 August 2014</strong>.
</div>
<div data-fill-with=at-risk><p>The following features are at-risk, and may be dropped during the CR period:
<ul><li>The <a data-link-type=dfn href=#referrer title=referrer>referrer</a> directive.<li>The <a data-link-type=dfn href=#reflected-xss title=reflected-xss>reflected-xss</a> directive.</ul></div>
<h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><ul class=toc>
<li><a href=#intro><span class=secno>1</span>Introduction</a>
<li><a href=#key-concepts><span class=secno>2</span>Key Concepts and Terminology</a>
<li><a href=#policy-delivery><span class=secno>3</span>Policy Delivery</a>
<ul class=toc>
<li><a href=#content-security-policy-header-field><span class=secno>3.1</span> <code>Content-Security-Policy</code> Header Field </a>
<li><a href=#content-security-policy-report-only-header-field><span class=secno>3.2</span> <code>Content-Security-Policy-Report-Only</code> Header Field </a>
<li><a href=#delivery-html-meta-element><span class=secno>3.3</span> HTML <code><span data-link-type=element title=meta>meta</span></code> Element </a>
<li><a href=#ch-csp-client-hint><span class=secno>3.4</span>The <code>CH-CSP</code> Client Hint</a>
<li><a href=#enforcing-multiple-policies><span class=secno>3.5</span>Enforcing multiple policies.</a>
<li><a href=#which-policy-applies><span class=secno>3.6</span>Policy applicability</a></ul>
<li><a href=#syntax-and-algorithms><span class=secno>4</span>Syntax and Algorithms</a>
<ul class=toc>
<li><a href=#policy-syntax><span class=secno>4.1</span>Policy Syntax</a>
<ul class=toc>
<li><a href=#policy-parsing><span class=secno>4.1.1</span>Parsing Policies</a></ul>
<li><a href=#source-list-syntax><span class=secno>4.2</span>Source List Syntax</a>
<ul class=toc>
<li><a href=#source-list-parsing><span class=secno>4.2.1</span>Parsing Source Lists</a>
<li><a href=#match-source-expression><span class=secno>4.2.2</span>Matching Source Expressions</a>
<ul class=toc>
<li><a href=#source-list-guid-matching><span class=secno>4.2.2.1</span> Security Considerations for GUID URI schemes </a>
<li><a href=#source-list-path-patching><span class=secno>4.2.2.2</span>Path Matching</a>
<li><a href=#source-list-paths-and-redirects><span class=secno>4.2.2.3</span>Paths and Redirects</a></ul>
<li><a href=#script-src-the-nonce-attribute><span class=secno>4.2.3</span> The <code>nonce</code> attribute </a>
<li><a href=#source-list-valid-nonces><span class=secno>4.2.4</span>Valid Nonces</a>
<li><a href=#source-list-valid-hashes><span class=secno>4.2.5</span>Valid Hashes</a></ul>
<li><a href=#media-type-list><span class=secno>4.3</span>Media Type List</a>
<ul class=toc>
<li><a href=#media-type-list-parsing><span class=secno>4.3.1</span>Parsing</a>
<li><a href=#media-type-list-matching><span class=secno>4.3.2</span>Matching</a></ul>
<li><a href=#violation-reports><span class=secno>4.4</span>Reporting</a></ul>
<li><a href=#processing-model><span class=secno>5</span>Processing Model</a>
<ul class=toc>
<li><a href=#processing-model-workers><span class=secno>5.1</span>Workers</a>
<li><a href=#processing-model-iframe-srcdoc><span class=secno>5.2</span><code>srcdoc</code> IFrames</a></ul>
<li><a href=#script-interfaces><span class=secno>6</span>Script Interfaces</a>
<ul class=toc>
<li><a href=#securitypolicyviolationevent-interface><span class=secno>6.1</span> <code>SecurityPolicyViolationEvent</code> Interface </a>
<li><a href=#securitypolicyviolationeventinit-interface><span class=secno>6.2</span> <code>SecurityPolicyViolationEventInit</code> Interface </a>
<li><a href=#firing-securitypolicyviolationevent-events><span class=secno>6.3</span>Firing Violation Events</a></ul>
<li><a href=#sec-directives><span class=secno>7</span>Directives</a>
<ul class=toc>
<li><a href=#directive-base-uri><span class=secno>7.1</span><code>base-uri</code></a>
<li><a href=#directive-child-src><span class=secno>7.2</span><code>child-src</code></a>
<ul class=toc>
<li><a href=#directive-child-src-nested><span class=secno>7.2.1</span>Nested Browsing Contexts</a>
<li><a href=#directive-child-src-workers><span class=secno>7.2.2</span>Workers</a></ul>
<li><a href=#directive-connect-src><span class=secno>7.3</span><code>connect-src</code></a>
<ul class=toc>
<li><a href=#connect-src-usage><span class=secno>7.3.1</span>Usage</a></ul>
<li><a href=#directive-default-src><span class=secno>7.4</span><code>default-src</code></a>
<ul class=toc>
<li><a href=#default-src-usage><span class=secno>7.4.1</span>Usage</a></ul>
<li><a href=#directive-font-src><span class=secno>7.5</span><code>font-src</code></a>
<li><a href=#directive-form-action><span class=secno>7.6</span><code>form-action</code></a>
<li><a href=#directive-frame-ancestors><span class=secno>7.7</span><code>frame-ancestors</code></a>
<ul class=toc>
<li><a href=#frame-ancestors-and-frame-options><span class=secno>7.7.1</span> Relation to <code>X-Frame-Options</code> </a>
<li><a href=#frame-ancestors-multiple-source-values><span class=secno>7.7.2</span>Multiple Host Source Values</a></ul>
<li><a href=#directive-frame-src><span class=secno>7.8</span><code>frame-src</code></a>
<li><a href=#directive-img-src><span class=secno>7.9</span><code>img-src</code></a>
<li><a href=#directive-media-src><span class=secno>7.10</span><code>media-src</code></a>
<li><a href=#directive-object-src><span class=secno>7.11</span><code>object-src</code></a>
<li><a href=#directive-plugin-types><span class=secno>7.12</span><code>plugin-types</code></a>
<ul class=toc>
<li><a href=#plugin-types-usage><span class=secno>7.12.1</span>Usage</a>
<li><a href=#plugin-types-predeclaration><span class=secno>7.12.2</span> Predeclaration of expected media types </a></ul>
<li><a href=#directive-referrer><span class=secno>7.13</span><code>referrer</code></a>
<ul class=toc>
<li><a href=#referrer-multiple-policies><span class=secno>7.13.1</span>Processing multiple referrer policies</a>
<ul class=toc>
<li><a href=#referrer-usage><span class=secno>7.13.1.1</span>Usage</a></ul></ul>
<li><a href=#directive-reflected-xss><span class=secno>7.14</span><code>reflected-xss</code></a>
<ul class=toc>
<li><a href=#reflected-xss-and-x-xss-protection><span class=secno>7.14.1</span> Relationship to <code>X-XSS-Protection</code> </a></ul>
<li><a href=#directive-report-uri><span class=secno>7.15</span><code>report-uri</code></a>
<li><a href=#directive-sandbox><span class=secno>7.16</span><code>sandbox</code></a>
<ul class=toc>
<li><a href=#sandbox-usage><span class=secno>7.16.1</span>Usage</a></ul>
<li><a href=#directive-script-src><span class=secno>7.17</span><code>script-src</code></a>
<ul class=toc>
<li><a href=#script-src-nonce-usage><span class=secno>7.17.1</span> Nonce usage for <code><span data-link-type=element title=script>script</span></code> elements </a>
<li><a href=#script-src-hash-usage><span class=secno>7.17.2</span> Hash usage for <code><span data-link-type=element title=script>script</span></code> elements </a></ul>
<li><a href=#directive-style-src><span class=secno>7.18</span><code>style-src</code></a>
<ul class=toc>
<li><a href=#style-src-nonce-usage><span class=secno>7.18.1</span> Nonce usage for <code><span data-link-type=element title=style>style</span></code> elements </a>
<li><a href=#style-src-hash-usage><span class=secno>7.18.2</span> Hash usage for <code><span data-link-type=element title=style>style</span></code> elements </a></ul></ul>
<li><a href=#examples><span class=secno>8</span>Examples</a>
<ul class=toc>
<li><a href=#example-policies><span class=secno>8.1</span>Sample Policy Definitions</a>
<li><a href=#example-violation-report><span class=secno>8.2</span>Sample Violation Report</a></ul>
<li><a href=#security-considerations><span class=secno>9</span>Security Considerations</a>
<ul class=toc>
<li><a href=#security-css-parsing><span class=secno>9.1</span>Cascading Style Sheet (CSS) Parsing</a>
<li><a href=#security-violation-reports><span class=secno>9.2</span>Violation Reports</a></ul>
<li><a href=#implementation-considerations><span class=secno>10</span>Implementation Considerations</a>
<li><a href=#iana-considerations><span class=secno>11</span>IANA Considerations</a>
<ul class=toc>
<li><a href=#iana-content-security-policy><span class=secno>11.1</span>Content-Security-Policy</a>
<li><a href=#iana-content-security-policy-report-only><span class=secno>11.2</span>Content-Security-Policy-Report-Only</a>
<li><a href=#iana-ch-csp><span class=secno>11.3</span>CH-CSP</a></ul>
<li><a href=#acknowledgements><span class=secno>12</span>Acknowledgements</a>
<li><a href=#conformance><span class=secno></span>Conformance</a>
<ul class=toc>
<li><a href=#conventions><span class=secno></span>Document conventions</a>
<li><a href=#conformant-algorithms><span class=secno></span>Conformant Algorithms</a>
<li><a href=#conformance-classes><span class=secno></span>Conformance Classes</a></ul>
<li><a href=#references><span class=secno></span> References</a>
<ul class=toc>
<li><a href=#normative><span class=secno></span> Normative References</a>
<li><a href=#informative><span class=secno></span> Informative References</a></ul>
<li><a href=#index><span class=secno></span> Index</a></ul></div>
<section>
<h2 class="heading settled heading" data-level=1 id=intro><span class=secno>1 </span><span class=content>Introduction</span><a class=self-link href=#intro></a></h2>
<p><em>This section is not normative.</em></p>
<p>This document defines Content Security Policy, a mechanism web applications
can use to mitigate a broad class of content injection vulnerabilities, such
as cross-site scripting (XSS). Content Security Policy is a declarative policy
that lets the authors (or server administrators) of a web application inform
the client about the sources from which the application expects to load
resources.</p>
<p>To mitigate XSS attacks, for example, a web application can declare that it
only expects to load script from specific, trusted sources. This declaration
allows the client to detect and block malicious scripts injected into the
application by an attacker.</p>
<p>Content Security Policy (CSP) is not intended as a first line of defense
against content injection vulnerabilities. Instead, CSP is best used as
defense-in-depth, to reduce the harm caused by content injection attacks. As
a first line of defense against content injection, server operators should
validate their input and encode their output.</p>
<p>There is often a non-trivial amount of work required to apply CSP to an
existing web application. To reap the greatest benefit, authors will need to
move all inline script and style out-of-line, for example into external
scripts, because the user agent cannot determine whether an inline script
was injected by an attacker.</p>
<p>To take advantage of CSP, a web application opts into using CSP by supplying a
<code>Content-Security-Policy</code> HTTP header. Such policies apply to the
current resource representation only. To supply a policy for an entire site,
the server needs to supply a policy with each resource representation.</p>
</section>
<section>
<h2 class="heading settled heading" data-level=2 id=key-concepts><span class=secno>2 </span><span class=content>Key Concepts and Terminology</span><a class=self-link href=#key-concepts></a></h2>
<p>This section defines several terms used throughout the document.</p>
<p>The term <dfn data-dfn-type=dfn data-export="" id=security-policy title="security policy|policy">security policy<a class=self-link href=#security-policy></a></dfn>
refers to either:</p>
<ol>
<li>a set of security preferences for restrictions within which
the content can operate, or</li>
<li>a fragment of text that codifies these preferences.</li>
</ol>
<p>The security policies defined by this document are applied by a
user agent on a <em>per-resource representation basis</em>.
Specifically, when a user agent receives a policy along with the
representation of a given resource, that policy applies to <em>that
resource representation only</em>. This document often refers to
that resource representation as the <dfn data-dfn-type=dfn data-export="" id=protected-resource>protected resource<a class=self-link href=#protected-resource></a></dfn>.</p>
<p>A <dfn data-dfn-type=dfn data-export="" id=security-policy-directive title="security policy directive|directive">security policy
directive<a class=self-link href=#security-policy-directive></a></dfn> is a portion of a <a data-link-type=dfn href=#security-policy title=policy>policy</a> that declares the specific
set of restrictions for a particular resource type, or which manipulates a
specific aspect of a protected resource’s configuration. A server transmits
its security policy for a particular protected resource as a collection of
directives, such as <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'self'</code>, each of which
declares a specific set of restrictions for that resource as instantiated
by the user agent. More details are provided in the
<a data-section="" href=#sec-directives>§7 Directives</a> section.</p>
<p>A directive consists of a <dfn data-dfn-type=dfn data-noexport="" id=directive-name0>directive name<a class=self-link href=#directive-name0></a></dfn>, which
indicates the privileges controlled by the directive, and a
<dfn data-dfn-type=dfn data-noexport="" id=directive-value0>directive value<a class=self-link href=#directive-value0></a></dfn>, which specifies the restrictions the
policy imposes on those privileges.</p>
The term <dfn data-dfn-type=dfn data-noexport="" id=origin>origin<a class=self-link href=#origin></a></dfn> is defined in the Origin specification.
<a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc6454 title=biblio-rfc6454>[RFC6454]</a>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=globally-unique-identifier>globally unique identifier<a class=self-link href=#globally-unique-identifier></a></dfn> is defined in section 4 of
the Origin specification. Note that URLs that do not use hierarchical
elements as naming authorities have origins which are globally unique
identifiers. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc6454 title=biblio-rfc6454>[RFC6454]</a></p>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=uri>URI<a class=self-link href=#uri></a></dfn> is defined in the URI specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-uri title=biblio-uri>[URI]</a></p>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=resource-representation>resource representation<a class=self-link href=#resource-representation></a></dfn> is defined
<a href=http://tools.ietf.org/html/rfc7231#section-3>Section 3</a>
of HTTP/1.1 -- Semantics and Content <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc7231 title=biblio-rfc7231>[RFC7231]</a></p>
<p>The terms <dfn data-dfn-type=dfn data-noexport="" id=json-object>JSON object<a class=self-link href=#json-object></a></dfn> and <dfn data-dfn-type=dfn data-noexport="" id=json-stringification>JSON stringification<a class=self-link href=#json-stringification></a></dfn> are
defined in the JSON specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc4627 title=biblio-rfc4627>[RFC4627]</a></p>
<p>The <code><a data-link-type=element href=http://www.w3.org/TR/html5/obsolete.html#the-applet-element title=applet>applet</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#audio title=audio>audio</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element title=img>img</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#the-link-element title=link>link</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/scripting-1.html#script title=script>script</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-source-element title=source>source</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-track-element title=track>track</a></code>, and
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#video title=video>video</a></code> elements are defined in the HTML5
specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-html5 title=biblio-html5>[HTML5]</a></p>
<p>The terms <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#auxiliary-browsing-context title="auxiliary browsing contexts">auxiliary browsing contexts</a>,
<a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#opener-browsing-context title="opener browsing context">opener browsing context</a>, and <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing contexts">nested browsing contexts</a> are
defined in the HTML5 specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-html5 title=biblio-html5>[HTML5]</a></p>
<p>A <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#plugin title=plugin>plugin</a> is defined in the HTML5 specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-html5 title=biblio-html5>[HTML5]</a></p>
<p>The <code><a class="production css-code" data-link-type=at-rule href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face><@font-face></a></code> Cascading Style Sheets (CSS) rule is defined
in the CSS Fonts Module Level 3 specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-css3-fonts title=biblio-css3-fonts>[CSS3-FONTS]</a></p>
<p>The <code>XMLHttpRequest</code> object is defined in the
<code>XMLHttpRequest</code> specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-xmlhttprequest title=biblio-xmlhttprequest>[XMLHTTPREQUEST]</a></p>
<p>The <code>WebSocket</code> object is defined in the <code>WebSocket</code>
specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-websockets title=biblio-websockets>[WEBSOCKETS]</a></p>
<p>The <code>EventSource</code> object is defined in the <code>EventSource</code>
specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-eventsource title=biblio-eventsource>[EVENTSOURCE]</a></p>
<p>The Augmented Backus-Naur Form (ABNF) notation used in this document is
specified in RFC5234. <a data-biblio-type=normative data-link-type=biblio href=#biblio-abnf title=biblio-abnf>[ABNF]</a></p>
<p>This document also uses the ABNF extension "#rule" as defined in
<a href=http://tools.ietf.org/html/rfc7230#section-7>Section 7</a>
of HTTP/1.1 -- Message Syntax and Routing. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc7230 title=biblio-rfc7230>[RFC7230]</a></p>
<p>The following core rules are included by reference, as defined in
<a href=http://tools.ietf.org/html/rfc5234#appendix-B.1>Appendix B.1</a>
of <a data-biblio-type=normative data-link-type=biblio href=#biblio-abnf title=biblio-abnf>[ABNF]</a>: <code>ALPHA</code> (letters), <code>DIGIT</code> (decimal
0-9), <code>WSP</code> (white space) and <code>VCHAR</code> (printing
characters).</p>
<p><dfn data-dfn-type=dfn data-noexport="" id=sha-256>SHA-256<a class=self-link href=#sha-256></a></dfn>, <dfn data-dfn-type=dfn data-noexport="" id=sha-384>SHA-384<a class=self-link href=#sha-384></a></dfn>, and <dfn data-dfn-type=dfn data-noexport="" id=sha-512>SHA-512<a class=self-link href=#sha-512></a></dfn> are the digest
algorithms <a href=http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf>defined by the NIST</a>.</p>
<p>The <dfn data-dfn-type=dfn data-noexport="" id=runs-a-worker>runs a worker<a class=self-link href=#runs-a-worker></a></dfn> algorithm is
<a href=http://www.w3.org/TR/workers/#run-a-worker>defined in the Web
Workers spec</a>. <a data-biblio-type=normative data-link-type=biblio href=#biblio-workers title=biblio-workers>[WORKERS]</a></p>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=callable>callable<a class=self-link href=#callable></a></dfn> refers to an object whose interface
has one or more <dfn data-dfn-type=dfn data-noexport="" id=callers>callers<a class=self-link href=#callers></a></dfn> as defined in the <a href=http://www.w3.org/TR/2010/WD-WebIDL-20101021/#idl-callers>Web
IDL</a> specification <a data-biblio-type=normative data-link-type=biblio href=#biblio-webidl title=biblio-webidl>[WEBIDL]</a>.</p>
<p>An <dfn data-dfn-type=dfn data-noexport="" id=http-200-response>HTTP 200 response<a class=self-link href=#http-200-response></a></dfn> is defined in
<a href=http://tools.ietf.org/html/rfc7231#section-6.3.1>Section 6.3.1</a>
of HTTP/1.1 -- Semantics and Content <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc7231 title=biblio-rfc7231>[RFC7231]</a></p>
</section>
<section>
<h2 class="heading settled heading" data-level=3 id=policy-delivery><span class=secno>3 </span><span class=content>Policy Delivery</span><a class=self-link href=#policy-delivery></a></h2>
<p>The server delivers the policy to the user agent via an HTTP
response header or an HTML <a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a> element. Servers are
informed that requests are subject to a policy via an HTTP request
header.</p>
<section>
<h3 class="heading settled heading" data-level=3.1 id=content-security-policy-header-field><span class=secno>3.1 </span><span class=content>
<code>Content-Security-Policy</code> Header Field
</span><a class=self-link href=#content-security-policy-header-field></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-export="" id=content-security-policy>Content-Security-Policy<a class=self-link href=#content-security-policy></a></dfn></code> header field is
the preferred mechanism for delivering a policy.</p>
<pre>"Content-Security-Policy:" 1#<a data-link-type=dfn href=#policy-token title=policy-token>policy-token</a>
</pre>
<p>For example:</p>
<pre class=example>Content-Security-Policy: script-src 'self'
</pre>
<p>A server MAY send more than one HTTP header field named
<code>Content-Security-Policy</code> with a given resource
representation.</p>
<p>A server MAY send different <code>Content-Security-Policy</code>
header field values with different representations of the same
resource or with different resources.</p>
<p>Upon receiving an HTTP response containing at least one
<code>Content-Security-Policy</code> header field, the user agent
MUST <a data-link-type=dfn href=#enforce title=enforce>enforce</a> each of the policies contained in each such
header field.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.2 id=content-security-policy-report-only-header-field><span class=secno>3.2 </span><span class=content>
<code>Content-Security-Policy-Report-Only</code> Header Field
</span><a class=self-link href=#content-security-policy-report-only-header-field></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-export="" id=content-security-policy-report-only>Content-Security-Policy-Report-Only<a class=self-link href=#content-security-policy-report-only></a></dfn></code>
header field lets servers experiment with policies by monitoring (rather
than enforcing) a policy.</p>
<pre>"Content-Security-Policy-Report-Only:" 1#<a data-link-type=dfn href=#policy-token title=policy-token>policy-token</a>
</pre>
<p>For example, server operators might wish to develop their
security policy iteratively. The operators can deploy a report-only
policy based on their best estimate of how their site behaves:</p>
<pre class=example>Content-Security-Policy-Report-Only: script-src 'self'; report-uri /csp-report-endpoint/
</pre>
<p>If their site violates this policy the user agent will <a data-link-type=dfn href=#send-violation-reports title="send violation reports">send violation
reports</a> to the URI specified in the policy’s <a data-link-type=dfn href=#report-uri title=report-uri>report-uri</a>
directive, but allow the violating resources to load regardless. Once a site
has confidence that the policy is appropriate, they can start enforcing the
policy using the <code><a data-link-type=dfn href=#content-security-policy title=content-security-policy>Content-Security-Policy</a></code> header field.</p>
<p>A server MAY send more than one HTTP header field named
<code>Content-Security-Policy-Report-Only</code> with a given
resource representation.</p>
<p>A server MAY send different
<code>Content-Security-Policy-Report-Only</code> header field values
with different representations of the same resource or with different
resources.</p>
<p>Upon receiving an HTTP response containing at least one
<code>Content-Security-Policy-Report-Only</code> header field, the
user agent MUST <a data-link-type=dfn href=#monitor title=monitor>monitor</a> each of the policies
contained in each such header field.</p>
<p class=note>Note: The <code><a data-link-type=dfn href=#content-security-policy-report-only title=content-security-policy-report-only>Content-Security-Policy-Report-Only</a></code>
header is <em>not</em> supported inside a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.3 id=delivery-html-meta-element><span class=secno>3.3 </span><span class=content>
HTML <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> Element
</span><a class=self-link href=#delivery-html-meta-element></a></h3>
<p>The server MAY supply a policy in an HTML <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element with an <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv title=http-equiv>http-equiv</a></code> attribute that
is a case insensitive match for the string
"<code>Content-Security-Policy</code>". For example:</p>
<pre class=example><meta http-equiv="Content-Security-Policy" content="script-src 'self'">
</pre>
Add the following entry to the
<a href=http://www.w3.org/TR/html5/document-metadata.html#pragma-directives>pragma directives</a>
for the <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element:
<dl>
<dt>
Content security policy
(<code>http-equiv="content-security-policy"</code>)
</dt>
<dd>
<ol>
<li>If the Document’s <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#the-head-element title=head>head</a></code> element is
not an ancestor of the <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element, abort
these steps.</li>
<li>If the <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element lacks a
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-content title=content>content</a></code> attribute, abort these
steps.</li>
<li>Let <var>policy</var> be the value of the
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-content title=content>content</a></code> attribute of the
<code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element.</li>
<li>Let <var>directive-set</var> be the result of
<a data-link-type=dfn href=#parse-the-policy title="parse the policy">parsing <var>policy</var></a>.</li>
<li>Remove all occurrences of <code><a data-link-type=dfn href=#reflected-xss title=reflected-xss>reflected-xss</a></code>,
<code><a data-link-type=dfn href=#report-uri title=report-uri>report-uri</a></code>, and <code><a data-link-type=dfn href=#sandbox title=sandbox>sandbox</a></code>
directives from <var>directive-set</var>.</li>
<li>Enforce each of the <a data-link-type=dfn href=#security-policy-directive title=directives>directives</a> in <var>directive-set</var>,
as <a href=#sec-directives>defined for each directive type</a>.</li>
</ol>
</dd>
</dl>
<p>Authors are <em>strongly encouraged</em> to place the
<code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element as early in the document as
possible to reduce the risk of content injection before a protective
policy can be read and enforced.</p>
<p class=note>Note: A <a data-link-type=dfn href=#security-policy title=policy>policy</a> specified via a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element will be enforced along with any other policies active for the
protected resource, regardless of where they’re specified. The general
mechanism for determining the effect of enforcing multiple policies is
detailed in the <a data-section="" href=#enforcing-multiple-policies>§3.5 Enforcing multiple policies.</a>
section.</p>
<p class=note>Note: Modifications to the <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-content title=content>content</a></code>
attribute of a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element after the
element has been parsed will be ignored.</p>
<p class=note>Note: The <code><a data-link-type=dfn href=#content-security-policy-report-only title=content-security-policy-report-only>Content-Security-Policy-Report-Only</a></code>
header is <em>not</em> supported inside a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.4 id=ch-csp-client-hint><span class=secno>3.4 </span><span class=content>The <code>CH-CSP</code> Client Hint</span><a class=self-link href=#ch-csp-client-hint></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=ch-csp>CH-CSP<a class=self-link href=#ch-csp></a></dfn></code> header field indicates that a particular
request is subject to a <a data-link-type=dfn href=#security-policy title=policy>policy</a>, and its value is defined by the
following ABNF grammar:</p>
<pre>"CH-CSP:" 1#<a data-link-type=dfn href=#hint-value title=hint-value>hint-value</a>
<dfn data-dfn-type=dfn data-noexport="" id=hint-value>hint-value<a class=self-link href=#hint-value></a></dfn> = *WSP "active"
</pre>
<p>If the user agent is <a data-link-type=dfn href=#monitor title=monitoring>monitoring</a> or <a data-link-type=dfn href=#enforce title=enforcing>enforcing</a> a <a data-link-type=dfn href=#security-policy title=policy>policy</a>
that includes directives whose value is a <a data-link-type=dfn href=#source-list0 title="source list">source list</a>, and whose
source list contains the <code>'unsafe-redirect'</code> source expression,
then the user agent MUST send a header field named <code>CH-CSP</code>
along with requests for resources whose <a data-link-type=dfn href=#origin title=origin>origin</a> <em>does not</em>
match the <a data-link-type=dfn href=#protected-resource title="protected resource">protected resource</a>’s origin. The value of this header MUST
be <code>active</code>.</p>
<p>The user agent MAY choose to send this header only if the request is for a
resource type which the active policy would effect. That is, given a policy
of <code>img-src example.com 'unsafe-redirect'</code>, the user agent
would send <code>CH-CSP: active</code> along with requests for images, but
might choose not to send the header with requests for script.</p>
<p class=note>Note: The central reason for including this header is that it hints to a
server that information about redirects might be leaked as a side-effect
of a page’s active policy. If this header is present, a server might decline
to redirect a logged-out user from <code>example.com</code> to
<code>accounts.example.com</code>, for example, as a malicious embedder
might otherwise be able to determine the user’s logged-in status.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.5 id=enforcing-multiple-policies><span class=secno>3.5 </span><span class=content>Enforcing multiple policies.</span><a class=self-link href=#enforcing-multiple-policies></a></h3>
<p><em>This section is not normative.</em></p>
<p>The above sections note that when multiple policies are present,
each must be enforced or reported, according to its type. An example
will help clarify how that ought to work in practice. The behavior of
an <code>XMLHttpRequest</code> might seem unclear given a site
that, for whatever reason, delivered the following HTTP headers:</p>
<pre class=example>Content-Security-Policy: <a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'self' http://example.com http://example.net;
<a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a> 'none';
Content-Security-Policy: <a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a> http://example.com/;
<a data-link-type=dfn href=#script-src title=script-src>script-src</a> http://example.com/
</pre>
<p>Is a connection to <code>example.com</code> allowed or not? The
short answer is that the connection is not allowed. Enforcing both
policies means that a potential connection would have to pass through
both unscathed. Even though the second policy would allow this
connection, the first policy contains <code><a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a>
'none'</code>, so its enforcement blocks the connection. The impact is
that adding additional policies to the list of policies to enforce can
only further restrict the capabilities of the protected resource.</p>
<p>To demonstrate that further, consider a script tag on this page.
The first policy would lock scripts down to <code>'self'</code>,
<code>http://example.com</code> and <code>http://example.net</code>
via the <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a></code> directive. The second, however,
would only allow script from <code>http://example.com/</code>. Script
will only load if it meets both policy’s criteria: in this case, the only
origin that can match is <code>http://example.com</code>, as both
policies allow it.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.6 id=which-policy-applies><span class=secno>3.6 </span><span class=content>Policy applicability</span><a class=self-link href=#which-policy-applies></a></h3>
<p><em>This section is not normative.</em></p>
<p>Policies are associated with an <a data-link-type=dfn href=#protected-resource title="protected resource">protected resource</a>, and
<a data-link-type=dfn href=#enforce title=enforce>enforced</a> or <a data-link-type=dfn href=#monitor title=monitored>monitored</a> for for that resource.
If a resource does not create a new execution context (for example, when
including a script, image, or stylesheet into a document), then any policies
delivered with that resource are discarded without effect. Its execution is
subject to the policy or policies of the including context. The following
table outlines examples of these relationships:</p>
<table>
<thead>
<tr>
<th colspan=2>Resource Type</th>
<th>What <a data-link-type=dfn href=#security-policy title=policy>policy</a> applies?</th>
<tr>
</thead>
<tbody>
<tr class=section>
<th rowspan=2>Top-level Contexts</th>
<td>HTML as a new, top-level browsing context</td>
<td>The policy delivered with the resource</td>
</tr>
<tr>
<td>SVG, as a top-level document</td>
<td>Policy delivered with the resource</td>
</tr>
<tr class=section>
<th rowspan=3>Embedded Contexts</th>
<td>
Any resource included via <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a>,
<a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a>, or <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a>
</td>
<td>
The policy of the embedding resource controls <em>what</em> may be
embedded. The embedded resource, however, is controlled by the
policy delivered with the resource, or the policy of the embedding
resource if the embedded resource is a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique
identifier</a> (or a <a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-srcdoc title=srcdoc>srcdoc</a> frame).
</td>
</tr>
<tr>
<td>SVG, as an embedded document</td>
<td>
The policy delivered with the resource, or policy of the creating
context if created from a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique identifier</a>.
</td>
</tr>
<tr>
<td>
JavaScript, as a Worker, Shared Worker or Service Worker
</td>
<td>
The policy delivered with the resource, or policy of the creating
context if created from a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique identifier</a>
</td>
</tr>
<tr class=section>
<th rowspan=7>Subresources</th>
<td>SVG, inlined via <a data-link-type=element href=http://www.w3.org/TR/svg2/struct.html#elementdef-svg title=svg>svg</a></td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>SVG, as a resource document</td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>HTML via XMLHttpRequest</td>
<td>Policy of the context that performed the fetch</td>
</tr>
<tr>
<td>Image via <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element title=img>img</a> element</td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>JavaScript via a <a data-link-type=element href=http://www.w3.org/TR/html5/scripting-1.html#script title=script>script</a> element</td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>SVG, via <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element title=img>img</a></td>
<td>No policy; should be just as safe as JPG</td>
</tr>
<tr>
<td>SVG, as a WebFont</td>
<td>No policy; should be just as safe as WOFF</td>
</tr>
</tbody>
</table>
</section>
</section>
<section>
<h2 class="heading settled heading" data-level=4 id=syntax-and-algorithms><span class=secno>4 </span><span class=content>Syntax and Algorithms</span><a class=self-link href=#syntax-and-algorithms></a></h2>
<section>
<h3 class="heading settled heading" data-level=4.1 id=policy-syntax><span class=secno>4.1 </span><span class=content>Policy Syntax</span><a class=self-link href=#policy-syntax></a></h3>
<p>A Content Security Policy consists of a U+003B SEMICOLON
(<code>;</code>) delimited list of directives. Each <a data-link-type=dfn href=#security-policy-directive title=directive>directive</a>
consists of a <a data-link-type=dfn href=#directive-name0 title="directive name">directive name</a> and (optionally) a
<a data-link-type=dfn href=#directive-value0 title="directive value">directive value</a>, defined by the following ABNF:</p>
<pre><dfn data-dfn-type=dfn data-noexport="" id=policy-token>policy-token<a class=self-link href=#policy-token></a></dfn> = [ <a data-link-type=dfn href=#directive-token title=directive-token>directive-token</a> *( ";" [ <a data-link-type=dfn href=#directive-token title=directive-token>directive-token</a> ] ) ]
<dfn data-dfn-type=dfn data-noexport="" id=directive-token>directive-token<a class=self-link href=#directive-token></a></dfn> = *WSP [ <a data-link-type=dfn href=#directive-name title=directive-name>directive-name</a> [ WSP <a data-link-type=dfn href=#directive-value title=directive-value>directive-value</a> ] ]
<dfn data-dfn-type=dfn data-noexport="" id=directive-name>directive-name<a class=self-link href=#directive-name></a></dfn> = 1*( ALPHA / DIGIT / "-" )
<dfn data-dfn-type=dfn data-noexport="" id=directive-value>directive-value<a class=self-link href=#directive-value></a></dfn> = *( WSP / <VCHAR except ";" and ","> )
</pre>
<section>
<h4 class="heading settled heading" data-level=4.1.1 id=policy-parsing><span class=secno>4.1.1 </span><span class=content>Parsing Policies</span><a class=self-link href=#policy-parsing></a></h4>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=parse-the-policy>parse the policy<a class=self-link href=#parse-the-policy></a></dfn> <var>policy</var>, the user agent MUST
use an algorithm equivalent to the following:</p>
<ol>
<li>Let the <var>set of directives</var> be the empty set.</li>
<li>For each non-empty token returned by
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#strictly-split-a-string title="strictly split a string">strictly splitting</a>
the string <var>policy</var> on the character U+003B SEMICOLON
(<code>;</code>):
<ol>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#skip-whitespace title="skip whitespace">Skip whitespace</a>.</li>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#collect-a-sequence-of-characters title="collect a sequence of characters">Collect a sequence of characters</a> that are
not <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#space-character title="space characters">space characters</a>. The collected characters
are the <var>directive name</var>.</li>
<li>If there are characters remaining in <var>token</var>,
skip ahead exactly one character (which must be a
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#space-character title="space character">space character</a>).</li>
<li>The remaining characters in <var>token</var> (if any) are
the <var>directive value</var>.</li>
<li>If the <var>set of directives</var> already contains a
directive whose name is a case insensitive match for
<var>directive name</var>, ignore this instance of the directive
and continue to the next token.</li>
<li>Add a <var>directive</var> to the <var>set of
directives</var> with name <var>directive name</var> and value
<var>directive value</var>.</li>
</ol>
</li>
<li>Return the <var>set of directives</var>.
</ol>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=4.2 id=source-list-syntax><span class=secno>4.2 </span><span class=content>Source List Syntax</span><a class=self-link href=#source-list-syntax></a></h3>
<p>Many CSP directives use a value consisting of a <dfn data-dfn-type=dfn data-noexport="" id=source-list0>source
list<a class=self-link href=#source-list0></a></dfn>, defined in the ABNF grammar below.</p>
<p>Each <dfn data-dfn-type=dfn data-noexport="" id=source-expression0>source expression<a class=self-link href=#source-expression0></a></dfn> in the source list represents a
location from which content of the specified type can be retrieved.
For example, the source expression <code>'none'</code> represents
the empty set of URIs, and the source expression
<code>'unsafe-inline'</code> represents content supplied inline in the
resource itself.</p>
<pre><dfn data-dfn-type=dfn data-noexport="" id=source-list>source-list<a class=self-link href=#source-list></a></dfn> = *WSP [ <a data-link-type=dfn href=#source-expression title=source-expression>source-expression</a> *( 1*WSP <a data-link-type=dfn href=#source-expression title=source-expression>source-expression</a> ) *WSP ]
/ *WSP "'none'" *WSP
<dfn data-dfn-type=dfn data-noexport="" id=source-expression>source-expression<a class=self-link href=#source-expression></a></dfn> = <a data-link-type=dfn href=#scheme-source title=scheme-source>scheme-source</a> / <a data-link-type=dfn href=#host-source title=host-source>host-source</a> / <a data-link-type=dfn href=#keyword-source title=keyword-source>keyword-source</a> / <a data-link-type=dfn href=#nonce-source title=nonce-source>nonce-source</a> / <a data-link-type=dfn href=#hash-source title=hash-source>hash-source</a>
<dfn data-dfn-type=dfn data-noexport="" id=scheme-source>scheme-source<a class=self-link href=#scheme-source></a></dfn> = <a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a> ":"
<dfn data-dfn-type=dfn data-noexport="" id=host-source>host-source<a class=self-link href=#host-source></a></dfn> = [ <a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a> "://" ] <a data-link-type=dfn href=#host-part title=host-part>host-part</a> [ <a data-link-type=dfn href=#port-part title=port-part>port-part</a> ] [ <a data-link-type=dfn href=#path-part title=path-part>path-part</a> ]
<dfn data-dfn-type=dfn data-noexport="" id=keyword-source>keyword-source<a class=self-link href=#keyword-source></a></dfn> = "'self'" / "'unsafe-inline'" / "'unsafe-eval'" / "'unsafe-redirect'"
<dfn data-dfn-type=dfn data-noexport="" id=base64-value>base64-value<a class=self-link href=#base64-value></a></dfn> = 1*( ALPHA / DIGIT / "+" / "/" )*2( "=" )
<dfn data-dfn-type=dfn data-noexport="" id=nonce-value>nonce-value<a class=self-link href=#nonce-value></a></dfn> = <a data-link-type=dfn href=#base64-value title=base64-value>base64-value</a>
<dfn data-dfn-type=dfn data-noexport="" id=hash-value>hash-value<a class=self-link href=#hash-value></a></dfn> = <a data-link-type=dfn href=#base64-value title=base64-value>base64-value</a>
<dfn data-dfn-type=dfn data-noexport="" id=nonce-source>nonce-source<a class=self-link href=#nonce-source></a></dfn> = "'nonce-" <a data-link-type=dfn href=#nonce-value title=nonce-value>nonce-value</a> "'"
<dfn data-dfn-type=dfn data-noexport="" id=hash-algo>hash-algo<a class=self-link href=#hash-algo></a></dfn> = "sha256" / "sha384" / "sha512"
<dfn data-dfn-type=dfn data-noexport="" id=hash-source>hash-source<a class=self-link href=#hash-source></a></dfn> = "'" <a data-link-type=dfn href=#hash-algo title=hash-algo>hash-algo</a> "-" <a data-link-type=dfn href=#base64-value title=base64-value>base64-value</a> "'"
<dfn data-dfn-type=dfn data-noexport="" id=scheme-part>scheme-part<a class=self-link href=#scheme-part></a></dfn> = <scheme production from <a href=http://tools.ietf.org/html/rfc3986#section-3.1>RFC 3986, section 3.1</a>>
<dfn data-dfn-type=dfn data-noexport="" id=host-part>host-part<a class=self-link href=#host-part></a></dfn> = "*" / [ "*." ] 1*<a data-link-type=dfn href=#host-char title=host-char>host-char</a> *( "." 1*<a data-link-type=dfn href=#host-char title=host-char>host-char</a> )
<dfn data-dfn-type=dfn data-noexport="" id=host-char>host-char<a class=self-link href=#host-char></a></dfn> = ALPHA / DIGIT / "-"
<dfn data-dfn-type=dfn data-noexport="" id=path-part>path-part<a class=self-link href=#path-part></a></dfn> = <path production from <a href=http://tools.ietf.org/html/rfc3986#section-3.3>RFC 3986, section 3.3</a>>
<dfn data-dfn-type=dfn data-noexport="" id=port-part>port-part<a class=self-link href=#port-part></a></dfn> = ":" ( 1*DIGIT / "*" )
</pre>
<p>If the policy contains a <code><a data-link-type=dfn href=#nonce-source title=nonce-source>nonce-source</a></code> expression, the
server MUST generate a fresh value for the <code><a data-link-type=dfn href=#nonce-value title=nonce-value>nonce-value</a></code>
directive at random and independently each time it transmits a policy.
This requirement ensures that the <code><a data-link-type=dfn href=#nonce-value title=nonce-value>nonce-value</a></code> is
difficult for an attacker to predict.</p>
<p>The <code><a data-link-type=dfn href=#host-char title=host-char>host-char</a></code> production intentionally contains only
ASCII characters; internationalized domain names cannot be entered
directly into a policy string, but instead MUST be Punycode-encoded
<a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc3492 title=biblio-rfc3492>[RFC3492]</a>. For example, the domain <code>üüüüüü.de</code> would be
encoded as <code>xn--tdaaaaaa.de</code>.</p>
<section>
<h4 class="heading settled heading" data-level=4.2.1 id=source-list-parsing><span class=secno>4.2.1 </span><span class=content>Parsing Source Lists</span><a class=self-link href=#source-list-parsing></a></h4>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=parse-a-source-list>parse a source list<a class=self-link href=#parse-a-source-list></a></dfn>
<var>source list</var>, the user agent MUST use an algorithm
equivalent to the following:</p>
<ol>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace title="strip leading and trailing whitespace">Strip leading and trailing whitespace</a> from
<var>source list</var>.</li>
<li>If <var>source list</var> is a case insensitive match
for the string <code>'none'</code> (including the quotation
marks), return the empty set.</li>
<li>Let <var>set of source expressions</var> be the empty
set.</li>
<li>For each token returned by
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-spaces title="split a string on spaces">splitting <var>source
list</var> on spaces</a>, if the token matches the grammar for
<code><a data-link-type=dfn href=#source-expression title=source-expression>source-expression</a></code>, add the token to the <var>set
of source expressions</var>.</li>
<li>Return the <var>set of source expressions</var>.</li>
</ol>
<p class=note>Note: Characters like U+003B SEMICOLON (<code>;</code>) and
U+002C COMMA (<code>,</code>) cannot appear in source expressions
directly: if you’d like to include these characters in a source
expression, they must be <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#percent-encode title="percent encode">percent
encoded</a> as <code>%3B</code> and <code>%2C</code> respectively.</p>
</section>
<section>
<h4 class="heading settled heading" data-level=4.2.2 id=match-source-expression><span class=secno>4.2.2 </span><span class=content>Matching Source Expressions</span><a class=self-link href=#match-source-expression></a></h4>
<p>A URI is said to <dfn data-dfn-type=dfn data-noexport="" id=match-a-source-expression>match a source expression<a class=self-link href=#match-a-source-expression></a></dfn> if the following
algorithm returns <em>does match</em>:</p>
<ol>
<li>Normalize the URI according to
<a href=http://tools.ietf.org/html/rfc3986#section-6>Section 6 of
RFC3986</a>.</li>
<li>If the source expression a consists of a single U+002A ASTERISK
character (<code>*</code>), and the URI’s scheme is not of a type
designating a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique identifier</a>, (such as
<code>blob:</code>, <code>data:</code>, or <code>filesystem:</code>)
then return <em>does match</em>.</li>
<li>If the source expression matches the grammar for
<code><a data-link-type=dfn href=#scheme-source title=scheme-source>scheme-source</a></code>:
<ol>
<li>If the URI’s scheme is a case-insensitive match for the
source expression’s <code><a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a></code>, return
<em>does match</em>.</li>
<li>Otherwise, return <em>does not match</em>.</li>
</ol>
</li>
<li>If the source expression matches the grammar for
<code><a data-link-type=dfn href=#host-source title=host-source>host-source</a></code>:
<ol>
<li>If the URI does <strong>not</strong> contain a host, then
return <em>does not match</em>.</li>
<li>Let <var>uri-scheme</var>, <var>uri-host</var>, and
<var>uri-port</var> be the scheme, host, and port of the URI,
respectively. If the URI does not have a port, then let
<var>uri-port</var> be the default port for
<var>uri-scheme</var>. Let <var>uri-path</var> be
the path of the URI after
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#percent-decode title="percent decode">decoding
percent-encoded characters</a>. If the URI does not have a
path, then let <var>uri-path</var> be the U+002F SOLIDUS
character (<code>/</code>).</li>
<li>If the source expression has a <code><a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a></code>
that is not a case insensitive match for <var>uri-scheme</var>,
then return <em>does not match</em>.</li>
<li>If the source expression does <strong>not</strong> have a
scheme, return <em>does not match</em> if
<ol>
<li>the scheme of the protected resource’s URI is a case
insensitive match for <code>HTTP</code>, and
<var>uri-scheme</var> is <strong>not</strong> a case
insensitive match for either <code>HTTP</code> or
<code>HTTPS</code></li>
<li>the scheme of the protected resource’s URI is
<strong>not</strong> a case insensitive match for
<code>HTTP</code>, and <var>uri-scheme</var> is
<strong>not</strong> a case insensitive match
for the scheme of the protected resource’s URI.</li>
</ol>
</li>
<li>If the first character of the source expression’s
<code><a data-link-type=dfn href=#host-part title=host-part>host-part</a></code> is an U+002A ASTERISK character
(<code>*</code>) and the remaining characters, including the
leading U+002E FULL STOP character (<code>.</code>), are not a
case insensitive match for the rightmost characters of
<var>uri-host</var>, then return <em>does not match</em>.</li>
<li>If the first character of the source expression’s
<code><a data-link-type=dfn href=#host-part title=host-part>host-part</a></code> is <em>not</em> an U+002A ASTERISK
character (<code>*</code>) and <var>uri-host</var> is not a
case insensitive match for the source expression’s
<code><a data-link-type=dfn href=#host-part title=host-part>host-part</a></code>, then return <em>does not
match</em>.</li>
<li>If the source expression does <strong>not</strong> contain
a <code>port-part</code> and <var>uri-port</var> is not the
default port for <var>uri-scheme</var>, then return <em>does not
match</em>.</li>
<li>If the source expression does contain a
<code>port-part</code>, then return <em>does not match</em> if
<ol>
<li><code><a data-link-type=dfn href=#port-part title=port-part>port-part</a></code> does <strong>not</strong>
contain an U+002A ASTERISK character (<code>*</code>),
and</li>
<li><code><a data-link-type=dfn href=#port-part title=port-part>port-part</a></code> does <strong>not</strong>
represent the same number as <var>uri-port</var>.</li>
</ol>
</li>
<li>If the source expression contains a non-empty
<code><a data-link-type=dfn href=#path-part title=path-part>path-part</a></code>, and the URI is <em>not</em> the
result of a redirect, then:
<ol>
<li>Let <var>decoded-path</var> be the result of
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#percent-decode title="percent decode">decoding
<code>path-part</code>’s percent-encoded characters</a>.</li>
<li>If the final character of <var>decoded-path</var> is
the U+002F SOLIDUS character (<code>/</code>), and
<var>decoded-path</var> is not a prefix of
<var>uri-path</var>, then return <em>does not
match</em>.</li>
<li>If the final character of <var>decoded-path</var> is
not the the U+002F SOLIDUS character (<code>/</code>),
and <var>decoded-path</var> is not an exact match for
<var>uri-path</var> then return <em>does not
match</em>.</li>
</ol>
</li>
<li>Otherwise, return <em>does match</em>.</li>
</ol>
</li>
<li>If the source expression is a case insensitive
match for <code>'self'</code> (including the quotation marks),
then:
<ol>
<li>Return <em>does match</em> if the URI has the same scheme,
host, and port as the protected resource’s URI (using the
default port for the appropriate scheme if either or both URIs
are missing ports).</li>
</ol>
</li>
<li>Otherwise, return <em>does not match</em>.</li>
</ol>
<p>A URI is said to <dfn data-dfn-type=dfn data-noexport="" id=match-a-source-list>match a source list<a class=self-link href=#match-a-source-list></a></dfn> if the following
conditions are met:</p>
<ol>
<li>
The URI <a data-link-type=dfn href=#match-a-source-expression title="match a source expression">matches at least one
source expression</a> in the set of source expressions obtained by
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the source list</a>.
</li>