forked from w3c/webappsec-csp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
WD.html
4842 lines (4808 loc) · 423 KB
/
WD.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">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<title>Content Security Policy Level 3</title>
<meta content="WD" name="w3c-status">
<link href="https://www.w3.org/StyleSheets/TR/2016/W3C-WD" rel="stylesheet" type="text/css">
<meta content="Bikeshed 1.0.0" name="generator">
<style>
ul.toc ul ul ul {
margin: 0 0 0 2em;
}
ul.toc ul ul ul span.secno {
margin-left: -9em;
}
a[href^="http:"]:after {
color: red;
content: "🔓";
}
</style>
<style>/* style-md-lists */
/* This is a weird hack for me not yet following the commonmark spec
regarding paragraph and lists. */
[data-md] > :first-child {
margin-top: 0;
}
[data-md] > :last-child {
margin-bottom: 0;
}</style>
<style>/* style-selflinks */
.heading, .issue, .note, .example, li, dt {
position: relative;
}
a.self-link {
position: absolute;
top: 0;
left: calc(-1 * (3.5rem - 26px));
width: calc(3.5rem - 26px);
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
}
a.self-link:hover {
opacity: 1;
}
.heading > a.self-link {
font-size: 83%;
}
li > a.self-link {
left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
top: auto;
left: auto;
opacity: 0;
width: 1.5em;
height: 1.5em;
background: gray;
color: white;
font-style: normal;
transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
opacity: 1;
}
dfn > a.self-link:hover {
color: black;
}
a.self-link::before { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before { content: "#"; }</style>
<style>/* style-counters */
body {
counter-reset: example figure issue;
}
.issue {
counter-increment: issue;
}
.issue:not(.no-marker)::before {
content: "Issue " counter(issue);
}
.example {
counter-increment: example;
}
.example:not(.no-marker)::before {
content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
content: "Invalid Example" counter(example);
}
figcaption {
counter-increment: figure;
}
figcaption:not(.no-marker)::before {
content: "Figure " counter(figure) " ";
}</style>
<style>/* style-autolinks */
.css.css, .property.property, .descriptor.descriptor {
color: #005a9c;
font-size: inherit;
font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
content: "‘";
}
.css::after, .property::after, .descriptor::after {
content: "’";
}
.property, .descriptor {
/* Don't wrap property and descriptor names */
white-space: nowrap;
}
.type { /* CSS value <type> */
font-style: italic;
}
pre .property::before, pre .property::after {
content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
content: "’";
}
[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
content: "";
}
[data-link-type=element],
[data-link-type=element-attr] {
font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after { content: ">" }
[data-link-type=biblio] {
white-space: pre;
}</style>
<style>/* style-dfn-panel */
.dfn-panel {
position: absolute;
z-index: 35;
height: auto;
width: -webkit-fit-content;
width: fit-content;
max-width: 300px;
max-height: 500px;
overflow: auto;
padding: 0.5em 0.75em;
font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
background: #DDDDDD;
color: black;
border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
display: inline-block;
position: fixed;
left: .5em;
bottom: 2em;
margin: 0 auto;
max-width: calc(100vw - 1.5em - .4em - .5em);
max-height: 30vh;
}
.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-syntax-highlighting */
pre.idl.highlight { color: #708090; }
.highlight:not(.idl) { background: hsl(24, 20%, 95%); }
code.highlight { padding: .1em; border-radius: .3em; }
pre.highlight, pre > code.highlight { display: block; padding: 1em; margin: .5em 0; overflow: auto; border-radius: 0; }
.highlight .c { color: #708090 } /* Comment */
.highlight .k { color: #990055 } /* Keyword */
.highlight .l { color: #000000 } /* Literal */
.highlight .n { color: #0077aa } /* Name */
.highlight .o { color: #999999 } /* Operator */
.highlight .p { color: #999999 } /* Punctuation */
.highlight .cm { color: #708090 } /* Comment.Multiline */
.highlight .cp { color: #708090 } /* Comment.Preproc */
.highlight .c1 { color: #708090 } /* Comment.Single */
.highlight .cs { color: #708090 } /* Comment.Special */
.highlight .kc { color: #990055 } /* Keyword.Constant */
.highlight .kd { color: #990055 } /* Keyword.Declaration */
.highlight .kn { color: #990055 } /* Keyword.Namespace */
.highlight .kp { color: #990055 } /* Keyword.Pseudo */
.highlight .kr { color: #990055 } /* Keyword.Reserved */
.highlight .kt { color: #990055 } /* Keyword.Type */
.highlight .ld { color: #000000 } /* Literal.Date */
.highlight .m { color: #000000 } /* Literal.Number */
.highlight .s { color: #a67f59 } /* Literal.String */
.highlight .na { color: #0077aa } /* Name.Attribute */
.highlight .nc { color: #0077aa } /* Name.Class */
.highlight .no { color: #0077aa } /* Name.Constant */
.highlight .nd { color: #0077aa } /* Name.Decorator */
.highlight .ni { color: #0077aa } /* Name.Entity */
.highlight .ne { color: #0077aa } /* Name.Exception */
.highlight .nf { color: #0077aa } /* Name.Function */
.highlight .nl { color: #0077aa } /* Name.Label */
.highlight .nn { color: #0077aa } /* Name.Namespace */
.highlight .py { color: #0077aa } /* Name.Property */
.highlight .nt { color: #669900 } /* Name.Tag */
.highlight .nv { color: #222222 } /* Name.Variable */
.highlight .ow { color: #999999 } /* Operator.Word */
.highlight .mb { color: #000000 } /* Literal.Number.Bin */
.highlight .mf { color: #000000 } /* Literal.Number.Float */
.highlight .mh { color: #000000 } /* Literal.Number.Hex */
.highlight .mi { color: #000000 } /* Literal.Number.Integer */
.highlight .mo { color: #000000 } /* Literal.Number.Oct */
.highlight .sb { color: #a67f59 } /* Literal.String.Backtick */
.highlight .sc { color: #a67f59 } /* Literal.String.Char */
.highlight .sd { color: #a67f59 } /* Literal.String.Doc */
.highlight .s2 { color: #a67f59 } /* Literal.String.Double */
.highlight .se { color: #a67f59 } /* Literal.String.Escape */
.highlight .sh { color: #a67f59 } /* Literal.String.Heredoc */
.highlight .si { color: #a67f59 } /* Literal.String.Interpol */
.highlight .sx { color: #a67f59 } /* Literal.String.Other */
.highlight .sr { color: #a67f59 } /* Literal.String.Regex */
.highlight .s1 { color: #a67f59 } /* Literal.String.Single */
.highlight .ss { color: #a67f59 } /* Literal.String.Symbol */
.highlight .vc { color: #0077aa } /* Name.Variable.Class */
.highlight .vg { color: #0077aa } /* Name.Variable.Global */
.highlight .vi { color: #0077aa } /* Name.Variable.Instance */
.highlight .il { color: #000000 } /* Literal.Number.Integer.Long */
</style>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
<h1>Content Security Policy Level 3</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">W3C Working Draft, <time class="dt-updated" datetime="2016-08-01">1 August 2016</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="https://www.w3.org/TR/2016/WD-CSP3-20160801/">https://www.w3.org/TR/2016/WD-CSP3-20160801/</a>
<dt>Latest published version:
<dd><a href="https://www.w3.org/TR/CSP3/">https://www.w3.org/TR/CSP3/</a>
<dt>Editor's Draft:
<dd><a href="https://w3c.github.io/webappsec-csp/">https://w3c.github.io/webappsec-csp/</a>
<dt>Previous Versions:
<dd><a href="https://www.w3.org/TR/2016/WD-CSP3-20160621/" rel="previous">https://www.w3.org/TR/2016/WD-CSP3-20160621/</a>
<dt>Version History:
<dd><a href="https://github.com/w3c/webappsec-csp/commits/master/index.src.html">https://github.com/w3c/webappsec-csp/commits/master/index.src.html</a>
<dt>Feedback:
<dd><span><a href="mailto:[email protected]?subject=%5BCSP3%5D%20YOUR%20TOPIC%20HERE">[email protected]</a> with subject line “<kbd>[CSP3] <i data-lt="">… message topic …</i></kbd>” (<a href="https://lists.w3.org/Archives/Public/public-webappsec/" rel="discussion">archives</a>)</span>
<dt class="editor">Editor:
<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>)
<dt>Participate:
<dd><span><a href="https://github.com/w3c/webappsec-csp/issues/new">File an issue</a> (<a href="https://github.com/w3c/webappsec-csp/issues">open issues</a>)</span>
</dl>
</div>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2016 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="https://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="https://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="https://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://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 mechanism by which web developers can control the
resources which a particular page can fetch or execute, as well as a number
of security-relevant policy decisions.</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> <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="https://www.w3.org/TR/">W3C technical reports
index at https://www.w3.org/TR/.</a></em> </p>
<p> This document was published by the <a href="https://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>
<p> The (<a href="https://lists.w3.org/Archives/Public/public-webappsec/">archived</a>) public mailing list <a href="mailto:[email protected]?Subject=%5BCSP3%5D%20PUT%20SUBJECT%20HERE">[email protected]</a> (see <a href="https://www.w3.org/Mail/Request">instructions</a>)
is preferred for discussion of this specification.
When sending e-mail,
please put the text “CSP3” in the subject,
preferably like this:
“[CSP3] <em>…summary of comment…</em>” </p>
<p> Publication as a 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>
<p> This document was produced by the <a href="https://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="https://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>.
W3C maintains a <a href="https://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="https://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="https://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="https://www.w3.org/2015/Process-20150901/" id="w3c_process_revision">1 September 2015 W3C Process Document</a>. </p>
<p></p>
</div>
<div data-fill-with="at-risk"></div>
<nav data-fill-with="table-of-contents" id="toc">
<h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<ol class="toc" role="directory">
<li>
<a href="#intro"><span class="secno">1</span> <span class="content">Introduction</span></a>
<ol class="toc">
<li>
<a href="#examples"><span class="secno">1.1</span> <span class="content">Examples</span></a>
<ol class="toc">
<li><a href="#example-basic"><span class="secno">1.1.1</span> <span class="content">Control Execution</span></a>
</ol>
<li><a href="#goals"><span class="secno">1.2</span> <span class="content">Goals</span></a>
<li><a href="#changes-from-level-2"><span class="secno">1.3</span> <span class="content">Changes from Level 2</span></a>
</ol>
<li>
<a href="#framework"><span class="secno">2</span> <span class="content">Framework</span></a>
<ol class="toc">
<li>
<a href="#framework-policy"><span class="secno">2.1</span> <span class="content">Policies</span></a>
<ol class="toc">
<li><a href="#parse-serialized-policy"><span class="secno">2.1.1</span> <span class="content"> Parse a <var>serialized CSP</var> as <var>disposition</var> </span></a>
<li><a href="#parse-serialized-policy-list"><span class="secno">2.1.2</span> <span class="content"> Parse a serialized CSP <var>list</var> as <var>disposition</var> </span></a>
</ol>
<li>
<a href="#framework-directives"><span class="secno">2.2</span> <span class="content">Directives</span></a>
<ol class="toc">
<li><a href="#framework-directive-source-list"><span class="secno">2.2.1</span> <span class="content">Source Lists</span></a>
</ol>
<li>
<a href="#framework-violation"><span class="secno">2.3</span> <span class="content">Violations</span></a>
<ol class="toc">
<li><a href="#create-violation-for-global"><span class="secno">2.3.1</span> <span class="content"> Create a violation object for <var>global</var>, <var>policy</var>, and <var>directive</var> </span></a>
<li><a href="#create-violation-for-request"><span class="secno">2.3.2</span> <span class="content"> Create a violation object for <var>request</var>, <var>policy</var>, and <var>directive</var> </span></a>
</ol>
</ol>
<li>
<a href="#policy-delivery"><span class="secno">3</span> <span class="content"> Policy Delivery </span></a>
<ol class="toc">
<li><a href="#csp-header"><span class="secno">3.1</span> <span class="content"> The <code>Content-Security-Policy</code> HTTP Response Header Field </span></a>
<li><a href="#cspro-header"><span class="secno">3.2</span> <span class="content"> The <code>Content-Security-Policy-Report-Only</code> HTTP Response Header Field </span></a>
<li><a href="#meta-element"><span class="secno">3.3</span> <span class="content"> The <code><meta></code> element </span></a>
</ol>
<li>
<a href="#integrations"><span class="secno">4</span> <span class="content">Integrations</span></a>
<ol class="toc">
<li>
<a href="#fetch-integration"><span class="secno">4.1</span> <span class="content"> Integration with Fetch </span></a>
<ol class="toc">
<li><a href="#set-response-csp-list"><span class="secno">4.1.1</span> <span class="content"> Set <var>response</var>’s <code>CSP list</code> </span></a>
<li><a href="#report-for-request"><span class="secno">4.1.2</span> <span class="content"> Report Content Security Policy violations for <var>request</var> </span></a>
<li><a href="#should-block-request"><span class="secno">4.1.3</span> <span class="content"> Should <var>request</var> be blocked by Content Security Policy? </span></a>
<li><a href="#should-block-response"><span class="secno">4.1.4</span> <span class="content"> Should <var>response</var> to <var>request</var> be blocked by Content
Security Policy? </span></a>
</ol>
<li>
<a href="#html-integration"><span class="secno">4.2</span> <span class="content"> Integration with HTML </span></a>
<ol class="toc">
<li><a href="#initialize-document-csp"><span class="secno">4.2.1</span> <span class="content"> Initialize a <code>Document</code>'s <code>CSP list</code> </span></a>
<li><a href="#initialize-global-object-csp"><span class="secno">4.2.2</span> <span class="content"> Initialize a global object’s <code>CSP list</code> </span></a>
<li><a href="#should-block-inline"><span class="secno">4.2.3</span> <span class="content"> Should <var>element</var>’s inline <var>type</var> behavior be blocked by Content Security Policy? </span></a>
</ol>
<li>
<a href="#ecma-integration"><span class="secno">4.3</span> <span class="content">Integration with ECMAScript</span></a>
<ol class="toc">
<li><a href="#can-compile-strings"><span class="secno">4.3.1</span> <span class="content"> EnsureCSPDoesNotBlockStringCompilation(<var>callerRealm</var>, <var>calleeRealm</var>) </span></a>
</ol>
</ol>
<li>
<a href="#reporting"><span class="secno">5</span> <span class="content"> Reporting </span></a>
<ol class="toc">
<li><a href="#violation-events"><span class="secno">5.1</span> <span class="content"> Violation DOM Events </span></a>
<li><a href="#deprecated-serialize-violation"><span class="secno">5.2</span> <span class="content"> Obtain the deprecated serialization of <var>violation</var> </span></a>
<li><a href="#report-violation"><span class="secno">5.3</span> <span class="content"> Report a <var>violation</var> </span></a>
</ol>
<li>
<a href="#csp-directives"><span class="secno">6</span> <span class="content"> Content Security Policy Directives </span></a>
<ol class="toc">
<li>
<a href="#directives-fetch"><span class="secno">6.1</span> <span class="content"> Fetch Directives </span></a>
<ol class="toc">
<li>
<a href="#directive-child-src"><span class="secno">6.1.1</span> <span class="content"><code>child-src</code></span></a>
<ol class="toc">
<li><a href="#child-src-algorithms"><span class="secno">6.1.1.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-connect-src"><span class="secno">6.1.2</span> <span class="content"><code>connect-src</code></span></a>
<ol class="toc">
<li><a href="#connect-src-algorithms"><span class="secno">6.1.2.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-default-src"><span class="secno">6.1.3</span> <span class="content"><code>default-src</code></span></a>
<ol class="toc">
<li><a href="#default-src-algorithms"><span class="secno">6.1.3.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-font-src"><span class="secno">6.1.4</span> <span class="content"><code>font-src</code></span></a>
<ol class="toc">
<li><a href="#font-src-algorithms"><span class="secno">6.1.4.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-frame-src"><span class="secno">6.1.5</span> <span class="content"><code>frame-src</code></span></a>
<ol class="toc">
<li><a href="#frame-src-algorithms"><span class="secno">6.1.5.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-img-src"><span class="secno">6.1.6</span> <span class="content"><code>img-src</code></span></a>
<ol class="toc">
<li><a href="#img-src-algorithms"><span class="secno">6.1.6.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-manifest-src"><span class="secno">6.1.7</span> <span class="content"><code>manifest-src</code></span></a>
<ol class="toc">
<li><a href="#manifest-src-algorithms"><span class="secno">6.1.7.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-media-src"><span class="secno">6.1.8</span> <span class="content"><code>media-src</code></span></a>
<ol class="toc">
<li><a href="#media-src-algorithms"><span class="secno">6.1.8.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-object-src"><span class="secno">6.1.9</span> <span class="content"><code>object-src</code></span></a>
<ol class="toc">
<li><a href="#object-src-algorithms"><span class="secno">6.1.9.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-script-src"><span class="secno">6.1.10</span> <span class="content"><code>script-src</code></span></a>
<ol class="toc">
<li><a href="#script-src-algorithms"><span class="secno">6.1.10.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-style-src"><span class="secno">6.1.11</span> <span class="content"><code>style-src</code></span></a>
<ol class="toc">
<li><a href="#style-src-algorithms"><span class="secno">6.1.11.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-worker-src"><span class="secno">6.1.12</span> <span class="content"><code>worker-src</code></span></a>
<ol class="toc">
<li><a href="#worker-src-algorithms"><span class="secno">6.1.12.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#fetch-directive-matching-url"><span class="secno">6.1.13</span> <span class="content">URL Matching Algorithms</span></a>
<ol class="toc">
<li><a href="#does-request-violate-policy"><span class="secno">6.1.13.1</span> <span class="content"> Does <var>request</var> violate <var>policy</var>? </span></a>
<li><a href="#match-nonce-to-source-list"><span class="secno">6.1.13.2</span> <span class="content"> Does <var>nonce</var> match <var>source list</var>? </span></a>
<li><a href="#match-url-to-source-list"><span class="secno">6.1.13.3</span> <span class="content"> Does <var>url</var> match <var>source list</var>? </span></a>
<li><a href="#match-url-to-source-expression"><span class="secno">6.1.13.4</span> <span class="content"> Does <var>url</var> match <var>expression</var> in <var>origin</var> with <var>redirect count</var>? </span></a>
<li><a href="#effective-directive-for-a-request"><span class="secno">6.1.13.5</span> <span class="content"> Get the effective directive for <var>request</var> </span></a>
</ol>
<li>
<a href="#fetch-directive-matching-element"><span class="secno">6.1.14</span> <span class="content">Element Matching Algorithms</span></a>
<ol class="toc">
<li><a href="#match-element-to-source-list"><span class="secno">6.1.14.1</span> <span class="content"> Does <var>element</var> match source <var>list</var> for <var>type</var> and <var>source</var>? </span></a>
</ol>
</ol>
<li>
<a href="#directives-document"><span class="secno">6.2</span> <span class="content"> Document Directives </span></a>
<ol class="toc">
<li>
<a href="#directive-base-uri"><span class="secno">6.2.1</span> <span class="content"><code>base-uri</code></span></a>
<ol class="toc">
<li><a href="#allow-base-for-document"><span class="secno">6.2.1.1</span> <span class="content"> Is <var>base</var> allowed for <var>document</var>? </span></a>
</ol>
<li><a href="#directive-plugin-types"><span class="secno">6.2.2</span> <span class="content"><code>plugin-types</code></span></a>
<li>
<a href="#directive-sandbox"><span class="secno">6.2.3</span> <span class="content"><code>sandbox</code></span></a>
<ol class="toc">
<li><a href="#sandbox-algorithms"><span class="secno">6.2.3.1</span> <span class="content">Algorithms</span></a>
</ol>
<li>
<a href="#directive-disown-opener"><span class="secno">6.2.4</span> <span class="content"><code>disown-opener</code></span></a>
<ol class="toc">
<li><a href="#disown-opener-algorithms"><span class="secno">6.2.4.1</span> <span class="content">Algorithms</span></a>
</ol>
</ol>
<li>
<a href="#directives-navigation"><span class="secno">6.3</span> <span class="content"> Navigation Directives </span></a>
<ol class="toc">
<li><a href="#directive-form-action"><span class="secno">6.3.1</span> <span class="content"><code>form-action</code></span></a>
<li>
<a href="#directive-frame-ancestors"><span class="secno">6.3.2</span> <span class="content"><code>frame-ancestors</code></span></a>
<ol class="toc">
<li><a href="#frame-ancestors-algorithms"><span class="secno">6.3.2.1</span> <span class="content">Algorithms</span></a>
</ol>
</ol>
<li>
<a href="#directives-reporting"><span class="secno">6.4</span> <span class="content"> Reporting Directives </span></a>
<ol class="toc">
<li><a href="#directive-report-uri"><span class="secno">6.4.1</span> <span class="content"><code>report-uri</code></span></a>
<li><a href="#directive-report-to"><span class="secno">6.4.2</span> <span class="content"><code>report-to</code></span></a>
</ol>
<li><a href="#directives-elsewhere"><span class="secno">6.5</span> <span class="content"> Directives Defined in Other Documents </span></a>
</ol>
<li>
<a href="#security-considerations"><span class="secno">7</span> <span class="content">Security Considerations</span></a>
<ol class="toc">
<li><a href="#security-nonces"><span class="secno">7.1</span> <span class="content">Nonce Reuse</span></a>
</ol>
<li>
<a href="#authoring-considerations"><span class="secno">8</span> <span class="content">Authoring Considerations</span></a>
<ol class="toc">
<li><a href="#multiple-policies"><span class="secno">8.1</span> <span class="content"> The effect of multiple policies </span></a>
<li><a href="#strict-dynamic-usage"><span class="secno">8.2</span> <span class="content"> Usage of "<code>'strict-dynamic'</code>" </span></a>
<li><a href="#unsafe-hashed-attributes-usage"><span class="secno">8.3</span> <span class="content"> Usage of "<code>'unsafe-hashed-attributes'</code>" </span></a>
<li><a href="#external-hash"><span class="secno">8.4</span> <span class="content"> Whitelisting external JavaScript with hashes </span></a>
</ol>
<li>
<a href="#implementation-considerations"><span class="secno">9</span> <span class="content">Implementation Considerations</span></a>
<ol class="toc">
<li><a href="#extensions"><span class="secno">9.1</span> <span class="content">Vendor-specific Extensions and Addons</span></a>
</ol>
<li>
<a href="#iana-considerations"><span class="secno">10</span> <span class="content">IANA Considerations</span></a>
<ol class="toc">
<li><a href="#iana-registry"><span class="secno">10.1</span> <span class="content"> Directive Registry </span></a>
<li>
<a href="#iana-headers"><span class="secno">10.2</span> <span class="content"> Headers </span></a>
<ol class="toc">
<li><a href="#iana-csp"><span class="secno">10.2.1</span> <span class="content">Content-Security-Policy</span></a>
<li><a href="#iana-cspro"><span class="secno">10.2.2</span> <span class="content">Content-Security-Policy-Report-Only</span></a>
</ol>
</ol>
<li><a href="#acknowledgements"><span class="secno">11</span> <span class="content">Acknowledgements</span></a>
<li>
<a href="#conformance"><span class="secno"></span> <span class="content">Conformance</span></a>
<ol 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>
</ol>
<li>
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ol 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>
</ol>
<li>
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ol 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>
</ol>
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
<li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a>
</ol>
</nav>
<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 <dfn data-dfn-type="dfn" data-export="" id="content-security-policy">Content Security Policy<a class="self-link" href="#content-security-policy"></a></dfn> (CSP), a tool
which developers can use to lock down their applications in various ways,
mitigating the risk of content injection vulnerabilities such as cross-site scripting, and
reducing the privilege with which their applications execute.</p>
<p>CSP is not intended as a first line of defense against content injection
vulnerabilities. Instead, CSP is best used as defense-in-depth. It reduces
the harm that a malicious injection can cause, but it is not a replacement for
careful input validation and output encoding.</p>
<p>This document is an iteration on Content Security Policy Level 2, with the
goal of more clearly explaining the interactions between CSP, HTML, and Fetch
on the one hand, and providing clear hooks for modular extensibility on the
other. Ideally, this will form a stable core upon which we can build new
functionality.</p>
<h3 class="heading settled" data-level="1.1" id="examples"><span class="secno">1.1. </span><span class="content">Examples</span><a class="self-link" href="#examples"></a></h3>
<h4 class="heading settled" data-level="1.1.1" id="example-basic"><span class="secno">1.1.1. </span><span class="content">Control Execution</span><a class="self-link" href="#example-basic"></a></h4>
<div class="example" id="example-1451d1f8">
<a class="self-link" href="#example-1451d1f8"></a> MegaCorp Inc’s developers want to protect themselves against cross-site
scripting attacks. They can mitigate the risk of script injection by
ensuring that their trusted CDN is the only origin from which script can
load and execute. Moreover, they wish to ensure that no plugins can
execute in their pages' contexts. The following policy has that effect:
<pre>Content-Security-Policy: script-src https://cdn.example.com/scripts/; object-src 'none'
</pre>
</div>
<h3 class="heading settled" data-level="1.2" id="goals"><span class="secno">1.2. </span><span class="content">Goals</span><a class="self-link" href="#goals"></a></h3>
<p>Content Security Policy aims to do to a few related things:</p>
<ol>
<li data-md="">
<p>Mitigate the risk of content-injection attacks by giving developers
fairly granular control over</p>
<ul>
<li data-md="">
<p>The resources which can be requested (and subsequently embedded or
executed) on behalf of a specific <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/html5/dom.html#document">Document</a></code> or <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#worker">Worker</a></code></p>
<li data-md="">
<p>The execution of inline script</p>
<li data-md="">
<p>Dynamic code execution (via <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262#sec-eval-x">eval()</a></code> and similar constructs)</p>
<li data-md="">
<p>The application of inline style</p>
</ul>
<li data-md="">
<p>Mitigate the risk of attacks which require a resource to be embedded
in a malicious context (the "Pixel Perfect" attack described in <a data-link-type="biblio" href="#biblio-timing">[TIMING]</a>, for example) by giving developers granular control over the
origins which can embed a given resource.</p>
<li data-md="">
<p>Provide a policy framework which allows developers to reduce the privilege
of their applications.</p>
<li data-md="">
<p>Provide a reporting mechanism which allows developers to detect flaws
being exploited in the wild.</p>
</ol>
<h3 class="heading settled" data-level="1.3" id="changes-from-level-2"><span class="secno">1.3. </span><span class="content">Changes from Level 2</span><a class="self-link" href="#changes-from-level-2"></a></h3>
<p>This document describes an evolution of the Content Security Policy Level 2
specification <a data-link-type="biblio" href="#biblio-csp2">[CSP2]</a>. The following is a high-level overview of the changes:</p>
<ol>
<li data-md="">
<p>The specification has been rewritten from the ground up in terms of the <a data-link-type="biblio" href="#biblio-fetch">[FETCH]</a> specification, which should make it simpler to integrate CSP’s
requirements and restrictions with other specifications (and with
Service Workers in particular).</p>
<li data-md="">
<p>The <code>frame-src</code> directive, which was deprecated in CSP Level
2, has been undeprecated, and a <code>worker-src</code> directive added. Both defer
to <code>child-src</code> if not present (which defers to <code>default-src</code> in turn).</p>
<li data-md="">
<p>The URL matching algorithm now treats insecure schemes and ports as
matching their secure variants. That is, the source expression <code>http://example.com:80</code> will match both <code>http://example.com:80</code> and <code>https://example.com:443</code>.</p>
<p>Likewise, <code>'self'</code> now matches <code>https:</code> and <code>wss:</code> variants of the page’s
origin, even on pages whose scheme is <code>http</code>.</p>
<li data-md="">
<p>Violation reports generated from inline script or style will now report
"<code>inline</code>" as the blocked resource. Likewise, blocked <code>eval()</code> execution
will report "<code>eval</code>" as the blocked resource.</p>
<li data-md="">
<p>The <code>manifest-src</code> directive has been added.</p>
<li data-md="">
<p>The <code>report-uri</code> directive is deprecated in favor of the new <code>report-to</code> directive, which relies on <a data-link-type="biblio" href="#biblio-oob-reporting">[OOB-REPORTING]</a> as infrastructure.</p>
<li data-md="">
<p>The <code>'strict-dynamic'</code> source expression will now allow script which
executes on a page to load more script via non-<a data-link-type="dfn" href="https://www.w3.org/TR/html5/scripting-1.html#parser-inserted">parser-inserted</a> <code><a data-link-type="element" href="https://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code> elements. Details are in <a href="#strict-dynamic-usage">§8.2 Usage of "'strict-dynamic'"</a>.</p>
<li data-md="">
<p>The <code>'unsafe-hashed-attributes'</code> source expression will now allow event
handlers and style attributes to match hash source expressions. Details
in <a href="#unsafe-hashed-attributes-usage">§8.3 Usage of "'unsafe-hashed-attributes'"</a>.</p>
<li data-md="">
<p>The <a data-link-type="dfn" href="#source-expression" id="ref-for-source-expression-1">source expression</a> matching has been changed to require explicit whitelisting
of any non-<a data-link-type="dfn" href="https://url.spec.whatwg.org/#network-scheme">network scheme</a>, rather than <a data-link-type="dfn" href="https://url.spec.whatwg.org/#local-scheme">local scheme</a>, as described
in <a href="#match-url-to-source-expression">§6.1.13.4 Does url match expression in origin with redirect count?</a>.</p>
<li data-md="">
<p>Hash-based source expressions may now whitelist external scripts if the <code><a data-link-type="element" href="https://www.w3.org/TR/html5/scripting-1.html#the-script-element">script</a></code> element that triggers the request specifies a set of integrity
metadata which is whitelisted by the current policy. Details in <a href="#external-hash">§8.4 Whitelisting external JavaScript with hashes</a>.</p>
<li data-md="">
<p>The <a data-link-type="dfn" href="#disown-opener" id="ref-for-disown-opener-1"><code>disown-opener</code></a> directive ensures that a resource can’t be opened
in such a way as to give another browsing context control over its contents.</p>
</ol>
</section>
<section>
<h2 class="heading settled" data-level="2" id="framework"><span class="secno">2. </span><span class="content">Framework</span><a class="self-link" href="#framework"></a></h2>
<h3 class="heading settled" data-level="2.1" id="framework-policy"><span class="secno">2.1. </span><span class="content">Policies</span><a class="self-link" href="#framework-policy"></a></h3>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="policy">policy</dfn> defines a set of allowed and
restricted behaviors, and may be applied to a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/html5/browsers.html#dom-window">Window</a></code> or <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/workers.html#workerglobalscope">WorkerGlobalScope</a></code> as described in <a href="#initialize-global-object-csp">§4.2.2 Initialize a global object’s CSP list</a>.</p>
<p>Each policy has an associated <dfn class="dfn-paneled" data-dfn-for="policy" data-dfn-type="dfn" data-export="" id="policy-directive-set">directive set</dfn>, which
is a set of <a data-link-type="dfn" href="#directives" id="ref-for-directives-1">directives</a> that define the policy’s implications when
applied.</p>
<p>Each policy has an associated <dfn class="dfn-paneled" data-dfn-for="policy" data-dfn-type="dfn" data-export="" id="policy-disposition">disposition</dfn>, which is
either "<code>enforce</code>" or "<code>report</code>".</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="serialized-csp">serialized CSP</dfn> is an ASCII string, consisting of a
semicolon-delimited series of <a data-link-type="dfn" href="#serialized-directive" id="ref-for-serialized-directive-1">serialized directives</a>, adhering to the
following ABNF grammar <a data-link-type="biblio" href="#biblio-rfc5234">[RFC5234]</a>:</p>
<pre><dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-serialized-policy">serialized-policy</dfn> = <a data-link-type="grammar" href="#grammardef-serialized-directive" id="ref-for-grammardef-serialized-directive-1">serialized-directive</a> *( <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">OWS</a> ";" [ <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">OWS</a> <a data-link-type="grammar" href="#grammardef-serialized-directive" id="ref-for-grammardef-serialized-directive-2">serialized-directive</a> ] )
; <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">OWS</a> is defined in section 3.2.3 of RFC 7230
</pre>
<h4 class="heading settled dfn-paneled algorithm" data-algorithm="Parse a serialized CSP as disposition" data-dfn-type="dfn" data-level="2.1.1" data-lt="parse a serialized CSP" data-noexport="" id="parse-serialized-policy"><span class="secno">2.1.1. </span><span class="content"> Parse a <var>serialized CSP</var> as <var>disposition</var> </span></h4>
<p>Given a <a data-link-type="dfn" href="#serialized-csp" id="ref-for-serialized-csp-1">serialized CSP</a> (<var>serialized CSP</var>), and a <a data-link-type="dfn" href="#policy-disposition" id="ref-for-policy-disposition-1">disposition</a> (<var>disposition</var>), this algorithm will return a <a data-link-type="dfn" href="#policy" id="ref-for-policy-1">policy</a> object. If the string cannot be parsed, the resulting <a data-link-type="dfn" href="#policy" id="ref-for-policy-2">policy</a>’s <a data-link-type="dfn" href="#policy-directive-set" id="ref-for-policy-directive-set-1">directive set</a> will be empty.</p>
<ol>
<li data-md="">
<p>Let <var>policy</var> be a new <a data-link-type="dfn" href="#policy" id="ref-for-policy-3">policy</a> with an empty <a data-link-type="dfn" href="#policy-directive-set" id="ref-for-policy-directive-set-2">directive set</a>, and a <a data-link-type="dfn" href="#policy-disposition" id="ref-for-policy-disposition-2">disposition</a> of <var>disposition</var>.</p>
<li data-md="">
<p>For each <var>token</var> returned by <a data-link-type="dfn" href="https://www.w3.org/TR/html5/infrastructure.html#strictly-split-a-string">strictly splitting</a> <var>serialized
CSP</var> on the U+003B SEMICOLON character (<code>;</code>):</p>
<ol>
<li data-md="">
<p><a data-link-type="dfn" href="https://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace">Strip leading and trailing whitespace</a> from <var>token</var>.</p>
<li data-md="">
<p>If <var>token</var> is an empty string, skip the remaining substeps
and continue to the next item.</p>
<li data-md="">
<p>Let <var>directive name</var> be the result of <a data-link-type="dfn" href="https://www.w3.org/TR/html5/infrastructure.html#collect-a-sequence-of-characters">collecting a sequence of
characters</a> from <var>token</var> which are not <a data-link-type="dfn" href="https://www.w3.org/TR/html5/infrastructure.html#space-characters">space
characters</a>.</p>
<li data-md="">
<p>If <var>policy</var>’s <a data-link-type="dfn" href="#policy-directive-set" id="ref-for-policy-directive-set-3">directive set</a> contains a <a data-link-type="dfn" href="#directives" id="ref-for-directives-2">directive</a> whose <a data-link-type="dfn" href="#directive-name" id="ref-for-directive-name-1">name</a> is <var>directive
name</var>, skip the remaining substeps and continue to the next item.</p>
<p>The user agent SHOULD notify developers that a directive was ignored.
A console warning might be appropriate, for example.</p>
<li data-md="">
<p>Let <var>directive value</var> be the result of <a data-link-type="dfn" href="https://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-spaces">splitting <var>token</var> on
spaces</a>.</p>
<li data-md="">
<p>Let <var>directive</var> be a new <a data-link-type="dfn" href="#directives" id="ref-for-directives-3">directive</a> whose <a data-link-type="dfn" href="#directive-name" id="ref-for-directive-name-2">name</a> is <var>directive name</var>, and <a data-link-type="dfn" href="#directive-value" id="ref-for-directive-value-1">value</a> is <var>directive value</var>.</p>
<li data-md="">
<p>Add <var>directive</var> to <var>policy</var>’s <a data-link-type="dfn" href="#policy-directive-set" id="ref-for-policy-directive-set-4">directive set</a>.</p>
</ol>
<li data-md="">
<p>Return <var>policy</var>.</p>
</ol>
<h4 class="heading settled algorithm" data-algorithm="Parse a serialized CSP list as disposition" data-level="2.1.2" id="parse-serialized-policy-list"><span class="secno">2.1.2. </span><span class="content"> Parse a serialized CSP <var>list</var> as <var>disposition</var> </span><a class="self-link" href="#parse-serialized-policy-list"></a></h4>
<p>Given a string (<var>list</var>) and a <a data-link-type="dfn" href="#policy-disposition" id="ref-for-policy-disposition-3">disposition</a> (<var>disposition</var>)
which contains a comma-delimited series of <a data-link-type="dfn" href="#serialized-csp" id="ref-for-serialized-csp-2">serialized CSP</a> strings, the
following algorithm will return a list of <a data-link-type="dfn" href="#policy" id="ref-for-policy-4">policy</a> objects:</p>
<ol>
<li data-md="">
<p>Let <var>policies</var> be an empty list.</p>
<li data-md="">
<p>For each <var>token</var> returned by <a data-link-type="dfn" href="https://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-commas">splitting <var>list</var> on commas</a>:</p>
<ol>
<li data-md="">
<p>Let <var>policy</var> be the result of executing <a href="#parse-serialized-policy" id="ref-for-parse-serialized-policy-1">§2.1.1 Parse a serialized CSP as disposition</a> on <var>token</var> with <var>disposition</var>.</p>
<li data-md="">
<p>If <var>policy</var>’s <a data-link-type="dfn" href="#policy-directive-set" id="ref-for-policy-directive-set-5">directive set</a> is empty, skip the
remaining substeps, and continue to the next item.</p>
<li data-md="">
<p>Add <var>policy</var> to <var>policies</var>.</p>
</ol>
<li data-md="">
<p>Return <var>policies</var>.</p>
</ol>
<h3 class="heading settled" data-level="2.2" id="framework-directives"><span class="secno">2.2. </span><span class="content">Directives</span><a class="self-link" href="#framework-directives"></a></h3>
<p>Each <a data-link-type="dfn" href="#policy" id="ref-for-policy-5">policy</a> contain a set of <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="directives">directives</dfn>, each of which controls
a specific behavior. The directives defined in this document are described in
detail in <a href="#csp-directives">§6 Content Security Policy Directives</a>.</p>
<p>Each <a data-link-type="dfn" href="#directives" id="ref-for-directives-4">directive</a> is a <dfn class="dfn-paneled" data-dfn-for="directive" data-dfn-type="dfn" data-export="" id="directive-name">name</dfn> / <dfn class="dfn-paneled" data-dfn-for="directive" data-dfn-type="dfn" data-export="" id="directive-value">value</dfn> pair. The <a data-link-type="dfn" href="#directive-name" id="ref-for-directive-name-3">name</a> is a
non-empty string, and the <a data-link-type="dfn" href="#directive-value" id="ref-for-directive-value-2">value</a> is a set of non-empty strings. The <a data-link-type="dfn" href="#directive-value" id="ref-for-directive-value-3">value</a> set MAY be empty.</p>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="serialized-directive">serialized directive</dfn> is an ASCII string, consisting of one or more
whitespace-delimited tokens, and adhering to the following ABNF <a data-link-type="biblio" href="#biblio-rfc5234">[RFC5234]</a>:</p>
<pre><dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-serialized-directive">serialized-directive</dfn> = <a data-link-type="grammar" href="#grammardef-directive-name" id="ref-for-grammardef-directive-name-1">directive-name</a> [ <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">RWS</a> <a data-link-type="grammar" href="#grammardef-directive-value" id="ref-for-grammardef-directive-value-1">directive-value</a> ]
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-directive-name">directive-name</dfn> = 1*( <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">ALPHA</a> / <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">DIGIT</a> / "-" )
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-directive-value">directive-value</dfn> = *( %x09 / %x20-%x2B / %x2D-%x3A / %x3C-%7E )
; Directive values may contain whitespace and <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">VCHAR</a> characters,
; excluding ";" and ","
; <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">RWS</a> is defined in section 3.2.3 of RFC7230. <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">ALPHA</a>, <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">DIGIT</a>, and
; <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">VCHAR</a> are defined in Appendix B.1 of RFC 5234.
</pre>
<p><a data-link-type="dfn" href="#directives" id="ref-for-directives-5">Directives</a> have five associated algorithms:</p>
<ol>
<li data-md="">
<p>A <dfn class="dfn-paneled" data-dfn-for="directive" data-dfn-type="dfn" data-export="" id="directive-pre-request-check">pre-request check</dfn>, which takes a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request">request</a> and a <a data-link-type="dfn" href="#policy" id="ref-for-policy-6">policy</a> as an argument, and is executed during <a href="#should-block-request">§4.1.3 Should request be blocked by Content Security Policy?</a>. This algorithm returns "<code>Allowed</code>" unless
otherwise specified.</p>
<li data-md="">
<p>A <dfn class="dfn-paneled" data-dfn-for="directive" data-dfn-type="dfn" data-export="" id="directive-post-request-check">post-request check</dfn>, which takes a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request">request</a>, a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response">response</a>, and a <a data-link-type="dfn" href="#policy" id="ref-for-policy-7">policy</a> as arguments, and
is executed during <a href="#should-block-response">§4.1.4 Should response to request be blocked by Content
Security Policy?</a>. This algorithm returns
"<code>Allowed</code>" unless otherwise specified.</p>
<li data-md="">
<p>A <dfn class="dfn-paneled" data-dfn-for="directive" data-dfn-type="dfn" data-export="" id="directive-response-check">response check</dfn>, which takes a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request">request</a>, a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response">response</a>, and a <a data-link-type="dfn" href="#policy" id="ref-for-policy-8">policy</a> as arguments, and
is executed during <a href="#should-block-response">§4.1.4 Should response to request be blocked by Content
Security Policy?</a>. This algorithm returns
"<code>Allowed</code>" unless otherwise specified.</p>
<li data-md="">
<p>An <dfn class="dfn-paneled" data-dfn-for="directive" data-dfn-type="dfn" data-export="" id="directive-inline-check">inline check</dfn>, which takes an <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#interface-element">Element</a></code> a
type string, and a soure string as arguments, and is executed during <a href="#should-block-inline">§4.2.3 Should element’s inline type behavior be blocked by Content Security Policy?</a>. This algorithm returns "<code>Allowed</code>" unless
otherwise specified.</p>
<li data-md="">
<p>An <dfn class="dfn-paneled" data-dfn-for="directive" data-dfn-type="dfn" data-export="" id="directive-initialization">initialization</dfn>, which takes a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/html5/dom.html#document">Document</a></code> or <a data-link-type="dfn" href="https://www.w3.org/TR/html5/webappapis.html#global-object">global object</a>, a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response">response</a>, and a <a data-link-type="dfn" href="#policy" id="ref-for-policy-9">policy</a> as
arguments. This algorithm is executed during <a href="#initialize-document-csp">§4.2.1 Initialize a Document's CSP list</a>,
and has no effect unless otherwise specified.</p>
</ol>
<h4 class="heading settled" data-level="2.2.1" id="framework-directive-source-list"><span class="secno">2.2.1. </span><span class="content">Source Lists</span><a class="self-link" href="#framework-directive-source-list"></a></h4>
<p>Many <a data-link-type="dfn" href="#directives" id="ref-for-directives-6">directives</a>' <a data-link-type="dfn" href="#directive-value" id="ref-for-directive-value-4">values</a> consist of <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="source-lists">source lists</dfn>: sets
of tokens which identify content that can be fetched and potentially embedded
or executed. These tokens represent one of the following types of <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" data-lt="source expression" id="source-expression">source
expression</dfn>:</p>
<ol>
<li data-md="">
<p>Keywords such as <a data-link-type="grammar" href="#grammardef-none" id="ref-for-grammardef-none-1"><code>'none'</code></a> and <a data-link-type="grammar" href="#grammardef-self" id="ref-for-grammardef-self-1"><code>'self'</code></a> (which match nothing and the current
URL’s origin, respectively)</p>
<li data-md="">
<p>Serialized URLs such as <code>https://example.com/path/to/file.js</code> (which matches a specific file) or <code>https://example.com/</code> (which matches everything on that origin)</p>
<li data-md="">
<p>Schemes such as <code>https:</code> (which matches any resource having
the specified scheme)</p>
<li data-md="">
<p>Hosts such as <code>example.com</code> (which matches any resource on
the host, regardless of scheme) or <code>*.example.com</code> (which
matches any resource on the host or any of its subdomains (and any of
its subdomains' subdomains, and so on))</p>
<li data-md="">
<p>Nonces such as <code>'nonce-qwertyu12345'</code> (which can match specific
elements on a page)</p>
<li data-md="">
<p>Digests such as <code>'sha256-abcd...'</code> (which can match specific
elements on a page)</p>
</ol>
<p>A <dfn data-dfn-type="dfn" data-export="" id="serialized-source-list">serialized source list<a class="self-link" href="#serialized-source-list"></a></dfn> is an ASCII string, consisting of a
space-delimited series of <a data-link-type="dfn" href="#source-expression" id="ref-for-source-expression-2">source expressions</a>, adhering to the
following ABNF grammar <a data-link-type="biblio" href="#biblio-rfc5234">[RFC5234]</a>:</p>
<pre><dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-serialized-source-list">serialized-source-list</dfn> = ( <a data-link-type="grammar" href="#grammardef-source-expression" id="ref-for-grammardef-source-expression-1">source-expression</a> *( <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">RWS</a> <a data-link-type="grammar" href="#grammardef-source-expression" id="ref-for-grammardef-source-expression-2">source-expression</a> ) ) / "<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-none">'none'</dfn>"
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-source-expression">source-expression</dfn> = <a data-link-type="grammar" href="#grammardef-scheme-source" id="ref-for-grammardef-scheme-source-1">scheme-source</a> / <a data-link-type="grammar" href="#grammardef-host-source" id="ref-for-grammardef-host-source-1">host-source</a> / <a data-link-type="grammar" href="#grammardef-keyword-source" id="ref-for-grammardef-keyword-source-1">keyword-source</a>
/ <a data-link-type="grammar" href="#grammardef-nonce-source" id="ref-for-grammardef-nonce-source-1">nonce-source</a> / <a data-link-type="grammar" href="#grammardef-hash-source" id="ref-for-grammardef-hash-source-1">hash-source</a>
; Schemes: "https:" / "custom-scheme:" / "another.custom-scheme:"
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-scheme-source">scheme-source</dfn> = <a data-link-type="grammar" href="#grammardef-scheme-part" id="ref-for-grammardef-scheme-part-1">scheme-part</a> ":"
; Hosts: "example.com" / "*.example.com" / "https://*.example.com:12/path/to/file.js"
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-host-source">host-source</dfn> = [ <a data-link-type="grammar" href="#grammardef-scheme-part" id="ref-for-grammardef-scheme-part-2">scheme-part</a> "://" ] <a data-link-type="grammar" href="#grammardef-host-part" id="ref-for-grammardef-host-part-1">host-part</a> [ <a data-link-type="grammar" href="#grammardef-port-part" id="ref-for-grammardef-port-part-1">port-part</a> ] [ <a data-link-type="grammar" href="#grammardef-path-part" id="ref-for-grammardef-path-part-1">path-part</a> ]
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-scheme-part">scheme-part</dfn> = <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc3986#section-3.1">scheme</a>
; <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc3986#section-3.1">scheme</a> is defined in section 3.1 of RFC 3986.
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-host-part">host-part</dfn> = "*" / [ "*." ] 1*<a data-link-type="grammar" href="#grammardef-host-char" id="ref-for-grammardef-host-char-1">host-char</a> *( "." 1*<a data-link-type="grammar" href="#grammardef-host-char" id="ref-for-grammardef-host-char-2">host-char</a> )
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-host-char">host-char</dfn> = <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">ALPHA</a> / <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">DIGIT</a> / "-"
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-port-part">port-part</dfn> = ":" ( 1*<a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">DIGIT</a> / "*" )
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-path-part">path-part</dfn> = <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc3986#section-3.3">path</a>
; <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc3986#section-3.3">path</a> is defined in section 3.3 of RFC 3986.
; Keywords:
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-keyword-source">keyword-source</dfn> = "<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-self">'self'</dfn>" / "<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-unsafe-inline">'unsafe-inline'</dfn>" / "<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-unsafe-eval">'unsafe-eval'</dfn>" / "<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-strict-dynamic">'strict-dynamic'</dfn>" / "<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-unsafe-hashed-attributes">'unsafe-hashed-attributes'</dfn>"
; Nonces: 'nonce-[nonce goes here]'
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-nonce-source">nonce-source</dfn> = "'nonce-" <a data-link-type="grammar" href="#grammardef-base64-value" id="ref-for-grammardef-base64-value-1">base64-value</a> "'"
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-base64-value">base64-value</dfn> = 1*( <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">ALPHA</a> / <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc5234#appendix-B.1">DIGIT</a> / "+" / "/" / "-" / "_" )*2( "=" )
; Digests: 'sha256-[digest goes here]'
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-hash-source">hash-source</dfn> = "'" <a data-link-type="grammar" href="#grammardef-hash-algorithm" id="ref-for-grammardef-hash-algorithm-1">hash-algorithm</a> "-" <a data-link-type="grammar" href="#grammardef-base64-value" id="ref-for-grammardef-base64-value-2">base64-value</a> "'"
<dfn class="dfn-paneled" data-dfn-type="grammar" data-export="" id="grammardef-hash-algorithm">hash-algorithm</dfn> = "sha256" / "sha384" / "sha512"
</pre>
<p>The <a data-link-type="grammar" href="#grammardef-host-char" id="ref-for-grammardef-host-char-3">host-char</a> production intentionally contains only ASCII
characters; internationalized domain names cannot be entered directly as part
of a <a data-link-type="dfn" href="#serialized-csp" id="ref-for-serialized-csp-3">serialized CSP</a>, but instead MUST be Punycode-encoded <a data-link-type="biblio" href="#biblio-rfc3492">[RFC3492]</a>. For example, the domain <code>üüüüüü.de</code> MUST be represented as <code>xn--tdaaaaaa.de</code>.</p>
<p class="note" role="note">Note: Though IP address 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-url-to-source-list">§6.1.13.3 Does url match source list?</a> for details). The security
properties of IP addresses are suspect, and authors ought to prefer hostnames
whenever possible.</p>
<p>A <code class="idl"><a data-link-type="idl" href="https://url.spec.whatwg.org/#url">URL</a></code> <dfn data-dfn-type="dfn" data-export="" id="matches-a-source-list">matches a source list<a class="self-link" href="#matches-a-source-list"></a></dfn> if the algorithm in <a href="#match-url-to-source-list">§6.1.13.3 Does url match source list?</a> returns <code>Matches</code>.</p>
<h3 class="heading settled" data-level="2.3" id="framework-violation"><span class="secno">2.3. </span><span class="content">Violations</span><a class="self-link" href="#framework-violation"></a></h3>
<p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="violation">violation</dfn> represents an action or resource which goes against the
set of <a data-link-type="dfn" href="#policy" id="ref-for-policy-10">policy</a> objects associated with a <a data-link-type="dfn" href="https://www.w3.org/TR/html5/webappapis.html#global-object">global object</a>.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-1">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-global-object">global object</dfn>, which
is the <a data-link-type="dfn" href="https://www.w3.org/TR/html5/webappapis.html#global-object">global object</a> whose <a data-link-type="dfn" href="#policy" id="ref-for-policy-11">policy</a> has been violated.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-2">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-url">url</dfn> which is its <a data-link-type="dfn" href="#violation-global-object" id="ref-for-violation-global-object-1">global object</a>’s <code class="idl"><a data-link-type="idl" href="https://url.spec.whatwg.org/#url">URL</a></code>.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-3">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-status">status</dfn> which is a
non-negative integer representing the HTTP status code of the resource for
which the global object was instantiated.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-4">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-resource">resource</dfn>, which is
either <code>null</code>, "<code>inline</code>", "<code>eval</code>", or a <code class="idl"><a data-link-type="idl" href="https://url.spec.whatwg.org/#url">URL</a></code>. It represents the resource
which violated the policy.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-5">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-referrer">referrer</dfn>, which is either <code>null</code>, or a <code class="idl"><a data-link-type="idl" href="https://url.spec.whatwg.org/#url">URL</a></code>. It represents the referrer of the resource whose policy
was violated.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-6">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-policy">policy</dfn>, which is the <a data-link-type="dfn" href="#policy" id="ref-for-policy-12">policy</a> that has been violated.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-7">violation</a> has an <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-effective-directive">effective directive</dfn> which is a non-empty string representing the <a data-link-type="dfn" href="#directives" id="ref-for-directives-7">directive</a> whose
enforcement caused the violation.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-8">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-source-file">source file</dfn>, which is
either <code>null</code> or a <code class="idl"><a data-link-type="idl" href="https://url.spec.whatwg.org/#url">URL</a></code>.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-9">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-line-number">line number</dfn>, which is
a non-negative integer.</p>
<p>Each <a data-link-type="dfn" href="#violation" id="ref-for-violation-10">violation</a> has a <dfn class="dfn-paneled" data-dfn-for="violation" data-dfn-type="dfn" data-export="" id="violation-column-number">column number</dfn>, which
is a non-negative integer.</p>
<h4 class="heading settled algorithm" data-algorithm="Create a violation object for global, policy, and directive" data-level="2.3.1" id="create-violation-for-global"><span class="secno">2.3.1. </span><span class="content"> Create a violation object for <var>global</var>, <var>policy</var>, and <var>directive</var> </span><a class="self-link" href="#create-violation-for-global"></a></h4>
<p>Given a <a data-link-type="dfn" href="https://www.w3.org/TR/html5/webappapis.html#global-object">global object</a> (<var>global</var>), a <a data-link-type="dfn" href="#policy" id="ref-for-policy-13">policy</a> (<var>policy</var>), and a
string (<var>directive</var>), the following algorithm creates a new <a data-link-type="dfn" href="#violation" id="ref-for-violation-11">violation</a> object, and populates it with an initial set of data:</p>
<ol>
<li data-md="">
<p>Let <var>violation</var> be a new <a data-link-type="dfn" href="#violation" id="ref-for-violation-12">violation</a> whose <a data-link-type="dfn" href="#violation-global-object" id="ref-for-violation-global-object-2">global
object</a> is <var>global</var>, <a data-link-type="dfn" href="#violation-policy" id="ref-for-violation-policy-1">policy</a> is <var>policy</var>, <a data-link-type="dfn" href="#violation-effective-directive" id="ref-for-violation-effective-directive-1">effective directive</a> is <var>directive</var>, and <a data-link-type="dfn" href="#violation-resource" id="ref-for-violation-resource-1">resource</a> is <code>null</code>.</p>
<li data-md="">
<p>If the user agent is currently executing script, and can extract a source
file’s URL, line number, and column number from the <var>global</var>, set <var>violation</var>’s <a data-link-type="dfn" href="#violation-source-file" id="ref-for-violation-source-file-1">source file</a>, <a data-link-type="dfn" href="#violation-line-number" id="ref-for-violation-line-number-1">line
number</a>, and <a data-link-type="dfn" href="#violation-column-number" id="ref-for-violation-column-number-1">column number</a> accordingly.</p>
<p class="issue" id="issue-c404edb5"><a class="self-link" href="#issue-c404edb5"></a> Is this kind of thing specified anywhere? I didn’t see anything
that looked useful in <a data-link-type="biblio" href="#biblio-ecma262">[ECMA262]</a>.</p>
<li data-md="">
<p>If <var>global</var> is a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/html5/browsers.html#dom-window">Window</a></code> object, set <var>violation</var>’s <a data-link-type="dfn" href="#violation-referrer" id="ref-for-violation-referrer-1">referrer</a> to <var>global</var>’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/html5/browsers.html#dom-document-2">document</a></code>'s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/html5/dom.html#dom-document-referrer">referrer</a></code>.</p>
<li data-md="">
<p>Set <var>violation</var>’s <a data-link-type="dfn" href="#violation-status" id="ref-for-violation-status-1">status</a> to the HTTP status code
for the resource associated with <var>violation</var>’s <a data-link-type="dfn" href="#violation-global-object" id="ref-for-violation-global-object-3">global
object</a>.</p>
<p class="issue" id="issue-99576800"><a class="self-link" href="#issue-99576800"></a> How, exactly, do we get the status code? We don’t actually store it
anywhere.</p>
<li data-md="">
<p>Return <var>violation</var>.</p>
</ol>
<h4 class="heading settled algorithm" data-algorithm="Create a violation object for request, policy, and directive" data-level="2.3.2" id="create-violation-for-request"><span class="secno">2.3.2. </span><span class="content"> Create a violation object for <var>request</var>, <var>policy</var>, and <var>directive</var> </span><a class="self-link" href="#create-violation-for-request"></a></h4>
<p>Given a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request">request</a> (<var>request</var>), a <a data-link-type="dfn" href="#policy" id="ref-for-policy-14">policy</a> (<var>policy</var>), and a string
(<var>directive</var>), the following algorithm creates a new <a data-link-type="dfn" href="#violation" id="ref-for-violation-13">violation</a> object,
and populates it with an initial set of data:</p>
<ol>
<li data-md="">
<p>Let <var>violation</var> be the result of executing <a href="#create-violation-for-global">§2.3.1 Create a violation object for global, policy, and directive</a> on <var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-client">client</a>’s <a data-link-type="dfn" href="https://www.w3.org/TR/html5/webappapis.html#concept-settings-object-global">global object</a>, <var>policy</var>, and <var>directive</var>.</p>
<li data-md="">
<p>Set <var>violation</var>’s <a data-link-type="dfn" href="#violation-resource" id="ref-for-violation-resource-2">resource</a> to <var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-url">url</a>.</p>
<p class="note" role="note">Note: We use <var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-url">url</a>, and <em>not</em> its <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-current-url">current url</a>, as the latter might contain information
about redirect targets to which the page MUST NOT be given access.</p>
<li data-md="">
<p>Return <var>violation</var>.</p>
</ol>
</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>A server MAY declare a <a data-link-type="dfn" href="#policy" id="ref-for-policy-15">policy</a> for a particular <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc7231#section-3">resource
representation</a> via an HTTP response header field whose value is a <a data-link-type="dfn" href="#serialized-csp" id="ref-for-serialized-csp-4">serialized CSP</a>. This mechanism is defined in detail in <a href="#csp-header">§3.1 The Content-Security-Policy HTTP Response Header Field</a> and <a href="#cspro-header">§3.2 The Content-Security-Policy-Report-Only HTTP Response Header Field</a>, and the integration with Fetch
and HTML is described in <a href="#fetch-integration">§4.1 Integration with Fetch</a> and <a href="#html-integration">§4.2 Integration with HTML</a>.</p>
<p>A <a data-link-type="dfn" href="#policy" id="ref-for-policy-16">policy</a> may also be declared inline in an HTML document via a <code><a data-link-type="element" href="https://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> element’s <code><a data-link-type="element-sub" href="https://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv">http-equiv</a></code> attribute, as described in <a href="#meta-element">§3.3 The <meta> element</a>.</p>
<h3 class="heading settled" data-level="3.1" id="csp-header"><span class="secno">3.1. </span><span class="content"> The <code>Content-Security-Policy</code> HTTP Response Header Field </span><a class="self-link" href="#csp-header"></a></h3>
<p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="header-content-security-policy"><code>Content-Security-Policy</code></dfn> HTTP response header field
is the preferred mechanism for delivering a policy from a server to a client.
The header’s value is represented by the following ABNF <a data-link-type="biblio" href="#biblio-rfc5234">[RFC5234]</a>:</p>
<pre>Content-Security-Policy = 1#<a data-link-type="grammar" href="#grammardef-serialized-policy" id="ref-for-grammardef-serialized-policy-1">serialized-policy</a>
</pre>
<div class="example" id="example-30ac7d45">
<a class="self-link" href="#example-30ac7d45"></a>
<pre><a data-link-type="dfn" href="#header-content-security-policy" id="ref-for-header-content-security-policy-1">Content-Security-Policy</a>: script-src 'self';
report-to csp-reporting-endpoint
</pre>
</div>
<p>A server MAY send different <code>Content-Security-Policy</code> header field
values with different <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc7231#section-3">representations</a> of the same resource.</p>
<p>A server SHOULD NOT send more than one HTTP response header field named
"<code>Content-Security-Policy</code>" with a given <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc7231#section-3">resource
representation</a>.</p>
<p>When the user agent receives a <code>Content-Security-Policy</code> header field, it
MUST <a data-link-type="dfn" href="#parse-serialized-policy" id="ref-for-parse-serialized-policy-2">parse</a> and <a data-link-type="dfn" href="#enforced" id="ref-for-enforced-1">enforce</a> each <a data-link-type="dfn" href="#serialized-csp" id="ref-for-serialized-csp-5">serialized CSP</a> it contains as described in <a href="#fetch-integration">§4.1 Integration with Fetch</a>, <a href="#html-integration">§4.2 Integration with HTML</a>.</p>
<h3 class="heading settled" data-level="3.2" id="cspro-header"><span class="secno">3.2. </span><span class="content"> The <code>Content-Security-Policy-Report-Only</code> HTTP Response Header Field </span><a class="self-link" href="#cspro-header"></a></h3>
<p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="header-content-security-policy-report-only"><code>Content-Security-Policy-Report-Only</code></dfn> HTTP response
header field allows web developers to experiment with policies by monitoring
(but not enforcing) their effects. The header’s value is represented by the
following ABNF <a data-link-type="biblio" href="#biblio-rfc5234">[RFC5234]</a>:</p>
<pre>Content-Security-Policy-Report-Only = 1#<a data-link-type="grammar" href="#grammardef-serialized-policy" id="ref-for-grammardef-serialized-policy-2">serialized-policy</a>
</pre>
<p>This header field allows developers to piece together their security policy in
an iterative fashion, deploying a report-only policy based on their best
estimate of how their site behaves, watching for violation reports, and then
moving to an enforced policy once they’ve gained confidence in that behavior.</p>
<div class="example" id="example-d1b5cb79">
<a class="self-link" href="#example-d1b5cb79"></a>
<pre><a data-link-type="dfn" href="#header-content-security-policy-report-only" id="ref-for-header-content-security-policy-report-only-1">Content-Security-Policy-Report-Only</a>: script-src 'self';
report-to csp-reporting-endpoint
</pre>
</div>
<p>A server MAY send different <code>Content-Security-Policy-Report-Only</code> header field values with different <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc7231#section-3">representations</a> of the same
resource.</p>
<p>A server SHOULD NOT send more than one HTTP response header field named
"<code>Content-Security-Policy-Report-Only</code>" with a given <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc7231#section-3">resource
representation</a>.</p>
<p>When the user agent receives a <code>Content-Security-Policy-Report-Only</code> header
field, it MUST <a data-link-type="dfn" href="#parse-serialized-policy" id="ref-for-parse-serialized-policy-3">parse</a> and <a data-link-type="dfn" href="#monitored" id="ref-for-monitored-1">monitor</a> each <a data-link-type="dfn" href="#serialized-csp" id="ref-for-serialized-csp-6">serialized CSP</a> it contains as described in <a href="#fetch-integration">§4.1 Integration with Fetch</a> and <a href="#html-integration">§4.2 Integration with HTML</a>.</p>
<p class="note" role="note">Note: The <a data-link-type="dfn" href="#header-content-security-policy-report-only" id="ref-for-header-content-security-policy-report-only-2"><code>Content-Security-Policy-Report-Only</code></a> header is <strong>not</strong> supported inside a <code><a data-link-type="element" href="https://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> element.</p>
<h3 class="heading settled" data-level="3.3" id="meta-element"><span class="secno">3.3. </span><span class="content"> The <code><meta></code> element </span><a class="self-link" href="#meta-element"></a></h3>
<p>A <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/html5/dom.html#document">Document</a></code> may deliver a policy via one or more HTML <code><a data-link-type="element" href="https://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> elements
whose <code><a data-link-type="element-sub" href="https://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv">http-equiv</a></code> attributes are an <a data-link-type="dfn" href="https://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>
<div class="example" id="example-cff5e786">
<a class="self-link" href="#example-cff5e786"></a>
<pre><meta http-equiv="Content-Security-Policy" content="script-src 'self'">
</pre>
</div>
<p>Implementation details can be found in HTML’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/#attr-meta-http-equiv-content-security-policy"><code>Content-Security-Policy</code> <code>http-equiv</code> processing instructions</a> <a data-link-type="biblio" href="#biblio-html">[HTML]</a>.</p>
<p class="note" role="note">Note: The <a data-link-type="dfn" href="#header-content-security-policy-report-only" id="ref-for-header-content-security-policy-report-only-3"><code>Content-Security-Policy-Report-Only</code></a> header is <em>not</em> supported inside a <code><a data-link-type="element" href="https://www.w3.org/TR/html5/document-metadata.html#the-meta-element">meta</a></code> element. Neither are the <code>report-uri</code>, <code>frame-ancestors</code>, and <code>sandbox</code> directives.</p>
<p>Authors are <em>strongly encouraged</em> to place <code><a data-link-type="element" href="https://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="https://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="https://www.w3.org/TR/html5/document-metadata.html#the-link-element">link</a></code> and <code><a data-link-type="element" href="https://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="https://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 policy specified via a <code><a data-link-type="element" href="https://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="#multiple-policies">§8.1 The effect of multiple policies</a>.</p>
<p class="note" role="note">Note: Modifications to the <code><a data-link-type="element-sub" href="https://www.w3.org/TR/html5/document-metadata.html#attr-meta-content">content</a></code> attribute of a <code><a data-link-type="element" href="https://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>
</section>
<section>
<h2 class="heading settled" data-level="4" id="integrations"><span class="secno">4. </span><span class="content">Integrations</span><a class="self-link" href="#integrations"></a></h2>
<p><em>This section is non-normative.</em></p>
<p>This document defines a set of algorithms which are used in other
specifications in order to implement the functionality. These
integrations are outlined here for clarity, but those external
documents are the normative references which ought to be consulted for
detailed information.</p>
<h3 class="heading settled" data-level="4.1" id="fetch-integration"><span class="secno">4.1. </span><span class="content"> Integration with Fetch </span><a class="self-link" href="#fetch-integration"></a></h3>
<p>A number of <a data-link-type="dfn" href="#directives" id="ref-for-directives-8">directives</a> control resource loading in one way or
another. This specification provides algorithms which allow Fetch to make
decisions about whether or not a particular <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request">request</a> should be blocked
or allowed, and about whether a particular <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response">response</a> should be replaced
with a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-network-error">network error</a>.</p>
<ol>
<li data-md="">