-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathindex.html
2637 lines (2614 loc) · 259 KB
/
index.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">
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
<meta content="Bikeshed 1.0.0" name="generator">
<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" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2016-04-25">25 April 2016</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="https://w3c.github.io/webappsec/specs/CSP2/">https://w3c.github.io/webappsec/specs/CSP2/</a>
<dt>Latest version:
<dd><a href="http://www.w3.org/TR/CSP2/">http://www.w3.org/TR/CSP2/</a>
<dt>Previous Versions:
<dd><a href="http://www.w3.org/TR/2014/WD-CSP2-20140703/" rel="previous">http://www.w3.org/TR/2014/WD-CSP2-20140703/</a>
<dd><a href="http://www.w3.org/TR/2014/WD-CSP11-20140211/" rel="previous">http://www.w3.org/TR/2014/WD-CSP11-20140211/</a>
<dd><a href="http://www.w3.org/TR/2012/CR-CSP-20121115/" rel="previous">http://www.w3.org/TR/2012/CR-CSP-20121115/</a>
<dt>Feedback:
<dd><span><a href="mailto:[email protected]?subject=%5BCSP2%5D%20YOUR%20TOPIC%20HERE">[email protected]</a> with subject line “<kbd>[CSP2] <var>… message topic …</var></kbd>” (<a href="http://lists.w3.org/Archives/Public/public-webappsec/" rel="discussion">archives</a>)</span>
<dt>Issue Tracking:
<dd><a href="https://github.com/w3c/webappsec/issues/">GitHub</a>
<dt class="editor">Editors:
<dd class="editor p-author h-card vcard" data-editor-id="56384"><a class="p-name fn u-email email" href="mailto:[email protected]">Mike West</a> (<span class="p-org org">Google Inc.</span>)
<dd class="editor p-author h-card vcard" data-editor-id="39502"><a class="p-name fn u-email email" href="mailto:[email protected]">Adam Barth</a> (<span class="p-org org">Google Inc.</span>)
<dd class="editor p-author h-card vcard" data-editor-id="41156"><a class="p-name fn u-email email" href="mailto:[email protected]">Dan Veditz</a> (<span class="p-org org">Mozilla Corporation</span>)
<dt>Former Editors:
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:[email protected]">Brandon Sterne</a> (<span class="p-org org">formerly of Mozilla Corporation</span>)
</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> © 2015 <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>). W3C <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" id="abstract"><span class="content">Abstract</span></h2>
<div 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>
</div>
<h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
<div data-fill-with="status">
<p> This is a public copy of the editors’ draft.
It is provided for discussion only and may change at any moment.
Its publication here does not imply endorsement of its contents by W3C.
Don’t cite this document other than as work in progress. </p>
<p> <strong>Changes to this document may be tracked at <a href="https://github.com/w3c/webappsec">https://github.com/w3c/webappsec</a>.</strong> </p>
<p> The (<a href="http://lists.w3.org/Archives/Public/public-webappsec/">archived</a>) public mailing list <a href="mailto:[email protected]?Subject=%5BCSP2%5D%20PUT%20SUBJECT%20HERE">[email protected]</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 “CSP2” in the subject,
preferably like this:
“[CSP2] <em>…summary of comment…</em>” </p>
<p> This document was produced by the <a href="http://www.w3.org/2011/webappsec/">Web Application Security Working Group</a>. </p>
<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/49309/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>
<p> This document is governed by the <a href="http://www.w3.org/2014/Process-20140801/" id="w3c_process_revision">1 August 2014 W3C Process Document</a>. </p>
<p></p>
</div>
<div data-fill-with="at-risk"></div>
<h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="content">Table of Contents</span></h2>
<div data-fill-with="table-of-contents" role="navigation">
<ul class="toc" role="directory">
<li>
<a href="#intro"><span class="secno">1</span> <span class="content">Introduction</span></a>
<ul class="toc">
<li><a href="#changes-from-level-1"><span class="secno">1.1</span> <span class="content">Changes from Level 1</span></a>
</ul>
<li>
<a href="#key-concepts"><span class="secno">2</span> <span class="content">Key Concepts and Terminology</span></a>
<ul class="toc">
<li><a href="#terms-defined-here"><span class="secno">2.1</span> <span class="content">Terms defined by this specification</span></a>
<li><a href="#terms-defined-by-reference"><span class="secno">2.2</span> <span class="content">Terms defined by reference</span></a>
<li><a href="#html-concepts"><span class="secno">2.3</span> <span class="content">Relevant Concepts from HTML</span></a>
<li><a href="#grammar"><span class="secno">2.4</span> <span class="content">Grammatical Concepts</span></a>
</ul>
<li>
<a href="#policy-delivery"><span class="secno">3</span> <span class="content">Policy Delivery</span></a>
<ul class="toc">
<li><a href="#content-security-policy-header-field"><span class="secno">3.1</span> <span class="content"> <code>Content-Security-Policy</code> Header Field </span></a>
<li><a href="#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>
<li><a href="#delivery-html-meta-element"><span class="secno">3.3</span> <span class="content"> HTML <code><span>meta</span></code> Element </span></a>
<li><a href="#enforcing-multiple-policies"><span class="secno">3.4</span> <span class="content">Enforcing multiple policies</span></a>
<li><a href="#which-policy-applies"><span class="secno">3.5</span> <span class="content">Policy applicability</span></a>
</ul>
<li>
<a href="#syntax-and-algorithms"><span class="secno">4</span> <span class="content">Syntax and Algorithms</span></a>
<ul class="toc">
<li>
<a href="#policy-syntax"><span class="secno">4.1</span> <span class="content">Policy Syntax</span></a>
<ul class="toc">
<li><a href="#policy-parsing"><span class="secno">4.1.1</span> <span class="content">Parsing Policies</span></a>
</ul>
<li>
<a href="#source-list-syntax"><span class="secno">4.2</span> <span class="content">Source List Syntax</span></a>
<ul class="toc">
<li><a href="#source-list-parsing"><span class="secno">4.2.1</span> <span class="content">Parsing Source Lists</span></a>
<li>
<a href="#match-source-expression"><span class="secno">4.2.2</span> <span class="content">Matching Source Expressions</span></a>
<ul class="toc">
<li><a href="#source-list-guid-matching"><span class="secno">4.2.2.1</span> <span class="content"> Security Considerations for GUID URL schemes </span></a>
<li><a href="#source-list-path-patching"><span class="secno">4.2.2.2</span> <span class="content">Path Matching</span></a>
<li><a href="#source-list-paths-and-redirects"><span class="secno">4.2.2.3</span> <span class="content">Paths and Redirects</span></a>
</ul>
<li><a href="#script-src-the-nonce-attribute"><span class="secno">4.2.3</span> <span class="content"> The <code>nonce</code> attribute </span></a>
<li><a href="#source-list-valid-nonces"><span class="secno">4.2.4</span> <span class="content">Valid Nonces</span></a>
<li><a href="#source-list-valid-hashes"><span class="secno">4.2.5</span> <span class="content">Valid Hashes</span></a>
</ul>
<li>
<a href="#media-type-list-syntax"><span class="secno">4.3</span> <span class="content">Media Type List Syntax</span></a>
<ul class="toc">
<li><a href="#media-type-list-parsing"><span class="secno">4.3.1</span> <span class="content">Parsing</span></a>
<li><a href="#media-type-list-matching"><span class="secno">4.3.2</span> <span class="content">Matching</span></a>
</ul>
<li><a href="#violation-reports"><span class="secno">4.4</span> <span class="content">Reporting</span></a>
</ul>
<li>
<a href="#processing-model"><span class="secno">5</span> <span class="content">Processing Model</span></a>
<ul class="toc">
<li><a href="#processing-model-workers"><span class="secno">5.1</span> <span class="content">Workers</span></a>
<li><a href="#processing-model-iframe-srcdoc"><span class="secno">5.2</span> <span class="content"><code>srcdoc</code> iframes</span></a>
</ul>
<li>
<a href="#script-interfaces"><span class="secno">6</span> <span class="content">Script Interfaces</span></a>
<ul class="toc">
<li><a href="#securitypolicyviolationevent-interface"><span class="secno">6.1</span> <span class="content"> <code>SecurityPolicyViolationEvent</code> Interface </span></a>
<li><a href="#securitypolicyviolationeventinit-interface"><span class="secno">6.2</span> <span class="content"> <code>SecurityPolicyViolationEventInit</code> Interface </span></a>
<li><a href="#firing-securitypolicyviolationevent-events"><span class="secno">6.3</span> <span class="content">Firing Violation Events</span></a>
</ul>
<li>
<a href="#directives"><span class="secno">7</span> <span class="content">Directives</span></a>
<ul class="toc">
<li><a href="#directive-base-uri"><span class="secno">7.1</span> <span class="content"><code>base-uri</code></span></a>
<li>
<a href="#directive-child-src"><span class="secno">7.2</span> <span class="content"><code>child-src</code></span></a>
<ul class="toc">
<li><a href="#directive-child-src-nested"><span class="secno">7.2.1</span> <span class="content">Nested Browsing Contexts</span></a>
<li><a href="#directive-child-src-workers"><span class="secno">7.2.2</span> <span class="content">Workers</span></a>
</ul>
<li>
<a href="#directive-connect-src"><span class="secno">7.3</span> <span class="content"><code>connect-src</code></span></a>
<ul class="toc">
<li><a href="#connect-src-usage"><span class="secno">7.3.1</span> <span class="content">Usage</span></a>
</ul>
<li>
<a href="#directive-default-src"><span class="secno">7.4</span> <span class="content"><code>default-src</code></span></a>
<ul class="toc">
<li><a href="#default-src-usage"><span class="secno">7.4.1</span> <span class="content">Usage</span></a>
</ul>
<li><a href="#directive-font-src"><span class="secno">7.5</span> <span class="content"><code>font-src</code></span></a>
<li><a href="#directive-form-action"><span class="secno">7.6</span> <span class="content"><code>form-action</code></span></a>
<li>
<a href="#directive-frame-ancestors"><span class="secno">7.7</span> <span class="content"><code>frame-ancestors</code></span></a>
<ul class="toc">
<li><a href="#frame-ancestors-and-frame-options"><span class="secno">7.7.1</span> <span class="content"> Relation to <code>X-Frame-Options</code> </span></a>
<li><a href="#frame-ancestors-multiple-source-values"><span class="secno">7.7.2</span> <span class="content">Multiple Host Source Values</span></a>
</ul>
<li><a href="#directive-frame-src"><span class="secno">7.8</span> <span class="content"><code>frame-src</code></span></a>
<li><a href="#directive-img-src"><span class="secno">7.9</span> <span class="content"><code>img-src</code></span></a>
<li><a href="#directive-media-src"><span class="secno">7.10</span> <span class="content"><code>media-src</code></span></a>
<li><a href="#directive-object-src"><span class="secno">7.11</span> <span class="content"><code>object-src</code></span></a>
<li>
<a href="#directive-plugin-types"><span class="secno">7.12</span> <span class="content"><code>plugin-types</code></span></a>
<ul class="toc">
<li><a href="#plugin-types-usage"><span class="secno">7.12.1</span> <span class="content">Usage</span></a>
<li><a href="#plugin-types-predeclaration"><span class="secno">7.12.2</span> <span class="content"> Predeclaration of expected media types </span></a>
</ul>
<li><a href="#directive-report-uri"><span class="secno">7.13</span> <span class="content"><code>report-uri</code></span></a>
<li>
<a href="#directive-sandbox"><span class="secno">7.14</span> <span class="content"><code>sandbox</code></span></a>
<ul class="toc">
<li><a href="#sandboxing-and-workers"><span class="secno">7.14.1</span> <span class="content">Sandboxing and Workers</span></a>
<li><a href="#sandbox-usage"><span class="secno">7.14.2</span> <span class="content">Usage</span></a>
</ul>
<li>
<a href="#directive-script-src"><span class="secno">7.15</span> <span class="content"><code>script-src</code></span></a>
<ul class="toc">
<li><a href="#script-src-nonce-usage"><span class="secno">7.15.1</span> <span class="content"> Nonce usage for <code><span>script</span></code> elements </span></a>
<li><a href="#script-src-hash-usage"><span class="secno">7.15.2</span> <span class="content"> Hash usage for <code><span>script</span></code> elements </span></a>
</ul>
<li>
<a href="#directive-style-src"><span class="secno">7.16</span> <span class="content"><code>style-src</code></span></a>
<ul class="toc">
<li><a href="#style-src-nonce-usage"><span class="secno">7.16.1</span> <span class="content"> Nonce usage for <code><span>style</span></code> elements </span></a>
<li><a href="#style-src-hash-usage"><span class="secno">7.16.2</span> <span class="content"> Hash usage for <code><span>style</span></code> elements </span></a>
</ul>
</ul>
<li>
<a href="#examples"><span class="secno">8</span> <span class="content">Examples</span></a>
<ul class="toc">
<li><a href="#example-policies"><span class="secno">8.1</span> <span class="content">Sample Policy Definitions</span></a>
<li><a href="#example-violation-report"><span class="secno">8.2</span> <span class="content">Sample Violation Report</span></a>
</ul>
<li>
<a href="#security-considerations"><span class="secno">9</span> <span class="content">Security Considerations</span></a>
<ul class="toc">
<li><a href="#security-css-parsing"><span class="secno">9.1</span> <span class="content">Cascading Style Sheet (CSS) Parsing</span></a>
<li><a href="#security-redirects"><span class="secno">9.2</span> <span class="content">Redirect Information Leakage</span></a>
</ul>
<li>
<a href="#implementation-considerations"><span class="secno">10</span> <span class="content">Implementation Considerations</span></a>
<ul class="toc">
<li><a href="#complications"><span class="secno">10.1</span> <span class="content">Processing Complications</span></a>
</ul>
<li>
<a href="#iana-considerations"><span class="secno">11</span> <span class="content">IANA Considerations</span></a>
<ul class="toc">
<li><a href="#iana-content-security-policy"><span class="secno">11.1</span> <span class="content">Content-Security-Policy</span></a>
<li><a href="#iana-content-security-policy-report-only"><span class="secno">11.2</span> <span class="content">Content-Security-Policy-Report-Only</span></a>
</ul>
<li><a href="#acknowledgements"><span class="secno">12</span> <span class="content">Acknowledgements</span></a>
<li>
<a href="#conformance"><span class="secno"></span> <span class="content">Conformance</span></a>
<ul class="toc">
<li><a href="#conventions"><span class="secno"></span> <span class="content">Document conventions</span></a>
<li><a href="#conformant-algorithms"><span class="secno"></span> <span class="content">Conformant Algorithms</span></a>
<li><a href="#conformance-classes"><span class="secno"></span> <span class="content">Conformance Classes</span></a>
</ul>
<li>
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ul class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
<li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
</ul>
<li>
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ul class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
</ul>
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
</ul>
</div>
<main>
<section>
<h2 class="heading settled" 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>
<h3 class="heading settled" data-level="1.1" id="changes-from-level-1"><span class="secno">1.1. </span><span class="content">Changes from Level 1</span><a class="self-link" href="#changes-from-level-1"></a></h3>
<p>This document describes an evolution of the <a href="http://www.w3.org/TR/CSP/">Content Security Policy specification</a>.
Level 2 makes two breaking changes from Level 1, and adds support for a number
of new directives and capabilities which are summarized below:</p>
<ol>
<li>
The following changes are backwards incompatible with the majority of
user agent’s implementations of Level 2:
<ol>
<li>
The path component of a source expression is now ignored if the
resource being loaded is the result of a redirect, as described in <a href="#source-list-paths-and-redirects">§4.2.2.3 Paths and Redirects</a>.
<p class="note" role="note">Note: Paths are technically new in Level 2, but they were already
implemented in many user agents before this revision of CSP was
completed, so noting the change here seems reasonable.</p>
<li> A <a data-link-type="dfn" href="#protected-resource">protected resource</a>’s ability to load Workers <a data-link-type="biblio" href="#biblio-workers">[WORKERS]</a> is now controlled via <a data-link-type="dfn" href="#child_src"><code>child-src</code></a> rather than <a data-link-type="dfn" href="#script_src"><code>script-src</code></a>.
<li> Workers now have their own policy, separate from the <a data-link-type="dfn" href="#protected-resource">protected
resource</a> which loaded them. This is described in <a href="#processing-model-workers">§5.1 Workers</a>.
</ol>
<li>
The following directives are brand new in this revision:
<ol>
<li> <a data-link-type="dfn" href="#base_uri"><code>base-uri</code></a> controls the <a data-link-type="dfn" href="#protected-resource">protected
resource</a>’s ability to specify the <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#document-base-url">document base
URL</a>.
<li> <a data-link-type="dfn" href="#child_src"><code>child-src</code></a> deprecates and replaces <a data-link-type="dfn" href="#frame_src"><code>frame-src</code></a>, controlling the <a data-link-type="dfn" href="#protected-resource">protected
resource</a>’s ability to embed frames, and to load Workers.
<li> <a data-link-type="dfn" href="#form_action"><code>form-action</code></a> controls the <a data-link-type="dfn" href="#protected-resource">protected
resource</a>’s ability to submit forms.
<li> <a data-link-type="dfn" href="#frame_ancestors"><code>frame-ancestors</code></a> controls the <a data-link-type="dfn" href="#protected-resource">protected
resource</a>’s ability be embedded in other documents. It is meant
to supplant the <code>X-Frame-Options</code> HTTP request header. <a data-link-type="biblio" href="#biblio-rfc7034">[RFC7034]</a>
<li> <a data-link-type="dfn" href="#plugin_types"><code>plugin-types</code></a> controls the <a data-link-type="dfn" href="#protected-resource">protected
resource</a>’s ability to load specific types of plugins.
</ol>
<li> Individual inline scripts and stylesheets may be whitelisted via nonces
(as described in <a href="#source-list-valid-nonces">§4.2.4 Valid Nonces</a>) and hashes (as described
in <a href="#source-list-valid-hashes">§4.2.5 Valid Hashes</a>).
<li> A <code class="idl"><a data-link-type="idl" href="#securitypolicyviolationevent">SecurityPolicyViolationEvent</a></code> is fired upon violations, as described
in <a href="#firing-securitypolicyviolationevent-events">§6.3 Firing Violation Events</a>.
<li> A number of new fields were added to violation reports (both those POSTED
via <a data-link-type="dfn" href="#report_uri"><code>report-uri</code></a>, and those handed to the DOM via <code class="idl"><a data-link-type="idl" href="#securitypolicyviolationevent">SecurityPolicyViolationEvent</a></code> events. These include <code class="idl"><a data-link-type="idl" href="#dom-securitypolicyviolationevent-effectivedirective">effectiveDirective</a></code>, <code class="idl"><a data-link-type="idl" href="#dom-securitypolicyviolationevent-statuscode">statusCode</a></code>, <code class="idl"><a data-link-type="idl" href="#dom-securitypolicyviolationevent-sourcefile">sourceFile</a></code>, <code class="idl"><a data-link-type="idl" href="#dom-securitypolicyviolationevent-linenumber">lineNumber</a></code>, and <code class="idl"><a data-link-type="idl" href="#dom-securitypolicyviolationevent-columnnumber">columnNumber</a></code>.
<li> Certain flags present in the <code><a data-link-type="dfn" href="#sandbox">sandbox</a></code> directive now
affect Worker creation, as described in <a href="#sandboxing-and-workers">§7.14.1 Sandboxing and Workers</a>.
</ol>
</section>
<section>
<h2 class="heading settled" 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>
<h3 class="heading settled" data-level="2.1" id="terms-defined-here"><span class="secno">2.1. </span><span class="content">Terms defined by this specification</span><a class="self-link" href="#terms-defined-here"></a></h3>
<dl>
<dt> <dfn data-dfn-type="dfn" data-export="" data-local-lt="policy" id="security-policy">security policy<a class="self-link" href="#security-policy"></a></dfn>
<dt> <dfn data-dfn-type="dfn" data-export="" data-local-lt="directive" id="security-policy-directive">security policy directive<a class="self-link" href="#security-policy-directive"></a></dfn>
<dt> <dfn data-dfn-type="dfn" data-export="" data-local-lt="directive name" id="security-policy-directive-name">security policy directive name<a class="self-link" href="#security-policy-directive-name"></a></dfn>
<dt> <dfn data-dfn-type="dfn" data-export="" data-local-lt="directive value" id="security-policy-directive-value">security policy directive value<a class="self-link" href="#security-policy-directive-value"></a></dfn>
<dd>
A <strong>security policy</strong> refers to both a set of security
preferences for restrictions within which content can operate, and
to a fragment of text that codifies or transmits these preferences.
For example, the following string is a policy which restricts script
and object content:
<div class="example" id="example-f8c8229d"><a class="self-link" href="#example-f8c8229d"></a> <code><a data-link-type="dfn" href="#script_src">script-src</a> 'self'; <a data-link-type="dfn" href="#object_src">object-src</a> 'none'</code> </div>
<p>Security policies contain a set of <strong>security policy
directives</strong> (<code><a data-link-type="dfn" href="#script_src">script-src</a></code> and <code><a data-link-type="dfn" href="#object_src">object-src</a></code> in the example above), each responsible
for declaring the restrictions for a particular resource type, or
manipulating a specific aspect of the policy’s restrictions. The list
of directives defined by this specification can be found in <a href="#directives">§7 Directives</a>.</p>
<p>Each directives has a <strong>name</strong> and a <strong>value</strong>; <strong>value</strong> may be optional for some directives.
A detailed grammar can be found in <a href="#syntax-and-algorithms">§4 Syntax and Algorithms</a>.</p>
<dt> <dfn data-dfn-type="dfn" data-export="" id="protected-resource">protected resource<a class="self-link" href="#protected-resource"></a></dfn>
<dd> A <a data-link-type="dfn" href="#security-policy">security policy</a> is applied by a user agent to a specific <a data-link-type="dfn" href="#resource-representation">resource representation</a>, known as the <strong>protected
resource</strong>. See <a href="#policy-delivery">§3 Policy Delivery</a> for details regarding
the mechanisms by which policies may be applied to a protected
resource.
</dl>
<h3 class="heading settled" data-level="2.2" id="terms-defined-by-reference"><span class="secno">2.2. </span><span class="content">Terms defined by reference</span><a class="self-link" href="#terms-defined-by-reference"></a></h3>
<dl>
<dt> <dfn data-dfn-type="dfn" data-noexport="" id="globally-unique-identifier">globally unique identifier<a class="self-link" href="#globally-unique-identifier"></a></dfn>
<dd>
Defined in <a href="https://tools.ietf.org/html/rfc6454#section-2.3">Section 2.3 of
the Origin specification</a>. <a data-link-type="biblio" href="#biblio-rfc6454">[RFC6454]</a>
<p class="note" role="note">NOTE: URLs which do not use hierarchical elements as naming authorities
(<code>data:</code>, for instance) have <a data-link-type="dfn" href="#origin">origins</a> which are globally
unique identifiers.</p>
<dt> <dfn data-dfn-type="dfn" data-noexport="" id="http-200-response">HTTP 200 response<a class="self-link" href="#http-200-response"></a></dfn>
<dd> Defined in <a href="https://tools.ietf.org/html/rfc7231#section-6.3.1">Section
6.3.1 of HTTP/1.1 -- Semantics and Content</a>. <a data-link-type="biblio" href="#biblio-rfc7231">[RFC7231]</a>
<dt> <dfn data-dfn-type="dfn" data-noexport="" id="json-object">JSON object<a class="self-link" href="#json-object"></a></dfn>
<dt> <dfn data-dfn-type="dfn" data-noexport="" id="json-stringification">JSON stringification<a class="self-link" href="#json-stringification"></a></dfn>
<dd> Defined in the JSON specification. <a data-link-type="biblio" href="#biblio-rfc4627">[RFC4627]</a>
<dt> <dfn data-dfn-type="dfn" data-noexport="" id="origin">origin<a class="self-link" href="#origin"></a></dfn>
<dd> Defined by the Origin specification. <a data-link-type="biblio" href="#biblio-rfc6454">[RFC6454]</a>
<dt> <dfn data-dfn-type="dfn" data-local-lt="representation" data-noexport="" id="resource-representation">resource representation<a class="self-link" href="#resource-representation"></a></dfn>
<dd> Defined in <a href="https://tools.ietf.org/html/rfc7231#section-3">Section
3 of HTTP/1.1 -- Semantics and Content</a>. <a data-link-type="biblio" href="#biblio-rfc7231">[RFC7231]</a>
<dt> <dfn data-dfn-type="dfn" data-noexport="" id="url">URL<a class="self-link" href="#url"></a></dfn>
<dd> Defined by <a data-link-type="biblio" href="#biblio-url">[URL]</a>.
<dt><dfn data-dfn-type="dfn" data-noexport="" id="sha_256">SHA-256<a class="self-link" href="#sha_256"></a></dfn>
<dt><dfn data-dfn-type="dfn" data-noexport="" id="sha_384">SHA-384<a class="self-link" href="#sha_384"></a></dfn>
<dt><dfn data-dfn-type="dfn" data-noexport="" id="sha_512">SHA-512<a class="self-link" href="#sha_512"></a></dfn>
<dd> These digest algorithms are defined by the NIST. <a data-link-type="biblio" href="#biblio-fips180">[FIPS180]</a>
</dl>
<h3 class="heading settled" data-level="2.3" id="html-concepts"><span class="secno">2.3. </span><span class="content">Relevant Concepts from HTML</span><a class="self-link" href="#html-concepts"></a></h3>
<p>The <code><a data-link-type="element" href="http://www.w3.org/TR/html5/obsolete.html#the-applet-element">applet</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-audio-element">audio</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element">embed</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element">img</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-link-element">link</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element">object</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-source-element">source</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-track-element">track</a></code>, and <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-video-element">video</a></code> are defined in <a data-link-type="biblio" href="#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">auxiliary browsing contexts</a>, <a data-link-type="dfn" href="http://www.w3.org/TR/html5/browsers.html#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">nested browsing contexts</a> are
defined in the HTML5 specification. <a data-link-type="biblio" href="#biblio-html5">[HTML5]</a></p>
<p>A <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#plugin">plugin</a> is defined in the HTML5 specification. <a data-link-type="biblio" href="#biblio-html5">[HTML5]</a></p>
<p>The <code><<@font-face>></code> Cascading Style Sheets (CSS) rule is defined
in the CSS Fonts Module Level 3 specification. <a data-link-type="biblio" href="#biblio-css3-fonts">[CSS3-FONTS]</a></p>
<p>The <code>XMLHttpRequest</code> object is defined in the <code>XMLHttpRequest</code> specification. <a data-link-type="biblio" href="#biblio-xmlhttprequest">[XMLHTTPREQUEST]</a></p>
<p>The <code>WebSocket</code> object is defined in the <code>WebSocket</code> specification. <a data-link-type="biblio" href="#biblio-websockets">[WEBSOCKETS]</a></p>
<p>The <code>EventSource</code> object is defined in the <code>EventSource</code> specification. <a data-link-type="biblio" href="#biblio-eventsource">[EVENTSOURCE]</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-link-type="biblio" href="#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-link-type="biblio" href="#biblio-webidl">[WEBIDL]</a>.</p>
<h3 class="heading settled" data-level="2.4" id="grammar"><span class="secno">2.4. </span><span class="content">Grammatical Concepts</span><a class="self-link" href="#grammar"></a></h3>
<p>The Augmented Backus-Naur Form (ABNF) notation used in this document is
specified in RFC5234. <a data-link-type="biblio" href="#biblio-abnf">[ABNF]</a></p>
<p>This document also uses the ABNF extension "#rule" as defined in <a href="https://tools.ietf.org/html/rfc7230#section-7">Section 7</a> of HTTP/1.1 -- Message Syntax and Routing. <a data-link-type="biblio" href="#biblio-rfc7230">[RFC7230]</a></p>
<p>The following core rules are included by reference, as defined in <a href="https://tools.ietf.org/html/rfc5234#appendix-B.1">Appendix B.1</a> of <a data-link-type="biblio" href="#biblio-abnf">[ABNF]</a>: <code><dfn data-dfn-type="dfn" data-noexport="" id="alpha">ALPHA<a class="self-link" href="#alpha"></a></dfn></code> (letters), <code><dfn data-dfn-type="dfn" data-noexport="" id="digit">DIGIT<a class="self-link" href="#digit"></a></dfn></code> (decimal 0-9), <code><dfn data-dfn-type="dfn" data-noexport="" id="wsp">WSP<a class="self-link" href="#wsp"></a></dfn></code> (white space) and <code><dfn data-dfn-type="dfn" data-noexport="" id="vchar">VCHAR<a class="self-link" href="#vchar"></a></dfn></code> (printing characters).</p>
</section>
<section>
<h2 class="heading settled" 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 a <a data-link-type="dfn" href="#security-policy">policy</a> to the user agent via an HTTP response
header (defined in <a href="#content-security-policy-header-field">§3.1 Content-Security-Policy Header Field</a> and <a href="#content-security-policy-report-only-header-field">§3.2 Content-Security-Policy-Report-Only Header Field</a>) or an HTML <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> element (defined in <a href="#delivery-html-meta-element">§3.3 HTML meta Element</a>).</p>
<section>
<h3 class="heading settled" 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. The grammar is as follows:</p>
<pre>"Content-Security-Policy:" 1#<a data-link-type="dfn" href="#policy_token">policy-token</a>
</pre>
<p>For example, a response might include the following header field:</p>
<div class="example" id="example-be526382"><a class="self-link" href="#example-be526382"></a> <code>Content-Security-Policy: <a data-link-type="dfn" href="#script_src">script-src</a> 'self'</code> </div>
<p>A server MUST NOT send more than one HTTP header field named <code>Content-Security-Policy</code> with a given <a data-link-type="dfn" href="#resource-representation">resource
representation</a>.</p>
<p>A server MAY send different <code>Content-Security-Policy</code> header field values with different <a data-link-type="dfn" href="#resource-representation">representations</a> 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">enforce</a> each of the policies contained in each such
header field.</p>
</section>
<section>
<h3 class="heading settled" 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. The grammar is as follows:</p>
<pre>"Content-Security-Policy-Report-Only:" 1#<a data-link-type="dfn" href="#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>
<div class="example" id="example-77886cbd">
<a class="self-link" href="#example-77886cbd"></a>
<pre>Content-Security-Policy-Report-Only: <a data-link-type="dfn" href="#script_src">script-src</a> 'self';
<a data-link-type="dfn" href="#report_uri">report-uri</a> /csp-report-endpoint/
</pre>
</div>
<p>If their site violates this policy the user agent will <a data-link-type="dfn" href="#send-violation-reports">send violation
reports</a> to the URL specified in the policy’s <a data-link-type="dfn" href="#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">Content-Security-Policy</a></code> header field.</p>
<p>A server MUST NOT send more than one HTTP header field named <code>Content-Security-Policy-Report-Only</code> with a given <a data-link-type="dfn" href="#resource-representation">resource representation</a>.</p>
<p>A server MAY send different <code>Content-Security-Policy-Report-Only</code> header field values
with different <a data-link-type="dfn" href="#resource-representation">representations</a> 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">monitor</a> each of the policies
contained in each such header field.</p>
<p class="note" role="note">Note: The <code><a data-link-type="dfn" href="#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#the-meta-element">meta</a></code> element.</p>
</section>
<section>
<h3 class="heading settled" 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#the-meta-element">meta</a></code> Element </span><a class="self-link" href="#delivery-html-meta-element"></a></h3>
<p>The server MAY supply policy via one or more HTML <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> elements
with <code><a data-link-type="element-attr" href="http://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv">http-equiv</a></code> attributes that are an <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#ascii-case-insensitive">ASCII case-insensitive
match</a> for the string "<code>Content-Security-Policy</code>". For
example:</p>
<pre class="example" id="example-ff79af85"><a class="self-link" href="#example-ff79af85"></a><meta http-equiv="Content-Security-Policy" content="<a data-link-type="dfn" href="#script_src">script-src</a> 'self'">
</pre>
<p>Add the following entry to the <a data-link-type="dfn" 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#the-meta-element">meta</a></code> element:</p>
<dl>
<dt> Content security policy
(<code>http-equiv="content-security-policy"</code>)
<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">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#the-meta-element">meta</a></code> element, abort these steps.
<li>If the <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">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">content</a></code> attribute, abort
these steps.
<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">content</a></code> attribute of the <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> element.
<li>Let <var>directive-set</var> be the result of <a data-link-type="dfn" href="#parse-the-policy">parsing <var>policy</var></a>.
<li>
Remove all occurrences of <code><a data-link-type="dfn" href="#report_uri">report-uri</a></code>, <code><a data-link-type="dfn" href="#frame_ancestors">frame-ancestors</a></code>, and <code><a data-link-type="dfn" href="#sandbox">sandbox</a></code> directives from <var>directive-set</var>.
<p class="note" role="note">Note: User agents are encouraged to issue a warning to developers
if one or more of these directives are included in a policy
delivered via <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code>.</p>
<li>Enforce each of the <a data-link-type="dfn" href="#security-policy-directive">directives</a> in <var>directive-set</var>,
as <a href="#directives">defined for each directive type</a>.
</ol>
</dl>
<p>Authors are <em>strongly encouraged</em> to place <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> elements as early
in the document as possible, because policies in <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> elements are not
applied to content which precedes them. In particular, note that resources
fetched or prefetched using the <code>Link</code> HTTP response header
field, and resources fetched or prefetched using <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-link-element">link</a></code> and <code><a data-link-type="element" href="http://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code> elements which precede a <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code>-delivered policy will not be blocked.</p>
<p class="note" role="note">Note: A <a data-link-type="dfn" href="#security-policy">policy</a> specified via a <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">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 impact of enforcing multiple
policies is described in <a href="#enforcing-multiple-policies">§3.4 Enforcing multiple policies</a>.</p>
<p class="note" role="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">content</a></code> attribute of a <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> element
after the element has been parsed will be ignored.</p>
<p class="note" role="note">Note: The <code><a data-link-type="dfn" href="#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#the-meta-element">meta</a></code> element.</p>
</section>
<section>
<h3 class="heading settled" data-level="3.4" id="enforcing-multiple-policies"><span class="secno">3.4. </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" id="example-53073245"><a class="self-link" href="#example-53073245"></a>Content-Security-Policy: <a data-link-type="dfn" href="#default_src">default-src</a> 'self' http://example.com http://example.net;
<a data-link-type="dfn" href="#connect_src">connect-src</a> 'none';
Content-Security-Policy: <a data-link-type="dfn" href="#connect_src">connect-src</a> http://example.com/;
<a data-link-type="dfn" href="#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">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">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" data-level="3.5" id="which-policy-applies"><span class="secno">3.5. </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">protected resource</a>, and <a data-link-type="dfn" href="#enforce">enforced</a> or <a data-link-type="dfn" href="#monitor">monitored</a> 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>What <a data-link-type="dfn" href="#security-policy">policy</a> applies?
<tbody>
<tr class="section">
<th rowspan="2">Top-level Contexts
<td>HTML as a new, top-level browsing context
<td>The policy delivered with the resource applies.
<tr>
<td>SVG, as a top-level document
<td>The policy delivered with the resource applies.
<tr class="section">
<th rowspan="3">Embedded Contexts
<td> Any resource included via <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element">object</a></code>, or <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element">embed</a></code>
<td> Unless the embedded resource is a globally unique identifier (or a
srcdoc iframe), the embedded resource is controlled by the policy
delivered with the resource. If the embedded resource is a globally
unique identifier or srcdoc iframe, it inherits the policy of the
context creating it. (The frame-src and
child-src directives of the embedding context only control
what resources are eligible for embedding in that context, not the
behavior of the resource once embedded.)
<tr>
<td>SVG, as an embedded document
<td> Unless the resource is a globally unique identifier,
it is controlled by the policy
delivered with the resource. If a globally
unique identifier, it inherits the policy of the
context creating it.
<tr>
<td> JavaScript, as a Worker, Shared Worker, or Service Worker
<td> Unless the resource is a globally unique identifier,
it is controlled by the
policy delivered with the resource. If a globally
unique identifier, it inherits the policy of the
context creating it.
<tr class="section">
<th rowspan="7">Subresources
<td>SVG, inlined via <code><a data-link-type="element" href="http://www.w3.org/TR/SVG2/struct.html#SVGElement">svg</a></code>
<td>The policy of the including context applies.
<tr>
<td>SVG, as a resource document
<td>The policy of the including context applies.
<tr>
<td>HTML via XMLHttpRequest
<td>The policy of the context that performed the fetch applies.
<tr>
<td>Image via <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element">img</a></code> element
<td>The policy of the including context applies.
<tr>
<td>JavaScript via a <code><a data-link-type="element" href="http://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code> element
<td>The policy of the including context applies.
<tr>
<td>SVG, via <code><a data-link-type="element" href="http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element">img</a></code>
<td>No policy applies; this should be just as safe as JPG
<tr>
<td>SVG, as a WebFont
<td>No policy applies; this should be just as safe as WOFF
</table>
</section>
</section>
<section>
<h2 class="heading settled" 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" 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">directive</a> consists of a <a data-link-type="dfn" href="#security-policy-directive-name">directive name</a> and (optionally) a <a data-link-type="dfn" href="#security-policy-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">directive-token</a> *( ";" [ <a data-link-type="dfn" href="#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">directive-name</a> [ WSP <a data-link-type="dfn" href="#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" 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>
For each non-empty token returned by <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#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-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#skip-whitespace">Skip whitespace</a>.
<li><a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#collect-a-sequence-of-characters">Collect a sequence of characters</a> that are
not <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#space-character">space characters</a>. The collected characters
are the <var>directive name</var>.
<li>If there are characters remaining in <var>token</var>,
skip ahead exactly one character (which must be a <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#space-character">space character</a>).
<li>The remaining characters in <var>token</var> (if any) are
the <var>directive value</var>.
<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>Add a <var>directive</var> to the <var>set of
directives</var> with name <var>directive name</var> and value <var>directive value</var>.
</ol>
<li>Return the <var>set of directives</var>.
</ol>
</section>
</section>
<section>
<h3 class="heading settled" 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-list">source
list<a class="self-link" href="#source-list"></a></dfn>, defined in the ABNF grammar below.</p>
<p>Each <dfn data-dfn-type="dfn" data-noexport="" id="source-expression">source expression<a class="self-link" href="#source-expression"></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 URLs, 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">source-expression</a> *( 1*WSP <a data-link-type="dfn" href="#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">scheme-source</a> / <a data-link-type="dfn" href="#host_source">host-source</a> / <a data-link-type="dfn" href="#keyword_source">keyword-source</a> / <a data-link-type="dfn" href="#nonce_source">nonce-source</a> / <a data-link-type="dfn" href="#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">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">scheme-part</a> "://" ] <a data-link-type="dfn" href="#host_part">host-part</a> [ <a data-link-type="dfn" href="#port_part">port-part</a> ] [ <a data-link-type="dfn" href="#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'"
<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">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">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">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">hash-algo</a> "-" <a data-link-type="dfn" href="#hash_value">hash-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="https://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">host-char</a> *( "." 1*<a data-link-type="dfn" href="#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="https://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">nonce-source</a></code> expression, the
server MUST generate a fresh value for the <code><a data-link-type="dfn" href="#nonce_value">nonce-value</a></code> directive at random and independently each time it transmits a policy.
The generated value SHOULD be at least 128 bits long (before encoding),
and generated via a cryptographically secure random number generator.
This requirement ensures that the <code><a data-link-type="dfn" href="#nonce_value">nonce-value</a></code> is
difficult for an attacker to predict.</p>
<p class="note" role="note">Note: Using a nonce to whitelist inline script or style is less secure than
not using a nonce, as nonces override the restrictions in the directive in
which they are present. An attacker who can gain access to the nonce can
execute whatever script they like, whenever they like. That said, nonces
provide a substantial improvement over <code>'unsafe-inline'</code> when
layering a content security policy on top of old code. When considering <code>'unsafe-inline'</code>, authors are encouraged to consider nonces (or
hashes) instead.</p>
<p>The <code><a data-link-type="dfn" href="#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-link-type="biblio" href="#biblio-rfc3492">[RFC3492]</a>. For example, the domain <code>üüüüüü.de</code> would be
encoded as <code>xn--tdaaaaaa.de</code>.</p>
<p class="note" role="note">NOTE: Though IP addresses do match the grammar above, only <code>127.0.0.1</code> will actually match a URL when used in a source
expression (see <a href="#match-source-expression">§4.2.2 Matching Source Expressions</a> for details). The security
properties of IP addresses are suspect, and authors ought to prefer
hostnames to IP addresses whenever possible.</p>
<section>
<h4 class="heading settled" 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-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace">Strip leading and trailing whitespace</a> from <var>source list</var>.
<li>If <var>source list</var> is an <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#ascii-case-insensitive">ASCII case-insensitive match</a> for the string <code>'none'</code> (including the quotation
marks), return the empty set.
<li>Let <var>set of source expressions</var> be the empty
set.
<li>For each token returned by <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#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">source-expression</a></code>, add the token to the <var>set
of source expressions</var>.
<li>Return the <var>set of source expressions</var>.
</ol>
<p class="note" role="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-type="dfn" href="http://www.w3.org/TR/url/#percent-encode">percent
encoded</a> as <code>%3B</code> and <code>%2C</code> respectively.</p>
</section>
<section>
<h4 class="heading settled" 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 URL <var>url</var> 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> for
a <var>protected resource</var> if the following algorithm returns <em>does match</em>:</p>
<ol>
<li> Let <var>url</var> be the result of processing the URL through the <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-parser">URL parser</a>.
<li> If the source expression consists of a single U+002A ASTERISK
character (<code>*</code>), and <var>url</var>’s <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-scheme">scheme</a> is not
one of <code>blob</code>, <code>data</code>, <code>filesystem</code>,
then return <em>does match</em>.
<li>
If the source expression matches the grammar for <code><a data-link-type="dfn" href="#scheme_source">scheme-source</a></code>:
<ol>
<li> If <var>url</var>’s <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-scheme">scheme</a> is an <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#ascii-case-insensitive">ASCII case-insensitive
match</a> for the source expression’s <code><a data-link-type="dfn" href="#scheme_part">scheme-part</a></code>, return <em>does match</em>.
<li> Otherwise, return <em>does not match</em>.
</ol>
<li>
If the source expression matches the grammar for <code><a data-link-type="dfn" href="#host_source">host-source</a></code>:
<ol>
<li> If <var>url</var>’s <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-host">host</a> is <code>null</code>,
return <em>does not match</em>.
<li>
Let <var>url-scheme</var>, <var>url-host</var>, and <var>url-port</var> be the <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-scheme">scheme</a>, <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-host">host</a>, and <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-port">port</a> of <var>url</var>’s origin, respectively.
<p class="note" role="note">Note: If <var>url</var> doesn’t specify a port, then its origin’s
port will be the <a data-link-type="dfn" href="http://www.w3.org/TR/url/#default-port">default port</a> for <var>url</var>’s <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-scheme">scheme</a>.</p>
<li> Let <var>url-path-list</var> be the <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-path">path</a> of <var>url</var>.
<li> If the source expression has a <code><a data-link-type="dfn" href="#scheme_part">scheme-part</a></code> that is not a case insensitive match for <var>url-scheme</var>,
then return <em>does not match</em>.
<li>
If the source expression does <strong>not</strong> have a
scheme, return <em>does not match</em> if any of the following
are true:
<ol>
<li> The scheme of the protected resource’s URL is a case
insensitive match for <code>HTTP</code>, and <var>url-scheme</var> is <strong>not</strong> a case
insensitive match for either <code>HTTP</code> or <code>HTTPS</code>.
<li> The scheme of the protected resource’s URL is <strong>not</strong> a case insensitive match for <code>HTTP</code>, and <var>url-scheme</var> is <strong>not</strong> a case insensitive match
for the scheme of the protected resource’s URL.
</ol>
<li> If the first character of the source expression’s <code><a data-link-type="dfn" href="#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>url-host</var>, then return <em>does not match</em>.
<li> If the first character of the source expression’s <code><a data-link-type="dfn" href="#host_part">host-part</a></code> is <em>not</em> an U+002A ASTERISK
character (<code>*</code>) and <var>url-host</var> is not a
case insensitive match for the source expression’s <code><a data-link-type="dfn" href="#host_part">host-part</a></code>, then return <em>does not
match</em>.
<li>
If the source expression’s <code><a data-link-type="dfn" href="#host_part">host-part</a></code> matches
the <code><a data-link-type="dfn" href="https://tools.ietf.org/html/rfc3986#section-3.2.2">IPv4address</a></code> production from <a data-link-type="biblio" href="#biblio-rfc3986">[RFC3986]</a>,
and is not <code>127.0.0.1</code>, or is an <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-ipv6">IPv6 address</a>,
return <em>does not match</em>.
<p class="note" role="note">Note: A future version of this specification may allow literal
IPv6 and IPv4 addresses, depending on usage and demand. Given the
weak security properties of IP addresses in relation to named
hosts, however, authors are encouraged to prefer the latter
whenever possible.</p>
<li> If the source expression does <strong>not</strong> contain
a <code>port-part</code> and <var>url-port</var> is not the <a data-link-type="dfn" href="http://www.w3.org/TR/url/#default-port">default port</a> for <var>url-scheme</var>, then return <em>does not match</em>.
<li>
If the source expression does contain a <code>port-part</code>,
then return <em>does not match</em> if both of the following
are true:
<ol>
<li> The <code><a data-link-type="dfn" href="#port_part">port-part</a></code> does <strong>not</strong> contain an U+002A ASTERISK character. (<code>*</code>)
<li> The <code><a data-link-type="dfn" href="#port_part">port-part</a></code> does <strong>not</strong> represent the same number as <var>url-port</var>.
</ol>
<li>
If the source expression contains a non-empty <code><a data-link-type="dfn" href="#path_part">path-part</a></code>, and the URL is <em>not</em> the
result of a redirect, then:
<ol>
<li> Let <var>exact-match</var> be <code>true</code> if the final
character of <var>path-part</var> is not the U+002F SOLIDUS
character (<code>/</code>), and <code>false</code> otherwise.
<li> Let <var>source-expression-path-list</var> be the result of
splitting <var>path-part</var> on the U+002F SOLIDUS character
(<code>/</code>).
<li> If <var>source-expression-path-list</var>’s length is greater
than <var>url-path-list</var>’s length, return <em>does not
match</em>.
<li>
For each <var>entry</var> in <var>source-expression-path-list</var>:
<ol>
<li> <a data-link-type="dfn" href="http://www.w3.org/TR/url/#percent-decode">Percent decode</a> <var>entry</var>.
<li> <a data-link-type="dfn" href="http://www.w3.org/TR/url/#percent-decode">Percent decode</a> the first item in <var>url-path-list</var>.
<li> If <var>entry</var> is not an <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#ascii-case-insensitive">ASCII case-insensitive
match</a> for the first item in <var>url-path-list</var>,
return <em>does not match</em>.
<li> Pop the first item in <var>url-path-list</var> off the
list.
</ol>
<li> If <var>exact-match</var> is <code>true</code>, and <var>url-path-list</var> is not empty, return <em>does not
match</em>.
</ol>
<li> Otherwise, return <em>does match</em>.
</ol>
<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 <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-origin">the
origin of <var>url</var></a> matches <a data-link-type="dfn" href="http://www.w3.org/TR/url/#concept-url-origin">the origin of <var>protected
resource</var>’s URL</a>.
<p class="note" role="note">Note: This includes IP addresses. That is, a document at <code>https://111.111.111.111/</code> with a <a data-link-type="dfn" href="#security-policy">policy</a> of <code>img-src 'self'</code> can load the image <code>https://111.111.111.111/image.png</code>, as the origins
match.</p>
</ol>
<li> Otherwise, return <em>does not match</em>.
</ol>
<p class="note" role="note">Note: This algorithm treats the URLs <code>https://example.com/</code> and <code>https://example.com./</code> as <em>non-matching</em>. This
is consistent with browser behavior which treats documents served from
these URLs as existing in distinct origins.</p>
<p>A URL <var>url</var> 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> for <var>protected resource</var> if at least one source expression in the set
of source expressions obtained by <a data-link-type="dfn" href="#parse-a-source-list">parsing the
source list</a> <a data-link-type="dfn" href="#match-a-source-expression">matches <var>url</var> for <var>protected resource</var></a>.</p>
<p class="note" role="note">Note: No URLs match an empty set of source expressions, such as the set
obtained by parsing the source list <code>'none'</code>.</p>
<section class="informative">
<h5 class="heading settled" data-level="4.2.2.1" id="source-list-guid-matching"><span class="secno">4.2.2.1. </span><span class="content"> Security Considerations for GUID URL schemes </span><a class="self-link" href="#source-list-guid-matching"></a></h5>
<p><em>This section is not normative.</em></p>
<p>As defined above, special URL schemes that refer to specific pieces of
unique content, such as "data:", "blob:" and "filesystem:" are
excluded from matching a policy of <code>*</code> and must be
explicitly listed. Policy authors should note that the content of
such URLs is often derived from a response body or execution in a
Document context, which may be unsafe. Especially for the <code><a data-link-type="dfn" href="#default_src">default-src</a></code> and <code><a data-link-type="dfn" href="#script_src">script-src</a></code> directives, policy authors should be aware that allowing "data:" URLs
is equivalent to <code>unsafe-inline</code> and allowing "blob:" or
"filesystem:" URLs is equivalent to <code>unsafe-eval</code>.</p>
</section>
<section class="informative">
<h5 class="heading settled" data-level="4.2.2.2" id="source-list-path-patching"><span class="secno">4.2.2.2. </span><span class="content">Path Matching</span><a class="self-link" href="#source-list-path-patching"></a></h5>
<p><em>This section is not normative.</em></p>
<p>The rules for matching source expressions that contain paths
are simpler than they look: paths that end with the <code>'/'</code> character match all files in a directory and its subdirectories. Paths
that do not end with the <code>'/'</code> character match only one
specific file. A few examples should make this clear:</p>
<ol>
<li>The source expression <code>example.com</code> has no path,
and therefore matches any file served from that host.
<li>The source expression <code>example.com/scripts/</code> matches any file in the <code>scripts</code> directory of <code>example.com</code>, and any of its subdirectories. For
example, both <code>https://example.com/scripts/file.js</code> and <code>https://example.com/scripts/js/file.js</code> would
match.
<li>The source expression <code>example.com/scripts/file.js</code> matches only the file
named <code>file.js</code> in the <code>scripts</code> directory
of <code>example.com</code>.
<li>Likewise, the source expression <code>example.com/js</code> matches only the file named <code>js</code>. In particular, note
that it would not match files inside a directory named <code>js</code>. Files like <code>example.com/js/file.js</code> would be matched only if the source expression ended with a
trailing "/", as in <code>example.com/js/</code>.
</ol>
<p class="note" role="note">Note: Query strings have no impact on matching: the source
expression <code>example.com/file</code> matches each of <code>https://example.com/file</code>, <code>https://example.com/file?key=value</code>, <code>https://example.com/file?key=notvalue</code>, and <code>https://example.com/file?notkey=notvalue</code>.</p>
</section>
<section class="informative">
<h5 class="heading settled" data-level="4.2.2.3" id="source-list-paths-and-redirects"><span class="secno">4.2.2.3. </span><span class="content">Paths and Redirects</span><a class="self-link" href="#source-list-paths-and-redirects"></a></h5>
<p>To avoid leaking path information cross-origin (as discussed
in Egor Homakov’s <a href="http://homakov.blogspot.de/2014/01/using-content-security-policy-for-evil.html">Using Content-Security-Policy for Evil</a>),
the matching algorithm ignores the path component of a source
expression if the resource being loaded is the result of a
redirect. For example, given a page with an active policy of <code><a data-link-type="dfn" href="#img_src">img-src</a> example.com not-example.com/path</code>:</p>
<ul>
<li>Directly loading <code>https://not-example.com/not-path</code> would fail, as it doesn’t match the policy.
<li>Directly loading <code>https://example.com/redirector</code> would pass, as it matches <code>example.com</code>.
<li>Assuming that <code>https://example.com/redirector</code> delivered a redirect response pointing to <code>https://not-example.com/not-path</code>,
the load would succeed, as the initial URL matches <code>example.com</code>,
and the redirect target matches <code>not-example.com/path</code> if we ignore its path component.
</ul>
<p>This restriction reduces the granularity of a document’s
policy when redirects are in play, a necessary compromise to
avoid brute-forced information leaks of this type.</p>
<p>The relatively long thread <a href="http://lists.w3.org/Archives/Public/public-webappsec/2014Feb/0036.html">"Remove paths from CSP?"</a> from [email protected] has more detailed discussion around
alternate proposals.</p>
</section>
</section>
<section>
<h4 class="heading settled" data-level="4.2.3" id="script-src-the-nonce-attribute"><span class="secno">4.2.3. </span><span class="content"> The <code>nonce</code> attribute </span><a class="self-link" href="#script-src-the-nonce-attribute"></a></h4>
<p>Nonce sources require a new <code>nonce</code> attribute to be added to
both <code><a data-link-type="element" href="http://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code> and <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-style-element">style</a></code> elements.</p>
<pre class="idl">partial interface <a class="idl-code" data-link-type="interface" href="http://www.w3.org/TR/html5/scripting-1.html#htmlscriptelement">HTMLScriptElement</a> {
attribute DOMString <a class="idl-code" data-link-type="attribute" data-type="DOMString " href="#dom-htmlscriptelement-nonce">nonce</a>;
};
</pre>
<dl>
<dt><dfn class="idl-code" data-dfn-for="HTMLScriptElement" data-dfn-type="attribute" data-export="" id="dom-htmlscriptelement-nonce">nonce<a class="self-link" href="#dom-htmlscriptelement-nonce"></a></dfn>, <span> of type <a data-link-type="idl-name" href="http://heycam.github.io/webidl/#idl-DOMString">DOMString</a></span>
<dd>This attribute <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#reflect">reflects</a> the value of the
element’s <code><dfn data-dfn-for="script" data-dfn-type="element-attr" data-export="" id="element-attrdef-script-nonce">nonce<a class="self-link" href="#element-attrdef-script-nonce"></a></dfn></code> content attribute.
</dl>
<pre class="idl">partial interface <a class="idl-code" data-link-type="interface" href="http://www.w3.org/TR/html5/document-metadata.html#htmlstyleelement">HTMLStyleElement</a> {
attribute DOMString <a class="idl-code" data-link-type="attribute" data-type="DOMString " href="#dom-htmlstyleelement-nonce">nonce</a>;
};
</pre>
<dl>
<dt><dfn class="idl-code" data-dfn-for="HTMLStyleElement" data-dfn-type="attribute" data-export="" id="dom-htmlstyleelement-nonce">nonce<a class="self-link" href="#dom-htmlstyleelement-nonce"></a></dfn>, <span> of type <a data-link-type="idl-name" href="http://heycam.github.io/webidl/#idl-DOMString">DOMString</a></span>
<dd>This attribute <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#reflect">reflects</a> the value of the
element’s <code><dfn data-dfn-for="style" data-dfn-type="element-attr" data-export="" id="element-attrdef-style-nonce">nonce<a class="self-link" href="#element-attrdef-style-nonce"></a></dfn></code> content attribute.
</dl>
</section>
<section>
<h4 class="heading settled" data-level="4.2.4" id="source-list-valid-nonces"><span class="secno">4.2.4. </span><span class="content">Valid Nonces</span><a class="self-link" href="#source-list-valid-nonces"></a></h4>
<p>An element has a <dfn data-dfn-type="dfn" data-noexport="" id="valid-nonce">valid nonce<a class="self-link" href="#valid-nonce"></a></dfn> for a <var>set of source
expressions</var> if the value of the element’s <code><a data-link-type="element-attr" href="#element-attrdef-script-nonce">nonce</a></code> attribute
after <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace">stripping leading
and trailing whitespace</a> is a case-sensitive match for the <code><a data-link-type="dfn" href="#nonce_value">nonce-value</a></code> component of at least one <code><a data-link-type="dfn" href="#nonce_source">nonce-source</a></code> expression in <var>set of source
expressions</var>.</p>
</section>
<section>
<h4 class="heading settled" data-level="4.2.5" id="source-list-valid-hashes"><span class="secno">4.2.5. </span><span class="content">Valid Hashes</span><a class="self-link" href="#source-list-valid-hashes"></a></h4>
<p>An <dfn data-dfn-type="dfn" data-noexport="" id="elements-content">element’s content<a class="self-link" href="#elements-content"></a></dfn> is <a data-link-type="dfn" href="http://www.w3.org/TR/html5/scripting-1.html#the-script-block's-source">the script block’s
source</a> for <code><a data-link-type="element" href="http://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code> elements, or the value of the element’s <code class="idl"><a data-link-type="idl" href="http://www.w3.org/TR/dom/#dom-node-textcontent">textContent</a></code> IDL attribute for non-<code><a data-link-type="element" href="http://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code> elements such as <code><a data-link-type="element" href="http://www.w3.org/TR/html5/document-metadata.html#the-style-element">style</a></code>.</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="digest-of-elements-content">digest of <var>element</var>’s content<a class="self-link" href="#digest-of-elements-content"></a></dfn> for is the result
of applying an <var>hashing algorithm</var> to the <a data-link-type="dfn" href="#elements-content">element’s content</a>.</p>
<p>To determine whether <var>element</var> has a <dfn data-dfn-type="dfn" data-noexport="" id="valid-hash">valid hash<a class="self-link" href="#valid-hash"></a></dfn> for
a <var>set of source expressions</var>, execute the following steps:</p>
<ol>
<li>Let <var>hashes</var> be a list of all <code><a data-link-type="dfn" href="#hash_source">hash-source</a></code> expressions in <var>set of source
expressions</var>.
<li>
For each <var>hash</var> in <var>hashes</var>:
<ol>
<li>
Let <var>hashing algorithm</var> be:
<ul>
<li><a data-link-type="dfn" href="#sha_256">SHA-256</a> if the <code><a data-link-type="dfn" href="#hash_algo">hash-algo</a></code> component of <var>hash</var> is an <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#ascii-case-insensitive">ASCII case-insensitive
match</a> for the string "sha256".
<li><a data-link-type="dfn" href="#sha_384">SHA-384</a> if the <code><a data-link-type="dfn" href="#hash_algo">hash-algo</a></code> component of <var>hash</var> is an <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#ascii-case-insensitive">ASCII case-insensitive
match</a> for the string "sha384".
<li><a data-link-type="dfn" href="#sha_512">SHA-512</a> if the <code><a data-link-type="dfn" href="#hash_algo">hash-algo</a></code> component of <var>hash</var> is an <a data-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#ascii-case-insensitive">ASCII case-insensitive
match</a> for the string "sha512".
</ul>
<li>Let <var>expected</var> be the <code><a data-link-type="dfn" href="#hash_value">hash-value</a></code> component of <var>hash</var>.
<li>Let <var>actual</var> be the <a href="https://tools.ietf.org/html/rfc4648#section-4">base64
encoding</a> of the binary <a data-link-type="dfn" href="#digest-of-elements-content">digest of <var>element</var>’s
content</a> using the <var>hashing algorithm</var>.
<li>If <var>actual</var> is a case-sensitive match for <var>expected</var>, return <strong>true</strong> and abort these
steps.
</ol>
<li>Return <strong>false</strong>.
</ol>