Permalink
Fetching contributors…
Cannot retrieve contributors at this time
3473 lines (2835 sloc) 249 KB
<!DOCTYPE html><html lang=en><head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>Content Security Policy Level 2</title>
<link href=./default.css rel=stylesheet type=text/css>
<link href=https://www.w3.org/StyleSheets/TR/W3C-LC rel=stylesheet type=text/css>
<style>
table {
text-align: left;
margin: 20px;
width: 100%;
border-collapse: collapse;
}
tbody tr:nth-child(odd) {
background-color: #EEE;
}
th {
border-bottom: 1px solid #999;
padding: 0.5em;
}
td:first-child {
width: 30%;
padding-right: 1em;
}
td {
vertical-align: top;
padding: 0.5em;
}
tbody th {
border: 0;
background-color: #FFF;
}
tr.section {
border-top: 1px solid #999;
vertical-align: top;
}
</style>
</head>
<body class=h-entry>
<div class=head>
<p data-fill-with=logo><a class=logo href=http://www.w3.org/>
<img alt=W3C height=48 src=https://www.w3.org/Icons/w3c_home width=72>
</a>
</p>
<h1 class="p-name no-ref" id=title>Content Security Policy Level 2</h1>
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>W3C Last Call Working Draft,
<span class=dt-updated><span class=value-title title=20140703>03 July 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl><dt>Feedback:<dd><a href="mailto:public-webappsec@w3.org?subject=%5BCSP%5D%20feedback">public-webappsec@w3.org</a>
with subject line
“<kbd>[CSP] <var>… message topic …</var></kbd>”(<a U00027="" href=http://lists.w3.org/Archives/Public/public-webappsec/ rel=discussion>archives</a>)<dt>Editor’s Draft:<dd><a href=https://w3c.github.io/webappsec/specs/content-security-policy/>https://w3c.github.io/webappsec/specs/content-security-policy/</a><dt>Former Editors:<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:brandon@hackmill.com>Brandon Sterne</a> (<span class="p-org org">formerly of Mozilla Corporation</span>)<dt>Editors:<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:mkwst@google.com>Mike West</a> (<span class="p-org org">Google Inc.</span>)<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:w3c@adambarth.com>Adam Barth</a> (<span class="p-org org">Google Inc.</span>)<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:dveditz@mozilla.com>Dan Veditz</a> (<span class="p-org org">Mozilla Corporation</span>)<dt>Latest version:<dd><a href=http://www.w3c.org/TR/CSP/>http://www.w3c.org/TR/CSP/</a><dt>This version:<dd><a class=u-url href=http://www.w3.org/TR/2014/WD-CSP-2-20140703/>http://www.w3.org/TR/2014/WD-CSP-2-20140703/</a></dl></div>
<div data-fill-with=warning></div>
<p class=copyright data-fill-with=copyright><a href=http://www.w3.org/Consortium/Legal/ipr-notice#Copyright>Copyright</a> © 2014
<a href=http://www.w3.org/><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup>
(<a href=http://www.csail.mit.edu/><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>,
<a href=http://www.ercim.eu/><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href=http://www.keio.ac.jp/>Keio</a>, <a href=http://ev.buaa.edu.cn/>Beihang</a>),
All Rights Reserved.
<abbr title="World Wide Web Consortium">W3C</abbr> <a href=http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer>liability</a>,
<a href=http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks>trademark</a> and
<a href=http://www.w3.org/Consortium/Legal/copyright-documents>document use</a>
rules apply.
</p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled heading" id=abstract><span class=content>Abstract</span></h2>
<p class=p-summary data-fill-with=abstract><p>This document defines a policy language used to declare a set of content restrictions for a web resource, and a mechanism for transmitting the policy from a server to a client where the policy is enforced.</p>
</p>
<h2 class="no-num no-toc no-ref heading settled heading" id=status><span class=content>Status of this document</span></h2>
<div data-fill-with=status><p>
<em>This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the <a href=http://www.w3.org/TR/>W3C technical reports
index at http://www.w3.org/TR/.</a></em>
<p>
This document was published by the
<a href=http://www.w3.org/2011/webappsec/>Web Application Security Working Group</a>
as a Working Draft. This document is intended to become a W3C Recommendation.
<p>
The (<a href=http://lists.w3.org/Archives/Public/public-webappsec/>archived</a>) public mailing list
<a href="mailto:public-webappsec@w3.org?Subject=%5BCSP%5D%20PUT%20SUBJECT%20HERE">public-webappsec@w3.org</a>
(see <a href=http://www.w3.org/Mail/Request>instructions</a>)
is preferred for discussion of this specification.
When sending e-mail,
please put the text “CSP” in the subject,
preferably like this:
“[CSP] <em>…summary of comment…</em>”
<p>
Publication as a Last Call Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite this
document as other than work in progress.
<p>
This document was produced by the
<a href=http://www.w3.org/2011/webappsec/>Web Application Security Working Group</a>.
<p>
This document was produced by a group operating under
the <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/>5 February 2004 W3C Patent Policy</a>.
W3C maintains a <a href=http://www.w3.org/2004/01/pp-impl/32061/status rel=disclosure>public list of any patent disclosures</a>
made in connection with the deliverables of the group;
that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent which the individual believes contains <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential>Essential Claim(s)</a>
must disclose the information in accordance with <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure>section 6 of the W3C Patent Policy</a>.
<p>
This specification is a <strong>Last Call Working Draft</strong>. All
persons are encouraged to review this document and <strong>send comments
to the <a href=http://lists.w3.org/Archives/Public/public-webappsec/>public-webappsec</a>
mailing list</strong> as described above. The <strong>deadline for
comments</strong> is <strong>13 August 2014</strong>.
</div>
<div data-fill-with=at-risk><p>The following features are at-risk, and may be dropped during the CR period:
<ul><li>The <a data-link-type=dfn href=#referrer title=referrer>referrer</a> directive.<li>The <a data-link-type=dfn href=#reflected-xss title=reflected-xss>reflected-xss</a> directive.</ul></div>
<h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><ul class=toc>
<li><a href=#intro><span class=secno>1</span>Introduction</a>
<li><a href=#key-concepts><span class=secno>2</span>Key Concepts and Terminology</a>
<li><a href=#policy-delivery><span class=secno>3</span>Policy Delivery</a>
<ul class=toc>
<li><a href=#content-security-policy-header-field><span class=secno>3.1</span> <code>Content-Security-Policy</code> Header Field </a>
<li><a href=#content-security-policy-report-only-header-field><span class=secno>3.2</span> <code>Content-Security-Policy-Report-Only</code> Header Field </a>
<li><a href=#delivery-html-meta-element><span class=secno>3.3</span> HTML <code><span data-link-type=element title=meta>meta</span></code> Element </a>
<li><a href=#ch-csp-client-hint><span class=secno>3.4</span>The <code>CH-CSP</code> Client Hint</a>
<li><a href=#enforcing-multiple-policies><span class=secno>3.5</span>Enforcing multiple policies.</a>
<li><a href=#which-policy-applies><span class=secno>3.6</span>Policy applicability</a></ul>
<li><a href=#syntax-and-algorithms><span class=secno>4</span>Syntax and Algorithms</a>
<ul class=toc>
<li><a href=#policy-syntax><span class=secno>4.1</span>Policy Syntax</a>
<ul class=toc>
<li><a href=#policy-parsing><span class=secno>4.1.1</span>Parsing Policies</a></ul>
<li><a href=#source-list-syntax><span class=secno>4.2</span>Source List Syntax</a>
<ul class=toc>
<li><a href=#source-list-parsing><span class=secno>4.2.1</span>Parsing Source Lists</a>
<li><a href=#match-source-expression><span class=secno>4.2.2</span>Matching Source Expressions</a>
<ul class=toc>
<li><a href=#source-list-guid-matching><span class=secno>4.2.2.1</span> Security Considerations for GUID URI schemes </a>
<li><a href=#source-list-path-patching><span class=secno>4.2.2.2</span>Path Matching</a>
<li><a href=#source-list-paths-and-redirects><span class=secno>4.2.2.3</span>Paths and Redirects</a></ul>
<li><a href=#script-src-the-nonce-attribute><span class=secno>4.2.3</span> The <code>nonce</code> attribute </a>
<li><a href=#source-list-valid-nonces><span class=secno>4.2.4</span>Valid Nonces</a>
<li><a href=#source-list-valid-hashes><span class=secno>4.2.5</span>Valid Hashes</a></ul>
<li><a href=#media-type-list><span class=secno>4.3</span>Media Type List</a>
<ul class=toc>
<li><a href=#media-type-list-parsing><span class=secno>4.3.1</span>Parsing</a>
<li><a href=#media-type-list-matching><span class=secno>4.3.2</span>Matching</a></ul>
<li><a href=#violation-reports><span class=secno>4.4</span>Reporting</a></ul>
<li><a href=#processing-model><span class=secno>5</span>Processing Model</a>
<ul class=toc>
<li><a href=#processing-model-workers><span class=secno>5.1</span>Workers</a>
<li><a href=#processing-model-iframe-srcdoc><span class=secno>5.2</span><code>srcdoc</code> IFrames</a></ul>
<li><a href=#script-interfaces><span class=secno>6</span>Script Interfaces</a>
<ul class=toc>
<li><a href=#securitypolicyviolationevent-interface><span class=secno>6.1</span> <code>SecurityPolicyViolationEvent</code> Interface </a>
<li><a href=#securitypolicyviolationeventinit-interface><span class=secno>6.2</span> <code>SecurityPolicyViolationEventInit</code> Interface </a>
<li><a href=#firing-securitypolicyviolationevent-events><span class=secno>6.3</span>Firing Violation Events</a></ul>
<li><a href=#sec-directives><span class=secno>7</span>Directives</a>
<ul class=toc>
<li><a href=#directive-base-uri><span class=secno>7.1</span><code>base-uri</code></a>
<li><a href=#directive-child-src><span class=secno>7.2</span><code>child-src</code></a>
<ul class=toc>
<li><a href=#directive-child-src-nested><span class=secno>7.2.1</span>Nested Browsing Contexts</a>
<li><a href=#directive-child-src-workers><span class=secno>7.2.2</span>Workers</a></ul>
<li><a href=#directive-connect-src><span class=secno>7.3</span><code>connect-src</code></a>
<ul class=toc>
<li><a href=#connect-src-usage><span class=secno>7.3.1</span>Usage</a></ul>
<li><a href=#directive-default-src><span class=secno>7.4</span><code>default-src</code></a>
<ul class=toc>
<li><a href=#default-src-usage><span class=secno>7.4.1</span>Usage</a></ul>
<li><a href=#directive-font-src><span class=secno>7.5</span><code>font-src</code></a>
<li><a href=#directive-form-action><span class=secno>7.6</span><code>form-action</code></a>
<li><a href=#directive-frame-ancestors><span class=secno>7.7</span><code>frame-ancestors</code></a>
<ul class=toc>
<li><a href=#frame-ancestors-and-frame-options><span class=secno>7.7.1</span> Relation to <code>X-Frame-Options</code> </a>
<li><a href=#frame-ancestors-multiple-source-values><span class=secno>7.7.2</span>Multiple Host Source Values</a></ul>
<li><a href=#directive-frame-src><span class=secno>7.8</span><code>frame-src</code></a>
<li><a href=#directive-img-src><span class=secno>7.9</span><code>img-src</code></a>
<li><a href=#directive-media-src><span class=secno>7.10</span><code>media-src</code></a>
<li><a href=#directive-object-src><span class=secno>7.11</span><code>object-src</code></a>
<li><a href=#directive-plugin-types><span class=secno>7.12</span><code>plugin-types</code></a>
<ul class=toc>
<li><a href=#plugin-types-usage><span class=secno>7.12.1</span>Usage</a>
<li><a href=#plugin-types-predeclaration><span class=secno>7.12.2</span> Predeclaration of expected media types </a></ul>
<li><a href=#directive-referrer><span class=secno>7.13</span><code>referrer</code></a>
<ul class=toc>
<li><a href=#referrer-multiple-policies><span class=secno>7.13.1</span>Processing multiple referrer policies</a>
<ul class=toc>
<li><a href=#referrer-usage><span class=secno>7.13.1.1</span>Usage</a></ul></ul>
<li><a href=#directive-reflected-xss><span class=secno>7.14</span><code>reflected-xss</code></a>
<ul class=toc>
<li><a href=#reflected-xss-and-x-xss-protection><span class=secno>7.14.1</span> Relationship to <code>X-XSS-Protection</code> </a></ul>
<li><a href=#directive-report-uri><span class=secno>7.15</span><code>report-uri</code></a>
<li><a href=#directive-sandbox><span class=secno>7.16</span><code>sandbox</code></a>
<ul class=toc>
<li><a href=#sandbox-usage><span class=secno>7.16.1</span>Usage</a></ul>
<li><a href=#directive-script-src><span class=secno>7.17</span><code>script-src</code></a>
<ul class=toc>
<li><a href=#script-src-nonce-usage><span class=secno>7.17.1</span> Nonce usage for <code><span data-link-type=element title=script>script</span></code> elements </a>
<li><a href=#script-src-hash-usage><span class=secno>7.17.2</span> Hash usage for <code><span data-link-type=element title=script>script</span></code> elements </a></ul>
<li><a href=#directive-style-src><span class=secno>7.18</span><code>style-src</code></a>
<ul class=toc>
<li><a href=#style-src-nonce-usage><span class=secno>7.18.1</span> Nonce usage for <code><span data-link-type=element title=style>style</span></code> elements </a>
<li><a href=#style-src-hash-usage><span class=secno>7.18.2</span> Hash usage for <code><span data-link-type=element title=style>style</span></code> elements </a></ul></ul>
<li><a href=#examples><span class=secno>8</span>Examples</a>
<ul class=toc>
<li><a href=#example-policies><span class=secno>8.1</span>Sample Policy Definitions</a>
<li><a href=#example-violation-report><span class=secno>8.2</span>Sample Violation Report</a></ul>
<li><a href=#security-considerations><span class=secno>9</span>Security Considerations</a>
<ul class=toc>
<li><a href=#security-css-parsing><span class=secno>9.1</span>Cascading Style Sheet (CSS) Parsing</a>
<li><a href=#security-violation-reports><span class=secno>9.2</span>Violation Reports</a></ul>
<li><a href=#implementation-considerations><span class=secno>10</span>Implementation Considerations</a>
<li><a href=#iana-considerations><span class=secno>11</span>IANA Considerations</a>
<ul class=toc>
<li><a href=#iana-content-security-policy><span class=secno>11.1</span>Content-Security-Policy</a>
<li><a href=#iana-content-security-policy-report-only><span class=secno>11.2</span>Content-Security-Policy-Report-Only</a>
<li><a href=#iana-ch-csp><span class=secno>11.3</span>CH-CSP</a></ul>
<li><a href=#acknowledgements><span class=secno>12</span>Acknowledgements</a>
<li><a href=#conformance><span class=secno></span>Conformance</a>
<ul class=toc>
<li><a href=#conventions><span class=secno></span>Document conventions</a>
<li><a href=#conformant-algorithms><span class=secno></span>Conformant Algorithms</a>
<li><a href=#conformance-classes><span class=secno></span>Conformance Classes</a></ul>
<li><a href=#references><span class=secno></span> References</a>
<ul class=toc>
<li><a href=#normative><span class=secno></span> Normative References</a>
<li><a href=#informative><span class=secno></span> Informative References</a></ul>
<li><a href=#index><span class=secno></span> Index</a></ul></div>
<section>
<h2 class="heading settled heading" data-level=1 id=intro><span class=secno>1 </span><span class=content>Introduction</span><a class=self-link href=#intro></a></h2>
<p><em>This section is not normative.</em></p>
<p>This document defines Content Security Policy, a mechanism web applications
can use to mitigate a broad class of content injection vulnerabilities, such
as cross-site scripting (XSS). Content Security Policy is a declarative policy
that lets the authors (or server administrators) of a web application inform
the client about the sources from which the application expects to load
resources.</p>
<p>To mitigate XSS attacks, for example, a web application can declare that it
only expects to load script from specific, trusted sources. This declaration
allows the client to detect and block malicious scripts injected into the
application by an attacker.</p>
<p>Content Security Policy (CSP) is not intended as a first line of defense
against content injection vulnerabilities. Instead, CSP is best used as
defense-in-depth, to reduce the harm caused by content injection attacks. As
a first line of defense against content injection, server operators should
validate their input and encode their output.</p>
<p>There is often a non-trivial amount of work required to apply CSP to an
existing web application. To reap the greatest benefit, authors will need to
move all inline script and style out-of-line, for example into external
scripts, because the user agent cannot determine whether an inline script
was injected by an attacker.</p>
<p>To take advantage of CSP, a web application opts into using CSP by supplying a
<code>Content-Security-Policy</code> HTTP header. Such policies apply to the
current resource representation only. To supply a policy for an entire site,
the server needs to supply a policy with each resource representation.</p>
</section>
<section>
<h2 class="heading settled heading" data-level=2 id=key-concepts><span class=secno>2 </span><span class=content>Key Concepts and Terminology</span><a class=self-link href=#key-concepts></a></h2>
<p>This section defines several terms used throughout the document.</p>
<p>The term <dfn data-dfn-type=dfn data-export="" id=security-policy title="security policy|policy">security policy<a class=self-link href=#security-policy></a></dfn>
refers to either:</p>
<ol>
<li>a set of security preferences for restrictions within which
the content can operate, or</li>
<li>a fragment of text that codifies these preferences.</li>
</ol>
<p>The security policies defined by this document are applied by a
user agent on a <em>per-resource representation basis</em>.
Specifically, when a user agent receives a policy along with the
representation of a given resource, that policy applies to <em>that
resource representation only</em>. This document often refers to
that resource representation as the <dfn data-dfn-type=dfn data-export="" id=protected-resource>protected resource<a class=self-link href=#protected-resource></a></dfn>.</p>
<p>A <dfn data-dfn-type=dfn data-export="" id=security-policy-directive title="security policy directive|directive">security policy
directive<a class=self-link href=#security-policy-directive></a></dfn> is a portion of a <a data-link-type=dfn href=#security-policy title=policy>policy</a> that declares the specific
set of restrictions for a particular resource type, or which manipulates a
specific aspect of a protected resource’s configuration. A server transmits
its security policy for a particular protected resource as a collection of
directives, such as <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'self'</code>, each of which
declares a specific set of restrictions for that resource as instantiated
by the user agent. More details are provided in the
<a data-section="" href=#sec-directives>§7 Directives</a> section.</p>
<p>A directive consists of a <dfn data-dfn-type=dfn data-noexport="" id=directive-name0>directive name<a class=self-link href=#directive-name0></a></dfn>, which
indicates the privileges controlled by the directive, and a
<dfn data-dfn-type=dfn data-noexport="" id=directive-value0>directive value<a class=self-link href=#directive-value0></a></dfn>, which specifies the restrictions the
policy imposes on those privileges.</p>
The term <dfn data-dfn-type=dfn data-noexport="" id=origin>origin<a class=self-link href=#origin></a></dfn> is defined in the Origin specification.
<a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc6454 title=biblio-rfc6454>[RFC6454]</a>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=globally-unique-identifier>globally unique identifier<a class=self-link href=#globally-unique-identifier></a></dfn> is defined in section 4 of
the Origin specification. Note that URLs that do not use hierarchical
elements as naming authorities have origins which are globally unique
identifiers. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc6454 title=biblio-rfc6454>[RFC6454]</a></p>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=uri>URI<a class=self-link href=#uri></a></dfn> is defined in the URI specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-uri title=biblio-uri>[URI]</a></p>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=resource-representation>resource representation<a class=self-link href=#resource-representation></a></dfn> is defined
<a href=http://tools.ietf.org/html/rfc7231#section-3>Section 3</a>
of HTTP/1.1 -- Semantics and Content <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc7231 title=biblio-rfc7231>[RFC7231]</a></p>
<p>The terms <dfn data-dfn-type=dfn data-noexport="" id=json-object>JSON object<a class=self-link href=#json-object></a></dfn> and <dfn data-dfn-type=dfn data-noexport="" id=json-stringification>JSON stringification<a class=self-link href=#json-stringification></a></dfn> are
defined in the JSON specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc4627 title=biblio-rfc4627>[RFC4627]</a></p>
<p>The <code><a data-link-type=element href=http://www.w3.org/TR/html5/obsolete.html#the-applet-element title=applet>applet</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#audio title=audio>audio</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element title=img>img</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#the-link-element title=link>link</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/scripting-1.html#script title=script>script</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-source-element title=source>source</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-track-element title=track>track</a></code>, and
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#video title=video>video</a></code> elements are defined in the HTML5
specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-html5 title=biblio-html5>[HTML5]</a></p>
<p>The terms <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#auxiliary-browsing-context title="auxiliary browsing contexts">auxiliary browsing contexts</a>,
<a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#opener-browsing-context title="opener browsing context">opener browsing context</a>, and <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing contexts">nested browsing contexts</a> are
defined in the HTML5 specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-html5 title=biblio-html5>[HTML5]</a></p>
<p>A <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#plugin title=plugin>plugin</a> is defined in the HTML5 specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-html5 title=biblio-html5>[HTML5]</a></p>
<p>The <code><a class="production css-code" data-link-type=at-rule href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>&lt;@font-face&gt;</a></code> Cascading Style Sheets (CSS) rule is defined
in the CSS Fonts Module Level 3 specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-css3-fonts title=biblio-css3-fonts>[CSS3-FONTS]</a></p>
<p>The <code>XMLHttpRequest</code> object is defined in the
<code>XMLHttpRequest</code> specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-xmlhttprequest title=biblio-xmlhttprequest>[XMLHTTPREQUEST]</a></p>
<p>The <code>WebSocket</code> object is defined in the <code>WebSocket</code>
specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-websockets title=biblio-websockets>[WEBSOCKETS]</a></p>
<p>The <code>EventSource</code> object is defined in the <code>EventSource</code>
specification. <a data-biblio-type=normative data-link-type=biblio href=#biblio-eventsource title=biblio-eventsource>[EVENTSOURCE]</a></p>
<p>The Augmented Backus-Naur Form (ABNF) notation used in this document is
specified in RFC5234. <a data-biblio-type=normative data-link-type=biblio href=#biblio-abnf title=biblio-abnf>[ABNF]</a></p>
<p>This document also uses the ABNF extension "#rule" as defined in
<a href=http://tools.ietf.org/html/rfc7230#section-7>Section 7</a>
of HTTP/1.1 -- Message Syntax and Routing. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc7230 title=biblio-rfc7230>[RFC7230]</a></p>
<p>The following core rules are included by reference, as defined in
<a href=http://tools.ietf.org/html/rfc5234#appendix-B.1>Appendix B.1</a>
of <a data-biblio-type=normative data-link-type=biblio href=#biblio-abnf title=biblio-abnf>[ABNF]</a>: <code>ALPHA</code> (letters), <code>DIGIT</code> (decimal
0-9), <code>WSP</code> (white space) and <code>VCHAR</code> (printing
characters).</p>
<p><dfn data-dfn-type=dfn data-noexport="" id=sha-256>SHA-256<a class=self-link href=#sha-256></a></dfn>, <dfn data-dfn-type=dfn data-noexport="" id=sha-384>SHA-384<a class=self-link href=#sha-384></a></dfn>, and <dfn data-dfn-type=dfn data-noexport="" id=sha-512>SHA-512<a class=self-link href=#sha-512></a></dfn> are the digest
algorithms <a href=http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf>defined by the NIST</a>.</p>
<p>The <dfn data-dfn-type=dfn data-noexport="" id=runs-a-worker>runs a worker<a class=self-link href=#runs-a-worker></a></dfn> algorithm is
<a href=http://www.w3.org/TR/workers/#run-a-worker>defined in the Web
Workers spec</a>. <a data-biblio-type=normative data-link-type=biblio href=#biblio-workers title=biblio-workers>[WORKERS]</a></p>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=callable>callable<a class=self-link href=#callable></a></dfn> refers to an object whose interface
has one or more <dfn data-dfn-type=dfn data-noexport="" id=callers>callers<a class=self-link href=#callers></a></dfn> as defined in the <a href=http://www.w3.org/TR/2010/WD-WebIDL-20101021/#idl-callers>Web
IDL</a> specification <a data-biblio-type=normative data-link-type=biblio href=#biblio-webidl title=biblio-webidl>[WEBIDL]</a>.</p>
<p>An <dfn data-dfn-type=dfn data-noexport="" id=http-200-response>HTTP 200 response<a class=self-link href=#http-200-response></a></dfn> is defined in
<a href=http://tools.ietf.org/html/rfc7231#section-6.3.1>Section 6.3.1</a>
of HTTP/1.1 -- Semantics and Content <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc7231 title=biblio-rfc7231>[RFC7231]</a></p>
</section>
<section>
<h2 class="heading settled heading" data-level=3 id=policy-delivery><span class=secno>3 </span><span class=content>Policy Delivery</span><a class=self-link href=#policy-delivery></a></h2>
<p>The server delivers the policy to the user agent via an HTTP
response header or an HTML <a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a> element. Servers are
informed that requests are subject to a policy via an HTTP request
header.</p>
<section>
<h3 class="heading settled heading" data-level=3.1 id=content-security-policy-header-field><span class=secno>3.1 </span><span class=content>
<code>Content-Security-Policy</code> Header Field
</span><a class=self-link href=#content-security-policy-header-field></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-export="" id=content-security-policy>Content-Security-Policy<a class=self-link href=#content-security-policy></a></dfn></code> header field is
the preferred mechanism for delivering a policy.</p>
<pre>"Content-Security-Policy:" 1#<a data-link-type=dfn href=#policy-token title=policy-token>policy-token</a>
</pre>
<p>For example:</p>
<pre class=example>Content-Security-Policy: script-src 'self'
</pre>
<p>A server MAY send more than one HTTP header field named
<code>Content-Security-Policy</code> with a given resource
representation.</p>
<p>A server MAY send different <code>Content-Security-Policy</code>
header field values with different representations of the same
resource or with different resources.</p>
<p>Upon receiving an HTTP response containing at least one
<code>Content-Security-Policy</code> header field, the user agent
MUST <a data-link-type=dfn href=#enforce title=enforce>enforce</a> each of the policies contained in each such
header field.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.2 id=content-security-policy-report-only-header-field><span class=secno>3.2 </span><span class=content>
<code>Content-Security-Policy-Report-Only</code> Header Field
</span><a class=self-link href=#content-security-policy-report-only-header-field></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-export="" id=content-security-policy-report-only>Content-Security-Policy-Report-Only<a class=self-link href=#content-security-policy-report-only></a></dfn></code>
header field lets servers experiment with policies by monitoring (rather
than enforcing) a policy.</p>
<pre>"Content-Security-Policy-Report-Only:" 1#<a data-link-type=dfn href=#policy-token title=policy-token>policy-token</a>
</pre>
<p>For example, server operators might wish to develop their
security policy iteratively. The operators can deploy a report-only
policy based on their best estimate of how their site behaves:</p>
<pre class=example>Content-Security-Policy-Report-Only: script-src 'self'; report-uri /csp-report-endpoint/
</pre>
<p>If their site violates this policy the user agent will <a data-link-type=dfn href=#send-violation-reports title="send violation reports">send violation
reports</a> to the URI specified in the policy’s <a data-link-type=dfn href=#report-uri title=report-uri>report-uri</a>
directive, but allow the violating resources to load regardless. Once a site
has confidence that the policy is appropriate, they can start enforcing the
policy using the <code><a data-link-type=dfn href=#content-security-policy title=content-security-policy>Content-Security-Policy</a></code> header field.</p>
<p>A server MAY send more than one HTTP header field named
<code>Content-Security-Policy-Report-Only</code> with a given
resource representation.</p>
<p>A server MAY send different
<code>Content-Security-Policy-Report-Only</code> header field values
with different representations of the same resource or with different
resources.</p>
<p>Upon receiving an HTTP response containing at least one
<code>Content-Security-Policy-Report-Only</code> header field, the
user agent MUST <a data-link-type=dfn href=#monitor title=monitor>monitor</a> each of the policies
contained in each such header field.</p>
<p class=note>Note: The <code><a data-link-type=dfn href=#content-security-policy-report-only title=content-security-policy-report-only>Content-Security-Policy-Report-Only</a></code>
header is <em>not</em> supported inside a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.3 id=delivery-html-meta-element><span class=secno>3.3 </span><span class=content>
HTML <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> Element
</span><a class=self-link href=#delivery-html-meta-element></a></h3>
<p>The server MAY supply a policy in an HTML <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element with an <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv title=http-equiv>http-equiv</a></code> attribute that
is a case insensitive match for the string
"<code>Content-Security-Policy</code>". For example:</p>
<pre class=example>&lt;meta http-equiv="Content-Security-Policy" content="script-src 'self'"&gt;
</pre>
Add the following entry to the
<a href=http://www.w3.org/TR/html5/document-metadata.html#pragma-directives>pragma directives</a>
for the <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element:
<dl>
<dt>
Content security policy
(<code>http-equiv="content-security-policy"</code>)
</dt>
<dd>
<ol>
<li>If the Document’s <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#the-head-element title=head>head</a></code> element is
not an ancestor of the <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element, abort
these steps.</li>
<li>If the <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element lacks a
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-content title=content>content</a></code> attribute, abort these
steps.</li>
<li>Let <var>policy</var> be the value of the
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-content title=content>content</a></code> attribute of the
<code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element.</li>
<li>Let <var>directive-set</var> be the result of
<a data-link-type=dfn href=#parse-the-policy title="parse the policy">parsing <var>policy</var></a>.</li>
<li>Remove all occurrences of <code><a data-link-type=dfn href=#reflected-xss title=reflected-xss>reflected-xss</a></code>,
<code><a data-link-type=dfn href=#report-uri title=report-uri>report-uri</a></code>, and <code><a data-link-type=dfn href=#sandbox title=sandbox>sandbox</a></code>
directives from <var>directive-set</var>.</li>
<li>Enforce each of the <a data-link-type=dfn href=#security-policy-directive title=directives>directives</a> in <var>directive-set</var>,
as <a href=#sec-directives>defined for each directive type</a>.</li>
</ol>
</dd>
</dl>
<p>Authors are <em>strongly encouraged</em> to place the
<code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element as early in the document as
possible to reduce the risk of content injection before a protective
policy can be read and enforced.</p>
<p class=note>Note: A <a data-link-type=dfn href=#security-policy title=policy>policy</a> specified via a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element will be enforced along with any other policies active for the
protected resource, regardless of where they’re specified. The general
mechanism for determining the effect of enforcing multiple policies is
detailed in the <a data-section="" href=#enforcing-multiple-policies>§3.5 Enforcing multiple policies.</a>
section.</p>
<p class=note>Note: Modifications to the <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-meta-content title=content>content</a></code>
attribute of a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element after the
element has been parsed will be ignored.</p>
<p class=note>Note: The <code><a data-link-type=dfn href=#content-security-policy-report-only title=content-security-policy-report-only>Content-Security-Policy-Report-Only</a></code>
header is <em>not</em> supported inside a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code>
element.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.4 id=ch-csp-client-hint><span class=secno>3.4 </span><span class=content>The <code>CH-CSP</code> Client Hint</span><a class=self-link href=#ch-csp-client-hint></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=ch-csp>CH-CSP<a class=self-link href=#ch-csp></a></dfn></code> header field indicates that a particular
request is subject to a <a data-link-type=dfn href=#security-policy title=policy>policy</a>, and its value is defined by the
following ABNF grammar:</p>
<pre>"CH-CSP:" 1#<a data-link-type=dfn href=#hint-value title=hint-value>hint-value</a>
<dfn data-dfn-type=dfn data-noexport="" id=hint-value>hint-value<a class=self-link href=#hint-value></a></dfn> = *WSP "active"
</pre>
<p>If the user agent is <a data-link-type=dfn href=#monitor title=monitoring>monitoring</a> or <a data-link-type=dfn href=#enforce title=enforcing>enforcing</a> a <a data-link-type=dfn href=#security-policy title=policy>policy</a>
that includes directives whose value is a <a data-link-type=dfn href=#source-list0 title="source list">source list</a>, and whose
source list contains the <code>'unsafe-redirect'</code> source expression,
then the user agent MUST send a header field named <code>CH-CSP</code>
along with requests for resources whose <a data-link-type=dfn href=#origin title=origin>origin</a> <em>does not</em>
match the <a data-link-type=dfn href=#protected-resource title="protected resource">protected resource</a>’s origin. The value of this header MUST
be <code>active</code>.</p>
<p>The user agent MAY choose to send this header only if the request is for a
resource type which the active policy would effect. That is, given a policy
of <code>img-src example.com 'unsafe-redirect'</code>, the user agent
would send <code>CH-CSP: active</code> along with requests for images, but
might choose not to send the header with requests for script.</p>
<p class=note>Note: The central reason for including this header is that it hints to a
server that information about redirects might be leaked as a side-effect
of a page’s active policy. If this header is present, a server might decline
to redirect a logged-out user from <code>example.com</code> to
<code>accounts.example.com</code>, for example, as a malicious embedder
might otherwise be able to determine the user’s logged-in status.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.5 id=enforcing-multiple-policies><span class=secno>3.5 </span><span class=content>Enforcing multiple policies.</span><a class=self-link href=#enforcing-multiple-policies></a></h3>
<p><em>This section is not normative.</em></p>
<p>The above sections note that when multiple policies are present,
each must be enforced or reported, according to its type. An example
will help clarify how that ought to work in practice. The behavior of
an <code>XMLHttpRequest</code> might seem unclear given a site
that, for whatever reason, delivered the following HTTP headers:</p>
<pre class=example>Content-Security-Policy: <a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'self' http://example.com http://example.net;
<a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a> 'none';
Content-Security-Policy: <a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a> http://example.com/;
<a data-link-type=dfn href=#script-src title=script-src>script-src</a> http://example.com/
</pre>
<p>Is a connection to <code>example.com</code> allowed or not? The
short answer is that the connection is not allowed. Enforcing both
policies means that a potential connection would have to pass through
both unscathed. Even though the second policy would allow this
connection, the first policy contains <code><a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a>
'none'</code>, so its enforcement blocks the connection. The impact is
that adding additional policies to the list of policies to enforce can
only further restrict the capabilities of the protected resource.</p>
<p>To demonstrate that further, consider a script tag on this page.
The first policy would lock scripts down to <code>'self'</code>,
<code>http://example.com</code> and <code>http://example.net</code>
via the <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a></code> directive. The second, however,
would only allow script from <code>http://example.com/</code>. Script
will only load if it meets both policy’s criteria: in this case, the only
origin that can match is <code>http://example.com</code>, as both
policies allow it.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=3.6 id=which-policy-applies><span class=secno>3.6 </span><span class=content>Policy applicability</span><a class=self-link href=#which-policy-applies></a></h3>
<p><em>This section is not normative.</em></p>
<p>Policies are associated with an <a data-link-type=dfn href=#protected-resource title="protected resource">protected resource</a>, and
<a data-link-type=dfn href=#enforce title=enforce>enforced</a> or <a data-link-type=dfn href=#monitor title=monitored>monitored</a> for for that resource.
If a resource does not create a new execution context (for example, when
including a script, image, or stylesheet into a document), then any policies
delivered with that resource are discarded without effect. Its execution is
subject to the policy or policies of the including context. The following
table outlines examples of these relationships:</p>
<table>
<thead>
<tr>
<th colspan=2>Resource Type</th>
<th>What <a data-link-type=dfn href=#security-policy title=policy>policy</a> applies?</th>
<tr>
</thead>
<tbody>
<tr class=section>
<th rowspan=2>Top-level Contexts</th>
<td>HTML as a new, top-level browsing context</td>
<td>The policy delivered with the resource</td>
</tr>
<tr>
<td>SVG, as a top-level document</td>
<td>Policy delivered with the resource</td>
</tr>
<tr class=section>
<th rowspan=3>Embedded Contexts</th>
<td>
Any resource included via <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a>,
<a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a>, or <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a>
</td>
<td>
The policy of the embedding resource controls <em>what</em> may be
embedded. The embedded resource, however, is controlled by the
policy delivered with the resource, or the policy of the embedding
resource if the embedded resource is a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique
identifier</a> (or a <a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-iframe-srcdoc title=srcdoc>srcdoc</a> frame).
</td>
</tr>
<tr>
<td>SVG, as an embedded document</td>
<td>
The policy delivered with the resource, or policy of the creating
context if created from a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique identifier</a>.
</td>
</tr>
<tr>
<td>
JavaScript, as a Worker, Shared Worker or Service Worker
</td>
<td>
The policy delivered with the resource, or policy of the creating
context if created from a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique identifier</a>
</td>
</tr>
<tr class=section>
<th rowspan=7>Subresources</th>
<td>SVG, inlined via <a data-link-type=element href=http://www.w3.org/TR/svg2/struct.html#elementdef-svg title=svg>svg</a></td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>SVG, as a resource document</td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>HTML via XMLHttpRequest</td>
<td>Policy of the context that performed the fetch</td>
</tr>
<tr>
<td>Image via <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element title=img>img</a> element</td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>JavaScript via a <a data-link-type=element href=http://www.w3.org/TR/html5/scripting-1.html#script title=script>script</a> element</td>
<td>Policy of the including context</td>
</tr>
<tr>
<td>SVG, via <a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element title=img>img</a></td>
<td>No policy; should be just as safe as JPG</td>
</tr>
<tr>
<td>SVG, as a WebFont</td>
<td>No policy; should be just as safe as WOFF</td>
</tr>
</tbody>
</table>
</section>
</section>
<section>
<h2 class="heading settled heading" data-level=4 id=syntax-and-algorithms><span class=secno>4 </span><span class=content>Syntax and Algorithms</span><a class=self-link href=#syntax-and-algorithms></a></h2>
<section>
<h3 class="heading settled heading" data-level=4.1 id=policy-syntax><span class=secno>4.1 </span><span class=content>Policy Syntax</span><a class=self-link href=#policy-syntax></a></h3>
<p>A Content Security Policy consists of a U+003B SEMICOLON
(<code>;</code>) delimited list of directives. Each <a data-link-type=dfn href=#security-policy-directive title=directive>directive</a>
consists of a <a data-link-type=dfn href=#directive-name0 title="directive name">directive name</a> and (optionally) a
<a data-link-type=dfn href=#directive-value0 title="directive value">directive value</a>, defined by the following ABNF:</p>
<pre><dfn data-dfn-type=dfn data-noexport="" id=policy-token>policy-token<a class=self-link href=#policy-token></a></dfn> = [ <a data-link-type=dfn href=#directive-token title=directive-token>directive-token</a> *( ";" [ <a data-link-type=dfn href=#directive-token title=directive-token>directive-token</a> ] ) ]
<dfn data-dfn-type=dfn data-noexport="" id=directive-token>directive-token<a class=self-link href=#directive-token></a></dfn> = *WSP [ <a data-link-type=dfn href=#directive-name title=directive-name>directive-name</a> [ WSP <a data-link-type=dfn href=#directive-value title=directive-value>directive-value</a> ] ]
<dfn data-dfn-type=dfn data-noexport="" id=directive-name>directive-name<a class=self-link href=#directive-name></a></dfn> = 1*( ALPHA / DIGIT / "-" )
<dfn data-dfn-type=dfn data-noexport="" id=directive-value>directive-value<a class=self-link href=#directive-value></a></dfn> = *( WSP / &lt;VCHAR except ";" and ","&gt; )
</pre>
<section>
<h4 class="heading settled heading" data-level=4.1.1 id=policy-parsing><span class=secno>4.1.1 </span><span class=content>Parsing Policies</span><a class=self-link href=#policy-parsing></a></h4>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=parse-the-policy>parse the policy<a class=self-link href=#parse-the-policy></a></dfn> <var>policy</var>, the user agent MUST
use an algorithm equivalent to the following:</p>
<ol>
<li>Let the <var>set of directives</var> be the empty set.</li>
<li>For each non-empty token returned by
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#strictly-split-a-string title="strictly split a string">strictly splitting</a>
the string <var>policy</var> on the character U+003B SEMICOLON
(<code>;</code>):
<ol>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#skip-whitespace title="skip whitespace">Skip whitespace</a>.</li>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#collect-a-sequence-of-characters title="collect a sequence of characters">Collect a sequence of characters</a> that are
not <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#space-character title="space characters">space characters</a>. The collected characters
are the <var>directive name</var>.</li>
<li>If there are characters remaining in <var>token</var>,
skip ahead exactly one character (which must be a
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#space-character title="space character">space character</a>).</li>
<li>The remaining characters in <var>token</var> (if any) are
the <var>directive value</var>.</li>
<li>If the <var>set of directives</var> already contains a
directive whose name is a case insensitive match for
<var>directive name</var>, ignore this instance of the directive
and continue to the next token.</li>
<li>Add a <var>directive</var> to the <var>set of
directives</var> with name <var>directive name</var> and value
<var>directive value</var>.</li>
</ol>
</li>
<li>Return the <var>set of directives</var>.
</ol>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=4.2 id=source-list-syntax><span class=secno>4.2 </span><span class=content>Source List Syntax</span><a class=self-link href=#source-list-syntax></a></h3>
<p>Many CSP directives use a value consisting of a <dfn data-dfn-type=dfn data-noexport="" id=source-list0>source
list<a class=self-link href=#source-list0></a></dfn>, defined in the ABNF grammar below.</p>
<p>Each <dfn data-dfn-type=dfn data-noexport="" id=source-expression0>source expression<a class=self-link href=#source-expression0></a></dfn> in the source list represents a
location from which content of the specified type can be retrieved.
For example, the source expression <code>'none'</code> represents
the empty set of URIs, and the source expression
<code>'unsafe-inline'</code> represents content supplied inline in the
resource itself.</p>
<pre><dfn data-dfn-type=dfn data-noexport="" id=source-list>source-list<a class=self-link href=#source-list></a></dfn> = *WSP [ <a data-link-type=dfn href=#source-expression title=source-expression>source-expression</a> *( 1*WSP <a data-link-type=dfn href=#source-expression title=source-expression>source-expression</a> ) *WSP ]
/ *WSP "'none'" *WSP
<dfn data-dfn-type=dfn data-noexport="" id=source-expression>source-expression<a class=self-link href=#source-expression></a></dfn> = <a data-link-type=dfn href=#scheme-source title=scheme-source>scheme-source</a> / <a data-link-type=dfn href=#host-source title=host-source>host-source</a> / <a data-link-type=dfn href=#keyword-source title=keyword-source>keyword-source</a> / <a data-link-type=dfn href=#nonce-source title=nonce-source>nonce-source</a> / <a data-link-type=dfn href=#hash-source title=hash-source>hash-source</a>
<dfn data-dfn-type=dfn data-noexport="" id=scheme-source>scheme-source<a class=self-link href=#scheme-source></a></dfn> = <a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a> ":"
<dfn data-dfn-type=dfn data-noexport="" id=host-source>host-source<a class=self-link href=#host-source></a></dfn> = [ <a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a> "://" ] <a data-link-type=dfn href=#host-part title=host-part>host-part</a> [ <a data-link-type=dfn href=#port-part title=port-part>port-part</a> ] [ <a data-link-type=dfn href=#path-part title=path-part>path-part</a> ]
<dfn data-dfn-type=dfn data-noexport="" id=keyword-source>keyword-source<a class=self-link href=#keyword-source></a></dfn> = "'self'" / "'unsafe-inline'" / "'unsafe-eval'" / "'unsafe-redirect'"
<dfn data-dfn-type=dfn data-noexport="" id=base64-value>base64-value<a class=self-link href=#base64-value></a></dfn> = 1*( ALPHA / DIGIT / "+" / "/" )*2( "=" )
<dfn data-dfn-type=dfn data-noexport="" id=nonce-value>nonce-value<a class=self-link href=#nonce-value></a></dfn> = <a data-link-type=dfn href=#base64-value title=base64-value>base64-value</a>
<dfn data-dfn-type=dfn data-noexport="" id=hash-value>hash-value<a class=self-link href=#hash-value></a></dfn> = <a data-link-type=dfn href=#base64-value title=base64-value>base64-value</a>
<dfn data-dfn-type=dfn data-noexport="" id=nonce-source>nonce-source<a class=self-link href=#nonce-source></a></dfn> = "'nonce-" <a data-link-type=dfn href=#nonce-value title=nonce-value>nonce-value</a> "'"
<dfn data-dfn-type=dfn data-noexport="" id=hash-algo>hash-algo<a class=self-link href=#hash-algo></a></dfn> = "sha256" / "sha384" / "sha512"
<dfn data-dfn-type=dfn data-noexport="" id=hash-source>hash-source<a class=self-link href=#hash-source></a></dfn> = "'" <a data-link-type=dfn href=#hash-algo title=hash-algo>hash-algo</a> "-" <a data-link-type=dfn href=#base64-value title=base64-value>base64-value</a> "'"
<dfn data-dfn-type=dfn data-noexport="" id=scheme-part>scheme-part<a class=self-link href=#scheme-part></a></dfn> = &lt;scheme production from <a href=http://tools.ietf.org/html/rfc3986#section-3.1>RFC 3986, section 3.1</a>&gt;
<dfn data-dfn-type=dfn data-noexport="" id=host-part>host-part<a class=self-link href=#host-part></a></dfn> = "*" / [ "*." ] 1*<a data-link-type=dfn href=#host-char title=host-char>host-char</a> *( "." 1*<a data-link-type=dfn href=#host-char title=host-char>host-char</a> )
<dfn data-dfn-type=dfn data-noexport="" id=host-char>host-char<a class=self-link href=#host-char></a></dfn> = ALPHA / DIGIT / "-"
<dfn data-dfn-type=dfn data-noexport="" id=path-part>path-part<a class=self-link href=#path-part></a></dfn> = &lt;path production from <a href=http://tools.ietf.org/html/rfc3986#section-3.3>RFC 3986, section 3.3</a>&gt;
<dfn data-dfn-type=dfn data-noexport="" id=port-part>port-part<a class=self-link href=#port-part></a></dfn> = ":" ( 1*DIGIT / "*" )
</pre>
<p>If the policy contains a <code><a data-link-type=dfn href=#nonce-source title=nonce-source>nonce-source</a></code> expression, the
server MUST generate a fresh value for the <code><a data-link-type=dfn href=#nonce-value title=nonce-value>nonce-value</a></code>
directive at random and independently each time it transmits a policy.
This requirement ensures that the <code><a data-link-type=dfn href=#nonce-value title=nonce-value>nonce-value</a></code> is
difficult for an attacker to predict.</p>
<p>The <code><a data-link-type=dfn href=#host-char title=host-char>host-char</a></code> production intentionally contains only
ASCII characters; internationalized domain names cannot be entered
directly into a policy string, but instead MUST be Punycode-encoded
<a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc3492 title=biblio-rfc3492>[RFC3492]</a>. For example, the domain <code>üüüüüü.de</code> would be
encoded as <code>xn--tdaaaaaa.de</code>.</p>
<section>
<h4 class="heading settled heading" data-level=4.2.1 id=source-list-parsing><span class=secno>4.2.1 </span><span class=content>Parsing Source Lists</span><a class=self-link href=#source-list-parsing></a></h4>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=parse-a-source-list>parse a source list<a class=self-link href=#parse-a-source-list></a></dfn>
<var>source list</var>, the user agent MUST use an algorithm
equivalent to the following:</p>
<ol>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace title="strip leading and trailing whitespace">Strip leading and trailing whitespace</a> from
<var>source list</var>.</li>
<li>If <var>source list</var> is a case insensitive match
for the string <code>'none'</code> (including the quotation
marks), return the empty set.</li>
<li>Let <var>set of source expressions</var> be the empty
set.</li>
<li>For each token returned by
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-spaces title="split a string on spaces">splitting <var>source
list</var> on spaces</a>, if the token matches the grammar for
<code><a data-link-type=dfn href=#source-expression title=source-expression>source-expression</a></code>, add the token to the <var>set
of source expressions</var>.</li>
<li>Return the <var>set of source expressions</var>.</li>
</ol>
<p class=note>Note: Characters like U+003B SEMICOLON (<code>;</code>) and
U+002C COMMA (<code>,</code>) cannot appear in source expressions
directly: if you’d like to include these characters in a source
expression, they must be <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#percent-encode title="percent encode">percent
encoded</a> as <code>%3B</code> and <code>%2C</code> respectively.</p>
</section>
<section>
<h4 class="heading settled heading" data-level=4.2.2 id=match-source-expression><span class=secno>4.2.2 </span><span class=content>Matching Source Expressions</span><a class=self-link href=#match-source-expression></a></h4>
<p>A URI is said to <dfn data-dfn-type=dfn data-noexport="" id=match-a-source-expression>match a source expression<a class=self-link href=#match-a-source-expression></a></dfn> if the following
algorithm returns <em>does match</em>:</p>
<ol>
<li>Normalize the URI according to
<a href=http://tools.ietf.org/html/rfc3986#section-6>Section 6 of
RFC3986</a>.</li>
<li>If the source expression a consists of a single U+002A ASTERISK
character (<code>*</code>), and the URI’s scheme is not of a type
designating a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique identifier</a>, (such as
<code>blob:</code>, <code>data:</code>, or <code>filesystem:</code>)
then return <em>does match</em>.</li>
<li>If the source expression matches the grammar for
<code><a data-link-type=dfn href=#scheme-source title=scheme-source>scheme-source</a></code>:
<ol>
<li>If the URI’s scheme is a case-insensitive match for the
source expression’s <code><a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a></code>, return
<em>does match</em>.</li>
<li>Otherwise, return <em>does not match</em>.</li>
</ol>
</li>
<li>If the source expression matches the grammar for
<code><a data-link-type=dfn href=#host-source title=host-source>host-source</a></code>:
<ol>
<li>If the URI does <strong>not</strong> contain a host, then
return <em>does not match</em>.</li>
<li>Let <var>uri-scheme</var>, <var>uri-host</var>, and
<var>uri-port</var> be the scheme, host, and port of the URI,
respectively. If the URI does not have a port, then let
<var>uri-port</var> be the default port for
<var>uri-scheme</var>. Let <var>uri-path</var> be
the path of the URI after
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#percent-decode title="percent decode">decoding
percent-encoded characters</a>. If the URI does not have a
path, then let <var>uri-path</var> be the U+002F SOLIDUS
character (<code>/</code>).</li>
<li>If the source expression has a <code><a data-link-type=dfn href=#scheme-part title=scheme-part>scheme-part</a></code>
that is not a case insensitive match for <var>uri-scheme</var>,
then return <em>does not match</em>.</li>
<li>If the source expression does <strong>not</strong> have a
scheme, return <em>does not match</em> if
<ol>
<li>the scheme of the protected resource’s URI is a case
insensitive match for <code>HTTP</code>, and
<var>uri-scheme</var> is <strong>not</strong> a case
insensitive match for either <code>HTTP</code> or
<code>HTTPS</code></li>
<li>the scheme of the protected resource’s URI is
<strong>not</strong> a case insensitive match for
<code>HTTP</code>, and <var>uri-scheme</var> is
<strong>not</strong> a case insensitive match
for the scheme of the protected resource’s URI.</li>
</ol>
</li>
<li>If the first character of the source expression’s
<code><a data-link-type=dfn href=#host-part title=host-part>host-part</a></code> is an U+002A ASTERISK character
(<code>*</code>) and the remaining characters, including the
leading U+002E FULL STOP character (<code>.</code>), are not a
case insensitive match for the rightmost characters of
<var>uri-host</var>, then return <em>does not match</em>.</li>
<li>If the first character of the source expression’s
<code><a data-link-type=dfn href=#host-part title=host-part>host-part</a></code> is <em>not</em> an U+002A ASTERISK
character (<code>*</code>) and <var>uri-host</var> is not a
case insensitive match for the source expression’s
<code><a data-link-type=dfn href=#host-part title=host-part>host-part</a></code>, then return <em>does not
match</em>.</li>
<li>If the source expression does <strong>not</strong> contain
a <code>port-part</code> and <var>uri-port</var> is not the
default port for <var>uri-scheme</var>, then return <em>does not
match</em>.</li>
<li>If the source expression does contain a
<code>port-part</code>, then return <em>does not match</em> if
<ol>
<li><code><a data-link-type=dfn href=#port-part title=port-part>port-part</a></code> does <strong>not</strong>
contain an U+002A ASTERISK character (<code>*</code>),
and</li>
<li><code><a data-link-type=dfn href=#port-part title=port-part>port-part</a></code> does <strong>not</strong>
represent the same number as <var>uri-port</var>.</li>
</ol>
</li>
<li>If the source expression contains a non-empty
<code><a data-link-type=dfn href=#path-part title=path-part>path-part</a></code>, and the URI is <em>not</em> the
result of a redirect, then:
<ol>
<li>Let <var>decoded-path</var> be the result of
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#percent-decode title="percent decode">decoding
<code>path-part</code>’s percent-encoded characters</a>.</li>
<li>If the final character of <var>decoded-path</var> is
the U+002F SOLIDUS character (<code>/</code>), and
<var>decoded-path</var> is not a prefix of
<var>uri-path</var>, then return <em>does not
match</em>.</li>
<li>If the final character of <var>decoded-path</var> is
not the the U+002F SOLIDUS character (<code>/</code>),
and <var>decoded-path</var> is not an exact match for
<var>uri-path</var> then return <em>does not
match</em>.</li>
</ol>
</li>
<li>Otherwise, return <em>does match</em>.</li>
</ol>
</li>
<li>If the source expression is a case insensitive
match for <code>'self'</code> (including the quotation marks),
then:
<ol>
<li>Return <em>does match</em> if the URI has the same scheme,
host, and port as the protected resource’s URI (using the
default port for the appropriate scheme if either or both URIs
are missing ports).</li>
</ol>
</li>
<li>Otherwise, return <em>does not match</em>.</li>
</ol>
<p>A URI is said to <dfn data-dfn-type=dfn data-noexport="" id=match-a-source-list>match a source list<a class=self-link href=#match-a-source-list></a></dfn> if the following
conditions are met:</p>
<ol>
<li>
The URI <a data-link-type=dfn href=#match-a-source-expression title="match a source expression">matches at least one
source expression</a> in the set of source expressions obtained by
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the source list</a>.
</li>
<li>
At least one of the following is true:
<ol>
<li>
The URI is one of <strong>not</strong> the result of a redirect.
</li>
<li>
The set of source expressions obtained by
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the source list</a>
contains the source expression <code>'unsafe-redirect'</code>.
</li>
<li>
The source list is the U+002A ASTERISK character (<code>*</code>).
</li>
</ol>
</li>
</ol>
<p class=note>Note: No URIs 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 heading" 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 URI 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 URI 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 URIs 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 title=default-src>default-src</a></code> and <code><a data-link-type=dfn href=#script-src title=script-src>script-src</a></code>
directives, policy authors should be aware that allowing "data:" URIs
is equivalent to <code>unsafe-inline</code> and allowing "blob:" or
"filesystem:" URIs is equivalent to <code>unsafe-eval</code>.</p>
</section>
<section class=informative>
<h5 class="heading settled heading" 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>
<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>
<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>
<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>.</li>
</ol>
<p class=note>Note: Query strings have no impact on matching: the source
expression <code>example.com/file?key=value</code> matches all 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 heading" 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 title=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>
<li>Directly loading <code>https://example.com/redirector</code>
would pass, as it matches <code>example.com</code>.</li>
<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.</li>
</ul>
<p>This restriction reduces the granularity of a document’s
policy when redirects are in play, which isn’t wonderful, but
given that we certainly don’t want to allow brute-forcing paths
after redirects, it seems a reasonable compromise.</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 public-webappsec@w3.org has more detailed discussion around
alternate proposals.</p>
</section>
</section>
<section>
<h4 class="heading settled heading" 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 attribute to be added to both
<code><a data-link-type=element href=http://www.w3.org/TR/html5/scripting-1.html#script title=script>script</a></code> and <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#the-style-element title=style>style</a></code>
elements: <code><dfn data-dfn-type=element-attr data-export="" id=element-attrdef-nonce>nonce<a class=self-link href=#element-attrdef-nonce></a></dfn></code>.</p>
<pre class=idl>partial interface <a class=idl-code data-global-name="" data-link-type=interface href=http://www.w3.org/TR/html5/scripting-1.html#htmlscriptelement title=htmlscriptelement>HTMLScriptElement</a> {
attribute DOMString <a class=idl-code data-global-name="HTMLScriptElement<interface>/nonce<attribute>" data-link-for=HTMLScriptElement data-link-type=attribute data-type="DOMString " href=#dom-htmlscriptelement-nonce title=nonce>nonce</a>;
};
</pre>
<dl data-dfn-for=HTMLScriptElement>
<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></dt>
<dd>This attribute <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#reflect title=reflects>reflects</a> the value of the
element’s <code><a data-link-type=element-attr href=#element-attrdef-nonce title=nonce>nonce</a></code> content attribute.</dd>
</dl>
<pre class=idl>partial interface <a class=idl-code data-global-name="" data-link-type=interface href=http://www.w3.org/TR/html5/document-metadata.html#htmlstyleelement title=htmlstyleelement>HTMLStyleElement</a> {
attribute DOMString <a class=idl-code data-global-name="HTMLStyleElement<interface>/nonce<attribute>" data-link-for=HTMLStyleElement data-link-type=attribute data-type="DOMString " href=#dom-htmlstyleelement-nonce title=nonce>nonce</a>;
};
</pre>
<dl data-dfn-for=HTMLStyleElement>
<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></dt>
<dd>This attribute <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#reflect title=reflects>reflects</a> the value of the
element’s <code><a data-link-type=element-attr href=#element-attrdef-nonce title=nonce>nonce</a></code> content attribute.</dd>
</dl>
</section>
<section>
<h4 class="heading settled heading" 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-nonce title=nonce>nonce</a></code> attribute after
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace title="strip leading and trailing whitespace">stripping
leading and trailing whitespace</a> is a case-sensitive match for the
<code><a data-link-type=dfn href=#nonce-value title=nonce-value>nonce-value</a></code> component of at least one
<code><a data-link-type=dfn href=#nonce-source title=nonce-source>nonce-source</a></code> expression in <var>set of source
expressions</var>.</p>
</section>
<section>
<h4 class="heading settled heading" 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-spec=HTML5 data-link-type=dfn href="http://www.w3.org/TR/html5/scripting-1.html#the-script-block's-source" title="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#script title=script>script</a></code> elements, or the
value of the element’s
<code><a class=idl-code data-link-for=Node data-link-type=attribute href=http://dom.spec.whatwg.org/#dom-node-textcontent title=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#script title=script>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 title=style>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>algorithm</var> to the <a data-link-type=dfn href=#elements-content title="element’s 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 title=hash-source>hash-source</a></code> expressions in <var>set of source
expressions</var>.</li>
<li>For each <var>hash</var> in <var>hashes</var>:
<ol>
<li>Let <var>algorithm</var> be:
<ul>
<li><a data-link-type=dfn href=#sha-256 title=sha-256>SHA-256</a> if the <code><a data-link-type=dfn href=#hash-algo title=hash-algo>hash-algo</a></code>
component of <var>hash</var> is a case-insensitive match for
the string "sha256"</li>
<li><a data-link-type=dfn href=#sha-384 title=sha-384>SHA-384</a> if the <code><a data-link-type=dfn href=#hash-algo title=hash-algo>hash-algo</a></code>
component of <var>hash</var> is a case-insensitive match for
the string "sha384"</li>
<li><a data-link-type=dfn href=#sha-512 title=sha-512>SHA-512</a> if the <code><a data-link-type=dfn href=#hash-algo title=hash-algo>hash-algo</a></code>
component of <var>hash</var> is a case-insensitive match for
the string "sha512"</li>
</ul>
</li>
<li>Let <var>expected</var> be the <code><a data-link-type=dfn href=#hash-value title=hash-value>hash-value</a></code>
component of <var>hash</var>.</li>
<li>Let <var>actual</var> be the
<a href=http://tools.ietf.org/html/rfc4648#section-4>base64
encoding</a> of the binary <a data-link-type=dfn href=#digest-of-elements-content title="digest of element’s content">digest of <var>element</var>’s
content</a> using the <var>algorithm</var> algorithm.</li>
<li>If <var>actual</var> is a case-sensitive match for
<var>expected</var>, return <strong>true</strong> and abort these
steps.</li>
</ol>
</li>
<li>Return <strong>false</strong>.</li>
</ol>
<p class=note>Note: If an element has an invalid hash, it would be helpful
if the user agent reported the failure to the author by adding
a warning message containing the <var>actual</var> hash value.</p>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=4.3 id=media-type-list><span class=secno>4.3 </span><span class=content>Media Type List</span><a class=self-link href=#media-type-list></a></h3>
<p>The <code><a data-link-type=dfn href=#plugin-types title=plugin-types>plugin-types</a></code> directive uses a value consisting
of a <dfn data-dfn-type=dfn data-noexport="" id=media-type-list0>media type list<a class=self-link href=#media-type-list0></a></dfn>.</p>
<p>Each <dfn data-dfn-type=dfn data-noexport="" id=media-type0>media type<a class=self-link href=#media-type0></a></dfn> in the media type list represents a specific
type of resource that can be retrieved and used to instantiate a
<a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#plugin title=plugin>plugin</a> in the protected resource.</p>
<pre><dfn data-dfn-type=dfn data-noexport="" id=media-type-list1>media-type-list<a class=self-link href=#media-type-list1></a></dfn> = <a data-link-type=dfn href=#media-type title=media-type>media-type</a> *( 1*WSP <a data-link-type=dfn href=#media-type title=media-type>media-type</a> )
<dfn data-dfn-type=dfn data-noexport="" id=media-type>media-type<a class=self-link href=#media-type></a></dfn> = &lt;type from RFC 2045&gt; "/" &lt;subtype from RFC 2045&gt;
</pre>
<section>
<h4 class="heading settled heading" data-level=4.3.1 id=media-type-list-parsing><span class=secno>4.3.1 </span><span class=content>Parsing</span><a class=self-link href=#media-type-list-parsing></a></h4>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=parse-a-media-type-list>parse a media type list<a class=self-link href=#parse-a-media-type-list></a></dfn> <var>media type list</var>, the
user agent MUST use an algorithm equivalent to the following:</p>
<ol>
<li>Let the <var>set of media types</var> be the empty set.</li>
<li>For each token returned by
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-spaces title="split a string on spaces">splitting
<var>media type list</var> on spaces</a>, if the token matches the
grammar for <code><a data-link-type=dfn href=#media-type title=media-type>media-type</a></code>, add the token to the
<var>set of media types</var>. Otherwise ignore the token.</li>
<li>Return the <var>set of media types</var>.</li>
</ol>
</section>
<section>
<h4 class="heading settled heading" data-level=4.3.2 id=media-type-list-matching><span class=secno>4.3.2 </span><span class=content>Matching</span><a class=self-link href=#media-type-list-matching></a></h4>
<p>A media type <dfn data-dfn-type=dfn data-noexport="" id=match-a-media-type-list title="match a media type list">matches a media type
list<a class=self-link href=#match-a-media-type-list></a></dfn> if, and only if, the media type is a case-insensitive match for
at least one token in the set of media types obtained by
<a data-link-type=dfn href=#parse-a-media-type-list title="parse a media type list">parsing the media type list</a>.</p>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=4.4 id=violation-reports><span class=secno>4.4 </span><span class=content>Reporting</span><a class=self-link href=#violation-reports></a></h3>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=strip-uri-for-reporting title="strip uri for reporting|stripped for reporting">strip
<var>uri</var> for reporting<a class=self-link href=#strip-uri-for-reporting></a></dfn>, the user agent MUST use an
algorithm equivalent to the following:</p>
<ol>
<li>If the <a data-link-type=dfn href=#origin title=origin>origin</a> of <var>uri</var> is a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique
identifier</a> (for example, <var>uri</var> has a scheme of
<code>data</code>, <code>blob</code>, or <code>filesystem</code>), then
abort these steps, and return the ASCII serialization of
<var>uri</var>’s scheme.</li>
<li>If the <a data-link-type=dfn href=#origin title=origin>origin</a> of <var>uri</var> is not the same as the
<a data-link-type=dfn href=#origin title=origin>origin</a> of the protected resource, then abort these steps, and
return the
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#ascii-serialization-of-an-origin title="ascii serialization of an origin">ASCII
serialization of <var>uri</var>’s origin</a>.</li>
<li>Return <var>uri</var>, with any <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#concept-url-fragment title=fragment>fragment</a>
component removed.</li>
</ol>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=generate-a-violation-report-object title="generate a violation report object|generating a violation report object">generate a violation report object<a class=self-link href=#generate-a-violation-report-object></a></dfn>,
the user agent MUST use an algorithm equivalent to the following:</p>
<ol>
<li>Prepare a JSON object <var>violation</var> with the
following keys and values:
<dl>
<dt id=violation-report-blocked-uri><a class=self-link href=#violation-report-blocked-uri></a>blocked-uri</dt>
<dd>The originally requested URI of the resource that was
prevented from loading, <a data-link-type=dfn href=#strip-uri-for-reporting title="stripped for reporting">stripped for reporting</a>,
or the empty string if the resource has no URI (inline script and
inline style, for example).</dd>
<dt id=violation-report-document-uri><a class=self-link href=#violation-report-document-uri></a>document-uri</dt>
<dd>The <a data-link-spec=HTML5 data-link-type=dfn href="http://www.w3.org/TR/html5/dom.html#the-document's-address" title="the document’s address">address</a>
of the protected resource, <a data-link-type=dfn href=#strip-uri-for-reporting title="stripped for reporting">stripped for reporting</a>.</dd>
<dt id=violation-report-effective-directive><a class=self-link href=#violation-report-effective-directive></a>effective-directive</dt>
<dd>The name of the policy directive that was violated. This will
contain the <a data-link-type=dfn href=#security-policy-directive title=directive>directive</a> whose enforcement triggered the
violation (e.g. "<code><a data-link-type=dfn href=#script-src title=script-src>script-src</a></code>") even if that
directive does not explicitly appear in the policy, but is
implicitly activated via the <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a></code>
directive.</dd>
<dt id=violation-report-original-policy><a class=self-link href=#violation-report-original-policy></a>original-policy</dt>
<dd>The original <a data-link-type=dfn href=#security-policy title=policy>policy</a>, as received by the user agent.</dd>
<dt id=violation-report-referrer><a class=self-link href=#violation-report-referrer></a>referrer</dt>
<dd>The <a class=idl-code data-link-for=Document data-link-type=attribute href=http://www.w3.org/TR/html5/dom.html#dom-document-referrer title=referrer>referrer</a> attribute of the protected
resource, or the empty string if the protected resource has no
referrer.</dd>
<dt id=violation-report-status-code><a class=self-link href=#violation-report-status-code></a>status-code</dt>
<dd>The <code>status-code</code> of the HTTP response that
contained the protected resource, if the protected resource was
obtained over HTTP. Otherwise, the number 0.</dd>
<dt id=violation-report-violated-directive><a class=self-link href=#violation-report-violated-directive></a>violated-directive</dt>
<dd>The policy directive that was violated, as it appears in the
policy. This will contain the <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a></code> directive
in the case of violations caused by falling back to the
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a> when enforcing
a directive.</dd>
</dl>
</li>
<li>If a specific line or a specific file can be identified as the
cause of the violation (for example, script execution that violates
the <code><a data-link-type=dfn href=#script-src title=script-src>script-src</a></code> directive), the user agent MAY add the
following keys and values to <var>violation</var>:
<dl>
<dt id=violation-report-source-file><a class=self-link href=#violation-report-source-file></a><dfn data-dfn-type=dfn data-noexport="" id=source-file>source-file<a class=self-link href=#source-file></a></dfn></dt>
<dd>The URI of the resource where the violation occurred,
<a data-link-type=dfn href=#strip-uri-for-reporting title="stripped for reporting">stripped for reporting</a>.</dd>
<dt id=violation-report-line-number><a class=self-link href=#violation-report-line-number></a>line-number</dt>
<dd>The line number in <code><a data-link-type=dfn href=#source-file title=source-file>source-file</a></code> on which
the violation occurred.</dd>
<dt id=violation-report-column-number><a class=self-link href=#violation-report-column-number></a>column-number</dt>
<dd>The column number in <code><a data-link-type=dfn href=#source-file title=source-file>source-file</a></code> on which
the violation occurred.</dd>
</dl>
</li>
<li>Return <var>violation</var>.</li>
</ol>
<p class=note>Note: <code>blocked-uri</code> will not contain the final location of a
resource that was blocked after one or more redirects. It instead will
contain only the location that the protected resource requested, before
any redirects were followed.</p>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=send-violation-reports>send violation reports<a class=self-link href=#send-violation-reports></a></dfn>, the user agent MUST use an
algorithm equivalent to the following:</p>
<ol>
<li>Prepare a <a data-link-type=dfn href=#json-object title="json object">JSON object</a> <var>report object</var> with a single
key, <code>csp-report</code>, whose value is the result of <a data-link-type=dfn href=#generate-a-violation-report-object title="generating a violation report object">generating
a violation report object</a>.</li>
<li>Let <var>report body</var> be the <a data-link-type=dfn href=#json-stringification title="json stringification">JSON stringification</a> of
<var>report object</var>.</li>
<li>For each <var>report URI</var> in the <a data-link-type=dfn href=#set-of-report-uris title="set of report uris">set of report URIs</a>:
<ol>
<li>If the user agent has already sent a violation report for
the protected resource to <var>report URI</var>, and that report
contained an entity body that exactly matches
<var>report body</var>, the user agent MAY abort these
steps and continue to the next <var>report URI</var>.</li>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/webappapis.html#queue-a-task title="queue a task">Queue a task</a> to <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetch>fetch</a>
<var>report URI</var> from the origin of the protected resource,
with the synchronous flag <em>not</em> set, using HTTP method
<code>POST</code>, with a <code>Content-Type</code> header field
of <code>application/csp-report</code>, and an entity body
consisting of <var>report body</var>. If the origin of
<var>report URI</var> is <strong>not</strong> the same as the
origin of the protected resource, the block cookies flag MUST also
be set. The user agent MUST NOT follow redirects when fetching this
resource. (Note: The user agent ignores the fetched resource.)
The <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/webappapis.html#task-source title="task source">task source</a> for these
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/webappapis.html#concept-task title=tasks>tasks</a> is the <dfn data-dfn-type=dfn data-noexport="" id=content-security-policy-task-source>Content Security Policy task
source<a class=self-link href=#content-security-policy-task-source></a></dfn>.</li>
</ol>
</li>
</ol>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=report-a-violation>report a violation<a class=self-link href=#report-a-violation></a></dfn>, the user agent MUST:</p>
<ol>
<li><a data-link-type=dfn href=#fire-a-violation-event title="fire a violation event">Fire a violation event</a> at the protected resource’s
<code><a class=idl-code data-link-spec=HTML5 data-link-type=interface href=http://www.w3.org/TR/html5/infrastructure.html#dom-document title=document>Document</a></code>.</li>
<li>If the <a data-link-type=dfn href=#set-of-report-uris title="set of report uris">set of report URIs</a> is non-empty, <a data-link-type=dfn href=#send-violation-reports title="send violation reports">send violation
reports</a> to each.</li>
</ol>
<p class=note>Note: This section of the specification should not be interpreted
as limiting user agents' ability to apply restrictions to violation
reports in order to limit data leakage above and beyond what these
algorithms specify.</p>
</section>
</section>
<section>
<h2 class="heading settled heading" data-level=5 id=processing-model><span class=secno>5 </span><span class=content>Processing Model</span><a class=self-link href=#processing-model></a></h2>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=enforce>enforce<a class=self-link href=#enforce></a></dfn> a policy, the user agent MUST <a data-link-type=dfn href=#parse-the-policy title="parse the policy">parse the policy</a>
and enforce each of the directives contained in the policy, where the
specific requirements for enforcing each directive are defined separately
for each directive (See <a data-section="" href=#sec-directives>§7 Directives</a>, below).</p>
<p>Generally speaking, enforcing a directive prevents the protected
resource from performing certain actions, such as loading scripts from
URIs other than those indicated in a source list. These restrictions
make it more difficult for an attacker to abuse an injection
vulnerability in the resource because the attacker will be unable to
usurp the resource’s privileges that have been restricted in this
way.</p>
<p class=note>Note: User agents may allow users to modify or bypass policy enforcement
through user preferences, bookmarklets, third-party additions to the user
agent, and other such mechanisms.</p>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=monitor>monitor<a class=self-link href=#monitor></a></dfn> a policy, the user agent MUST <a data-link-type=dfn href=#parse-the-policy title="parse the policy">parse the policy</a>
and monitor each of the directives contained in the policy.</p>
<p>Monitoring a directive does not prevent the protected resource from
undertaking any actions. Instead, any actions that would have been
prevented by the directives are allowed, but a violation report is
<a data-link-type=dfn href=#report-a-violation title="report a violation">generated and reported</a> to the
developer of the web application. Monitoring a policy is useful for
testing whether enforcing the policy will cause the web application to
malfunction.</p>
<p>A server MAY cause user agents to monitor one policy while enforcing
another policy by returning both <code><a data-link-type=dfn href=#content-security-policy title=content-security-policy>Content-Security-Policy</a></code>
and <code><a data-link-type=dfn href=#content-security-policy-report-only title=content-security-policy-report-only>Content-Security-Policy-Report-Only</a></code> header fields.
For example, if a server operator may wish to <a data-link-type=dfn href=#enforce title=enforce>enforce</a> one policy but
experiment with a stricter policy, she can monitor the stricter policy while
enforcing the original policy. Once the server operator is satisfied that
the stricter policy does not break the web application, the server operator
can start enforcing the stricter policy.</p>
<p>If the user agent monitors or enforces a policy that does not contain any
directives, the user agent SHOULD report a warning message in the
developer console.</p>
<p>If the user agent <a data-link-type=dfn href=#monitor title=monitors>monitors</a> or <a data-link-type=dfn href=#enforce title=enforces>enforces</a> a policy that contains
an unrecognized directive, the user agent SHOULD report a warning message
in the developer console indicating the name of the unrecognized directive.</p>
<p>If the user agent <a data-link-type=dfn href=#monitor title=monitors>monitors</a> or <a data-link-type=dfn href=#enforce title=enforces>enforces</a> a policy that contains
a directive that contains a <a data-link-type=dfn href=#source-list0 title="source list">source list</a>, then the user agent MUST set
a <code><a data-link-type=dfn href=#ch-csp title=ch-csp>CH-CSP</a></code> Client Hint when requesting cross-origin
resources, as described in the <a data-section="" href=#ch-csp-client-hint>§3.4 The CH-CSP Client Hint</a>
section.</p>
<section>
<h3 class="heading settled heading" data-level=5.1 id=processing-model-workers><span class=secno>5.1 </span><span class=content>Workers</span><a class=self-link href=#processing-model-workers></a></h3>
<p>Whenever a user agent <a data-link-type=dfn href=#runs-a-worker title="runs a worker">runs a worker</a>:</p>
<ul>
<li>If the worker’s script’s origin is a <a data-link-type=dfn href=#globally-unique-identifier title="globally unique identifier">globally unique identifier</a>
(for example, the worker’s script’s URL has a scheme of
<code>data</code>, <code>blob</code>, or <code>filesystem</code>), then:
<ul>
<li>If the user agent is enforcing a CSP policy for the <var>owner
document</var>, the user agent MUST enforce the CSP policy for the
worker.</li>
<li>If the user agent is monitoring a CSP policy for the <var>owner
document</var>, the user agent MUST monitor the CSP policy for the
worker.</li>
</ul></li>
<li>Otherwise:
<ul>
<li>If the worker’s script is delivered with a
<code>Content-Security-Policy</code> HTTP header containing the
value <var>policy</var>, the user agent MUST <a data-link-type=dfn href=#enforce title=enforce>enforce</a>
<var>policy</var> for the worker.</li>
<li>If the worker’s script is delivered with a
<code>Content-Security-Policy-Report-Only</code> HTTP header
containing the value <var>policy</var>, the user agent MUST
<a data-link-type=dfn href=#monitor title=monitor>monitor</a> <var>policy</var> for the worker.</li>
</ul>
</li>
</ul>
</section>
<section>
<h3 class="heading settled heading" data-level=5.2 id=processing-model-iframe-srcdoc><span class=secno>5.2 </span><span class=content><code>srcdoc</code> IFrames</span><a class=self-link href=#processing-model-iframe-srcdoc></a></h3>
<p>Whenever a user agent creates an <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/embedded-content-0.html#an-iframe-srcdoc-document title="an iframe srcdoc document">an <code>iframe</code>
<code>srcdoc</code> document</a> in a browsing context nested in the
protected resource, if the user agent is <a data-link-type=dfn href=#enforce title=enforcing>enforcing</a> any <a data-link-type=dfn href=#security-policy title=policies>policies</a>
for the protected resource, the user agent MUST <a data-link-type=dfn href=#enforce title=enforce>enforce</a> those
<a data-link-type=dfn href=#security-policy title=policies>policies</a> on the <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a></code>
<code>srcdoc</code> document as well.</p>
<p>Whenever a user agent creates a <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/embedded-content-0.html#an-iframe-srcdoc-document title="an iframe srcdoc document">an <code>iframe</code>
<code>srcdoc</code> document</a> in a browsing context nested in the
protected resource, if the user agent is monitoring any policies for the
protected resource, the user agent MUST <a data-link-type=dfn href=#monitor title=monitor>monitor</a> those policies on
the <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a></code> <code>srcdoc</code> document as well.</p>
</section>
</section>
<section>
<h2 class="heading settled heading" data-level=6 id=script-interfaces><span class=secno>6 </span><span class=content>Script Interfaces</span><a class=self-link href=#script-interfaces></a></h2>
<section>
<h3 class="heading settled heading" data-level=6.1 id=securitypolicyviolationevent-interface><span class=secno>6.1 </span><span class=content>
<code>SecurityPolicyViolationEvent</code> Interface
</span><a class=self-link href=#securitypolicyviolationevent-interface></a></h3>
<pre class=idl>[Constructor(DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent/SecurityPolicyViolationEvent() data-dfn-type=argument data-export="" data-global-name="SecurityPolicyViolationEvent<interface>/SecurityPolicyViolationEvent()<method>/type<argument>" id=dom-securitypolicyviolationeventsecuritypolicyviolationevent-type>type<a class=self-link href=#dom-securitypolicyviolationeventsecuritypolicyviolationevent-type></a></dfn>, optional <a data-link-type=idl href=#dictdef-securitypolicyviolationeventinit title=securitypolicyviolationeventinit>SecurityPolicyViolationEventInit</a> <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent/SecurityPolicyViolationEvent() data-dfn-type=argument data-export="" data-global-name="SecurityPolicyViolationEvent<interface>/SecurityPolicyViolationEvent()<method>/eventinitdict<argument>" id=dom-securitypolicyviolationeventsecuritypolicyviolationevent-eventinitdict>eventInitDict<a class=self-link href=#dom-securitypolicyviolationeventsecuritypolicyviolationevent-eventinitdict></a></dfn>)]
interface <dfn class=idl-code data-dfn-type=interface data-export="" data-global-name="" id=dom-securitypolicyviolationevent>SecurityPolicyViolationEvent<a class=self-link href=#dom-securitypolicyviolationevent></a></dfn> : <a data-link-type=idl href=http://dom.spec.whatwg.org/#event title=event>Event</a> {
readonly attribute DOMString <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/documenturi<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="DOMString " href=#dom-securitypolicyviolationevent-documenturi title=documenturi>documentURI</a>;
readonly attribute DOMString <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/referrer<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="DOMString " href=#dom-securitypolicyviolationevent-referrer title=referrer>referrer</a>;
readonly attribute DOMString <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/blockeduri<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="DOMString " href=#dom-securitypolicyviolationevent-blockeduri title=blockeduri>blockedURI</a>;
readonly attribute DOMString <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/violateddirective<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="DOMString " href=#dom-securitypolicyviolationevent-violateddirective title=violateddirective>violatedDirective</a>;
readonly attribute DOMString <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/effectivedirective<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="DOMString " href=#dom-securitypolicyviolationevent-effectivedirective title=effectivedirective>effectiveDirective</a>;
readonly attribute DOMString <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/originalpolicy<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="DOMString " href=#dom-securitypolicyviolationevent-originalpolicy title=originalpolicy>originalPolicy</a>;
readonly attribute DOMString <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/sourcefile<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="DOMString " href=#dom-securitypolicyviolationevent-sourcefile title=sourcefile>sourceFile</a>;
readonly attribute long <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/linenumber<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="long " href=#dom-securitypolicyviolationevent-linenumber title=linenumber>lineNumber</a>;
readonly attribute long <a class=idl-code data-global-name="SecurityPolicyViolationEvent<interface>/columnnumber<attribute>" data-link-for=SecurityPolicyViolationEvent data-link-type=attribute data-readonly="" data-type="long " href=#dom-securitypolicyviolationevent-columnnumber title=columnnumber>columnNumber</a>;
};
</pre>
<dl data-dfn-for=SecurityPolicyViolationEvent>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-documenturi>documentURI<a class=self-link href=#dom-securitypolicyviolationevent-documenturi></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-document-uri><code>document-uri</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-referrer>referrer<a class=self-link href=#dom-securitypolicyviolationevent-referrer></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-referrer><code>referrer</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-blockeduri>blockedURI<a class=self-link href=#dom-securitypolicyviolationevent-blockeduri></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-blocked-uri><code>blocked-uri</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-violateddirective>violatedDirective<a class=self-link href=#dom-securitypolicyviolationevent-violateddirective></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-violated-directive><code>violated-directive</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-effectivedirective>effectiveDirective<a class=self-link href=#dom-securitypolicyviolationevent-effectivedirective></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-effective-directive><code>effective-directive</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-originalpolicy>originalPolicy<a class=self-link href=#dom-securitypolicyviolationevent-originalpolicy></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-original-policy><code>original-policy</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-sourcefile>sourceFile<a class=self-link href=#dom-securitypolicyviolationevent-sourcefile></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-source-file><code>source-file</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-linenumber>lineNumber<a class=self-link href=#dom-securitypolicyviolationevent-linenumber></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-line-number><code>line-number</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEvent data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationevent-columnnumber>columnNumber<a class=self-link href=#dom-securitypolicyviolationevent-columnnumber></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-column-number><code>column-number</code></a> property of violation reports for a description of this property.</dd>
</dl>
</section>
<section>
<h3 class="heading settled heading" data-level=6.2 id=securitypolicyviolationeventinit-interface><span class=secno>6.2 </span><span class=content>
<code>SecurityPolicyViolationEventInit</code> Interface
</span><a class=self-link href=#securitypolicyviolationeventinit-interface></a></h3>
<pre class=idl>dictionary <dfn class=idl-code data-dfn-type=dictionary data-export="" data-global-name="" id=dictdef-securitypolicyviolationeventinit>SecurityPolicyViolationEventInit<a class=self-link href=#dictdef-securitypolicyviolationeventinit></a></dfn> : <a data-link-type=idl href=http://dom.spec.whatwg.org/#eventinit title=eventinit>EventInit</a> {
DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/documenturi<dict-member>" id=dom-securitypolicyviolationeventinit-documenturi0>documentURI<a class=self-link href=#dom-securitypolicyviolationeventinit-documenturi0></a></dfn>;
DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/referrer<dict-member>" id=dom-securitypolicyviolationeventinit-referrer0>referrer<a class=self-link href=#dom-securitypolicyviolationeventinit-referrer0></a></dfn>;
DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/blockeduri<dict-member>" id=dom-securitypolicyviolationeventinit-blockeduri0>blockedURI<a class=self-link href=#dom-securitypolicyviolationeventinit-blockeduri0></a></dfn>;
DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/violateddirective<dict-member>" id=dom-securitypolicyviolationeventinit-violateddirective0>violatedDirective<a class=self-link href=#dom-securitypolicyviolationeventinit-violateddirective0></a></dfn>;
DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/effectivedirective<dict-member>" id=dom-securitypolicyviolationeventinit-effectivedirective0>effectiveDirective<a class=self-link href=#dom-securitypolicyviolationeventinit-effectivedirective0></a></dfn>;
DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/originalpolicy<dict-member>" id=dom-securitypolicyviolationeventinit-originalpolicy0>originalPolicy<a class=self-link href=#dom-securitypolicyviolationeventinit-originalpolicy0></a></dfn>;
DOMString <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/sourcefile<dict-member>" id=dom-securitypolicyviolationeventinit-sourcefile0>sourceFile<a class=self-link href=#dom-securitypolicyviolationeventinit-sourcefile0></a></dfn>;
long <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/linenumber<dict-member>" id=dom-securitypolicyviolationeventinit-linenumber0>lineNumber<a class=self-link href=#dom-securitypolicyviolationeventinit-linenumber0></a></dfn>;
long <dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=dict-member data-export="" data-global-name="SecurityPolicyViolationEventInit<dictionary>/columnnumber<dict-member>" id=dom-securitypolicyviolationeventinit-columnnumber0>columnNumber<a class=self-link href=#dom-securitypolicyviolationeventinit-columnnumber0></a></dfn>;
};
</pre>
<dl data-dfn-for=SecurityPolicyViolationEventInit>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-documenturi>documentURI<a class=self-link href=#dom-securitypolicyviolationeventinit-documenturi></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-document-uri><code>document-uri</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-referrer>referrer<a class=self-link href=#dom-securitypolicyviolationeventinit-referrer></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-referrer><code>referrer</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-blockeduri>blockedURI<a class=self-link href=#dom-securitypolicyviolationeventinit-blockeduri></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-blocked-uri><code>blocked-uri</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-violateddirective>violatedDirective<a class=self-link href=#dom-securitypolicyviolationeventinit-violateddirective></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-violated-directive><code>violated-directive</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-effectivedirective>effectiveDirective<a class=self-link href=#dom-securitypolicyviolationeventinit-effectivedirective></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-effective-directive><code>effective-directive</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-originalpolicy>originalPolicy<a class=self-link href=#dom-securitypolicyviolationeventinit-originalpolicy></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-original-policy><code>original-policy</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-sourcefile>sourceFile<a class=self-link href=#dom-securitypolicyviolationeventinit-sourcefile></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-source-file><code>source-file</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-linenumber>lineNumber<a class=self-link href=#dom-securitypolicyviolationeventinit-linenumber></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-line-number><code>line-number</code></a> property of violation reports for a description of this property.</dd>
<dt><dfn class=idl-code data-dfn-for=SecurityPolicyViolationEventInit data-dfn-type=attribute data-export="" id=dom-securitypolicyviolationeventinit-columnnumber>columnNumber<a class=self-link href=#dom-securitypolicyviolationeventinit-columnnumber></a></dfn></dt>
<dd>Refer to the <a href=#violation-report-column-number><code>column-number</code></a> property of violation reports for a description of this property.</dd>
</dl>
</section>
<section>
<h3 class="heading settled heading" data-level=6.3 id=firing-securitypolicyviolationevent-events><span class=secno>6.3 </span><span class=content>Firing Violation Events</span><a class=self-link href=#firing-securitypolicyviolationevent-events></a></h3>
<p>To <dfn data-dfn-type=dfn data-noexport="" id=fire-a-violation-event>fire a violation event<a class=self-link href=#fire-a-violation-event></a></dfn>, the user agent MUST use an algorithm
equivalent to the following:</p>
<ol>
<li>Let <var>report object</var> be the result of <a data-link-type=dfn href=#generate-a-violation-report-object title="generating a violation report object">generating a
violation report object</a>.</li>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/webappapis.html#queue-a-task title="queue a task">Queue a task</a> to
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#concept-event-fire title=firing>fire an event</a> named
<code>securitypolicyviolation</code> using the
<code><a class=idl-code data-link-type=interface href=#dom-securitypolicyviolationevent title=securitypolicyviolationevent>SecurityPolicyViolationEvent</a></code> interface
with the following initializations:
<ul>
<li><code>blockedURI</code> MUST be initialized to the value of
<var>report object</var>’s <code>blocked-uri</code> key.</li>
<li><code>documentURI</code> MUST be initialized to the value of
<var>report object</var>’s <code>document-uri</code> key.</li>
<li><code>effectiveDirective</code> MUST be initialized to the value of
<var>report object</var>’s <code>effective-directive</code> key.</li>
<li><code>originalPolicy</code> MUST be initialized to the value of
<var>report object</var>’s <code>original-policy</code> key.</li>
<li><code>referrer</code> MUST be initialized to the value of
<var>report object</var>’s <code>referrer</code> key.</li>
<li><code>violatedDirective</code> MUST be initialized to the value of
<var>report object</var>’s <code>violated-directive</code> key.</li>
<li><code>sourceFile</code> MUST be initialized to the value of
<var>report object</var>’s <code>source-file</code> key.</li>
<li><code>lineNumber</code> MUST be initialized to the value of
<var>report object</var>’s <code>line-number</code> key.</li>
<li><code>columnNumber</code> MUST be initialized to the value of
<var>report object</var>’s <code>column-number</code> key.</li>
</ul>
</li>
</ol>
<p>The <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/webappapis.html#task-source title="task source">task source</a> for these <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/webappapis.html#concept-task title=tasks>tasks</a>
is the <a data-link-type=dfn href=#content-security-policy-task-source title="content security policy task source">Content Security Policy task source</a>.</p>
</section>
</section>
<section>
<h2 class="heading settled heading" data-level=7 id=sec-directives><span class=secno>7 </span><span class=content>Directives</span><a class=self-link href=#sec-directives></a></h2>
<p>This section describes the content security policy directives
introduced in this specification. Directive names are case insensitive.</p>
<p>In order to protect against Cross-Site Scripting (XSS), web
application authors SHOULD include:</p>
<ul>
<li>both the <code><a data-link-type=dfn href=#script-src title=script-src>script-src</a></code> and
<code><a data-link-type=dfn href=#object-src title=object-src>object-src</a></code> directives, or</li>
<li>include a <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a></code> directive, which covers both
scripts and plugins.</li>
</ul>
<p>In either case, authors SHOULD NOT include either
<code>'unsafe-inline'</code> or <code>data:</code> as valid sources in
their policies. Both enable XSS attacks by allowing code to be included
directly in the document itself; they are best avoided completely.</p>
<p>Redirects are another area of potential concern. Authors SHOULD NOT include
<code>'unsafe-redirect'</code> as valid sources in their policies. It makes
it more difficult to reason about the complete set of resources that a policy
allows, especially given the path behavior outlined in the
<a data-section="" href=#source-list-paths-and-redirects>§4.2.2.3 Paths and Redirects</a> section.</p>
<section>
<h3 class="heading settled heading" data-level=7.1 id=directive-base-uri><span class=secno>7.1 </span><span class=content><code>base-uri</code></span><a class=self-link href=#directive-base-uri></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=base-uri>base-uri<a class=self-link href=#base-uri></a></dfn></code> directive restricts the URIs that can
be used to specify the <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#document-base-url title="document base url">document base URL</a>. The syntax for
the name and value of the directive are described by the following ABNF
grammar:</p>
<pre>directive-name = "base-uri"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-base-uris>allowed base URIs<a class=self-link href=#allowed-base-uris></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>base-uri</code> directive’s
value as a source list</a>.</p>
<p>Step 4 of the algorithm defined in HTML5 to obtain a
<em>document’s base URL</em> MUST be changed to:</p>
<ol start=4>
<li>If the previous step was not successful, or the result of the
previous step does not <a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a>
the <a data-link-type=dfn href=#allowed-base-uris title="allowed base uris">allowed base URIs</a>, then the <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#document-base-url title="document base url">document base URL</a>
is <var>fallback base URL</var>. Otherwise, it is the result of the
previous step.</li>
</ol>
</section>
<section>
<h3 class="heading settled heading" data-level=7.2 id=directive-child-src><span class=secno>7.2 </span><span class=content><code>child-src</code></span><a class=self-link href=#directive-child-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=child-src>child-src<a class=self-link href=#child-src></a></dfn></code> directive governs the creation of
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing contexts">nested browsing contexts</a> as well as Worker execution
contexts. The syntax for the name and value of the directive are described
by the following ABNF grammar:</p>
<pre>directive-name = "child-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-child-sources>allowed child sources<a class=self-link href=#allowed-child-sources></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>child-src</code>
directive’s value as a source list</a> if a <code>child-src</code>
directive is explicitly specified, and otherwise to the
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a>.</p>
<section>
<h4 class="heading settled heading" data-level=7.2.1 id=directive-child-src-nested><span class=secno>7.2.1 </span><span class=content>Nested Browsing Contexts</span><a class=self-link href=#directive-child-src-nested></a></h4>
<p>To enforce the <code>child-src</code> directive the user agent MUST
enforce the <code><a data-link-type=dfn href=#frame-src title=frame-src>frame-src</a></code> directive.</p>
</section>
<section>
<h4 class="heading settled heading" data-level=7.2.2 id=directive-child-src-workers><span class=secno>7.2.2 </span><span class=content>Workers</span><a class=self-link href=#directive-child-src-workers></a></h4>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URL while processing the
<code>Worker</code> or <code>SharedWorker</code> constructors
<a data-biblio-type=normative data-link-type=biblio href=#biblio-workers title=biblio-workers>[WORKERS]</a>, the user agent MUST act as if there was a fatal network
error and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>
if the URI does not <a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the
<a data-link-type=dfn href=#allowed-child-sources title="allowed child sources">allowed child sources</a>.</p>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=7.3 id=directive-connect-src><span class=secno>7.3 </span><span class=content><code>connect-src</code></span><a class=self-link href=#directive-connect-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=connect-src>connect-src<a class=self-link href=#connect-src></a></dfn></code> directive restricts which URIs the
protected resource can load using script interfaces. The syntax for the name
and value of the directive are described by the following ABNF grammar:</p>
<pre>directive-name = "connect-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-connection-targets>allowed connection targets<a class=self-link href=#allowed-connection-targets></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>connect-src</code>
directive’s value as a source list</a> if the policy contains an
explicit <code>connect-src</code> directive, or otherwise to the
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a>.</p>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URI in the course of one of the
following activities, if the URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-connection-targets title="allowed connection targets">allowed connection
targets</a>, the user agent MUST act as if there was a fatal network error
and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>:</p>
<ul>
<li>Processing the <a href=http://www.w3.org/TR/XMLHttpRequest/#the-send()-method><code>send()</code>
method</a> of an <code>XMLHttpRequest</code> object.</li>
<li>Processing the <a href=http://dev.w3.org/html5/websockets/#websocket><code>WebSocket</code>
constructor</a>.</li>
<li>Processing the <a href=http://dev.w3.org/html5/eventsource/#eventsource><code>EventSource</code>
constructor</a>.</li>
</ul>
<section class=informative>
<h4 class="heading settled heading" data-level=7.3.1 id=connect-src-usage><span class=secno>7.3.1 </span><span class=content>Usage</span><a class=self-link href=#connect-src-usage></a></h4>
<p><em>This section is not normative.</em></p>
<p>JavaScript offers a few mechanisms that directly connect to an
external server to send or receive information. <code>EventSource</code>
maintains an open HTTP connection to a server in order to receive push
notifications, <code>WebSockets</code> open a bidirectional communication
channel between your browser and a server, and <code>XMLHttpRequest</code>
makes arbitrary HTTP requests on your behalf. These are powerful APIs that
enable useful functionality, but also provide tempting avenues for data
exfiltration.</p>
<p>The <code>connect-src</code> directive allows you to ensure that
these sorts of connections are only opened to origins you trust.
Sending a policy that defines a list of source expressions for this
directive is straightforward. For example, to limit connections to
only <code>example.com</code>, send the following header:</p>
<pre>Content-Security-Policy: <a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a> example.com</pre>
<p>All of the following will fail with the preceding directive in
place:</p>
<ul>
<li><code>new WebSocket("wss://evil.com/");</code></li>
<li><code>(new XMLHttpRequest()).open("GET", "https://evil.com/", true);</code></li>
<li><code>new EventSource("https://evil.com");</code></li>
</ul>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=7.4 id=directive-default-src><span class=secno>7.4 </span><span class=content><code>default-src</code></span><a class=self-link href=#directive-default-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=default-src>default-src<a class=self-link href=#default-src></a></dfn></code> directive sets a default
source list for a number of directives. The syntax for the name and
value of the directive are described by the following ABNF grammar:</p>
<pre>directive-name = "default-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>Let the <dfn data-dfn-type=dfn data-noexport="" id=default-sources>default sources<a class=self-link href=#default-sources></a></dfn> be the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>default-src</code>
directive’s value as a source list</a> if a <code>default-src</code>
directive is explicitly specified, and otherwise the U+002A ASTERISK
character (*).</p>
<p>To enforce the <code>default-src</code> directive, the user agent
MUST enforce the following directives:</p>
<ul>
<li><code><a data-link-type=dfn href=#child-src title=child-src>child-src</a></code></li>
<li><code><a data-link-type=dfn href=#connect-src title=connect-src>connect-src</a></code></li>
<li><code><a data-link-type=dfn href=#font-src title=font-src>font-src</a></code></li>
<li><code><a data-link-type=dfn href=#img-src title=img-src>img-src</a></code></li>
<li><code><a data-link-type=dfn href=#media-src title=media-src>media-src</a></code></li>
<li><code><a data-link-type=dfn href=#object-src title=object-src>object-src</a></code></li>
<li><code><a data-link-type=dfn href=#script-src title=script-src>script-src</a></code></li>
<li><code><a data-link-type=dfn href=#style-src title=style-src>style-src</a></code></li>
</ul>
<p>If not specified explicitly in the policy, the directives listed
above will use the <a data-link-type=dfn href=#default-sources title="default sources">default sources</a> as their source list.</p>
<section>
<h4 class="heading settled heading" data-level=7.4.1 id=default-src-usage><span class=secno>7.4.1 </span><span class=content>Usage</span><a class=self-link href=#default-src-usage></a></h4>
<p><em>This section is not normative.</em></p>
<p><code>default-src</code>, as the name implies, serves as a default
source list which the other source list-style directives will use as
a fallback if they’re not otherwise explicitly set. That is, consider
the following policy declaration:</p>
<pre>Content-Security-Policy: <a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'self'</pre>
<p>Under this policy, fonts, frames, images, media, objects, scripts,
and styles will all only load from the same origin as the protected
resource, and connections will only be made to the same origin. Adding
a more specific declaration to the policy would completely override
the default source list for that resource type.</p>
<pre>Content-Security-Policy: <a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'self'; <a data-link-type=dfn href=#script-src title=script-src>script-src</a> example.com</pre>
<p>Under this new policy, fonts, frames, and etc. continue to be load
from the same origin, but scripts will <em>only</em> load from
<code>example.com</code>. There’s no inheritance; the
<code><a data-link-type=dfn href=#script-src title=script-src>script-src</a></code> directive sets the allowed sources of
script, and the default list is not used for that resource type.</p>
<p>Given this behavior, one good way of building a policy for a site
would be to begin with a <code>default-src</code> of
<code>'none'</code>, and to build up a policy from there that contains
only those resource types which are actually in use for the page you’d
like to protect. If you don’t use webfonts, for instance, there’s no
reason to specify a source list for <code><a data-link-type=dfn href=#font-src title=font-src>font-src</a></code>;
specifying only those resource types a page uses ensures that the
possible attack surface for that page remains as small as possible.</p>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=7.5 id=directive-font-src><span class=secno>7.5 </span><span class=content><code>font-src</code></span><a class=self-link href=#directive-font-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=font-src>font-src<a class=self-link href=#font-src></a></dfn></code> directive restricts from where the
protected resource can load fonts. The syntax for the name and value
of the directive are described by the following ABNF grammar:</p>
<pre>directive-name = "font-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-font-sources>allowed font sources<a class=self-link href=#allowed-font-sources></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>font-src</code>
directive’s value as a source list</a> if the policy contains an
explicit <code>font-src</code>, or otherwise to the
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a>.</p>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URI in the course of one of the
following activities, if the URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-font-sources title="allowed font sources">allowed font sources</a>,
the user agent MUST act as if there was a fatal network error
and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>:</p>
<ul>
<li>Requesting data for display in a font, such as when processing
the <a class="production css-code" data-link-type=at-rule href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>&lt;@font-face&gt;</a> Cascading Style Sheets (CSS) rule.</li>
</ul>
</section>
<section>
<h3 class="heading settled heading" data-level=7.6 id=directive-form-action><span class=secno>7.6 </span><span class=content><code>form-action</code></span><a class=self-link href=#directive-form-action></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=form-action>form-action<a class=self-link href=#form-action></a></dfn></code> restricts which URIs can be used as
the action of HTML <code><a data-link-type=element href=http://www.w3.org/TR/html5/forms.html#the-form-element title=form>form</a></code> elements. The syntax for the name and
value of the directive are described by the following ABNF grammar:</p>
<pre>directive-name = "form-action"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-form-actions>allowed form actions<a class=self-link href=#allowed-form-actions></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>form-action</code>
directive’s value as a source list</a>.</p>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URI in the course of one of the
following activities, if the URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-form-actions title="allowed form actions">allowed form actions</a>,
the user agent MUST act as if there was a fatal network error
and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>:</p>
<ul>
<li>Processing an HTML <code><a data-link-type=element href=http://www.w3.org/TR/html5/forms.html#the-form-element title=form>form</a></code> element.</li>
<li>Pinging an endpoint during <a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#hyperlink-auditing>hyperlink auditing</a></li>
</ul>
<p class=note>Note: <code>form-action</code> does not fall back to the <a data-link-type=dfn href=#default-sources title="default sources">default
sources</a> when the directive is not defined. That is, a policy that
defines <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'none'</code> but not
<code>form-action</code> will still allow form submissions to any
target.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=7.7 id=directive-frame-ancestors><span class=secno>7.7 </span><span class=content><code>frame-ancestors</code></span><a class=self-link href=#directive-frame-ancestors></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=frame-ancestors>frame-ancestors<a class=self-link href=#frame-ancestors></a></dfn></code> directive indicates whether the
user agent should allow embedding the resource using a
<code><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/obsolete.html#frame title=frame>frame</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code> or
<code><a data-link-type=element href=http://www.w3.org/TR/html5/obsolete.html#the-applet-element title=applet>applet</a></code> tag, or equivalent
functionality in non-HTML resources. Resources can use this directive to
avoid many UI Redressing <a data-biblio-type=informative data-link-type=biblio href=#biblio-uiredress title=biblio-uiredress>[UIREDRESS]</a> attacks by avoiding being embedded
into potentially hostile contexts.</p>
<p>The syntax for the name and value of the directive are described by the
following ABNF grammar:</p>
<pre>directive-name = "frame-ancestors"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-frame-ancestors>allowed frame ancestors<a class=self-link href=#allowed-frame-ancestors></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>frame-ancestors</code>
directive’s value as a source list</a>. If a <code>frame-ancestors</code>
directive is not explicitly included in the policy, then <a data-link-type=dfn href=#allowed-frame-ancestors title="allowed frame ancestors">allowed frame
ancestors</a> is "<code>*</code>".</p>
<p>To enforce the <code>frame-ancestors</code> directive, whenever the
user agent would load the protected resource into a <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing context">nested browsing
context</a>, the user agent MUST perform the following steps:</p>
<ol>
<li>Let <var>nestedContext</var> be the nested browsing context into
which the protected resource is being loaded.</li>
<li>Let <var>ancestorList</var> be the list of all
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#ancestor-browsing-context title=ancestors>ancestors</a> of <var>nestedContext</var>.</li>
<li>For each <var>ancestorContext</var> in <var>ancestorList</var>:
<ol>
<li>Let <var>document</var> be <var>ancestorContext</var>’s
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#active-document title="active document">active document</a>.</li>
<li>If <var>document</var>’s URL does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-frame-ancestors title="allowed frame ancestors">allowed frame
ancestors</a>, the user agent MUST:
<ol>
<li>Abort loading the protected resource.</li>
<li>Act as if it received an empty <a data-link-type=dfn href=#http-200-response title="http 200 response">HTTP 200 response</a>.</li>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#parse-a-sandboxing-directive title="parse a sandboxing directive">Parse a sandboxing directive</a> using the
empty string as the <em>input</em> and the newly created
document’s <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#forced-sandboxing-flag-set title="forced sandboxing flag set">forced sandboxing flag set</a> as the
<em>output</em>.</li>
</ol>
</li>
</ol>
</li>
</ol>
<p>Steps 2.2 and 2.3 ensure that the blocked frame appears to be a
normal cross-origin document’s load. If these steps are ignored,
leakage of a document’s policy state is possible. The user agent MAY
implement these steps by instead redirecting the user to friendly
error page in a unique origin which provides the option of opening
the blocked page in a new <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#top-level-browsing-context title="top-level browsing context">top-level browsing context</a>.</p>
<p>The <code>frame-ancestors</code> directive MUST be ignored
when <a data-link-type=dfn href=#monitor title=monitoring>monitoring</a> a policy, and when a contained in a
policy defined via a <code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#meta title=meta>meta</a></code> element.</p>
<p class=note>Note: <code><a data-link-type=dfn href=#frame-ancestors title=frame-ancestors>frame-ancestors</a></code> does not fall back to the
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a> when the directive is not defined. That is, a policy
that defines <code><a data-link-type=dfn href=#default-src title=default-src>default-src</a> 'none'</code> but not
<code>frame-ancestors</code> will still allow the resource to be framed from
anywhere.</p>
<p>When generating a violation report for a <code>frame-ancestors</code>
violation, the user agent MUST NOT include the value of the embedding
ancestor as a <code>blocked-uri</code> value unless it is same-origin with
the protected resource, as disclosing the value of cross-origin ancestors
is a violation of the Same-Origin Policy.</p>
<section>
<h4 class="heading settled heading" data-level=7.7.1 id=frame-ancestors-and-frame-options><span class=secno>7.7.1 </span><span class=content>
Relation to <code>X-Frame-Options</code>
</span><a class=self-link href=#frame-ancestors-and-frame-options></a></h4>
<p>This directive is similar to the <code>X-Frame-Options</code> header that
several user agents have implemented. The <code>'none'</code> source
expression is roughly equivalent to that header’s <code>DENY</code>,
<code>'self'</code> to <code>SAMEORIGIN</code>, and so on. The major
difference is that many user agents implement <code>SAMEORIGIN</code> such
that it only matches against the top-level document’s location. This
directive checks each ancestor. If any ancestor doesn’t match, the load
is cancelled. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc7034 title=biblio-rfc7034>[RFC7034]</a></p>
<p>The <code>frame-ancestors</code> directive <em>obsoletes</em> the
<code>X-Frame-Options</code> header. If a resource has both policies,
the <code>frame-ancestors</code> policy SHOULD be enforced and the
<code>X-Frame-Options</code> policy SHOULD be ignored.</p>
</section>
<section class=informative id=multiple-host-source-values>
<h4 class="heading settled heading" data-level=7.7.2 id=frame-ancestors-multiple-source-values><span class=secno>7.7.2 </span><span class=content>Multiple Host Source Values</span><a class=self-link href=#frame-ancestors-multiple-source-values></a></h4>
<p><em>This section is not normative.</em></p>
<p>Multiple source-list expressions are allowed in a single policy (in contrast
to <code>X-Frame-Options</code>, which allows only one) to enable
scenarios involving embedded application components that are multiple levels
below the top-level browsing context.</p>
<p>Many common scenarios for permissioned embedding (e.g. embeddable payment,
sharing or social apps) involve potentially many hundreds or thousands of
valid <code>source-list</code> expressions, but it is strongly recommended
against accommodating such scenarios with a static
<code>frame-ancestors</code> directive listing multiple values. In such
cases it is beneficial to generate this value dynamically, based on an
HTTP Referer header or an explicitly passed-in value, to allow only the
sources necessary for each given embedding of the resource.</p>
<p>Consider a service providing a payments application at
<code>https://payments/makeEmbedded</code>. The service allows this resource
to be embedded by both merchant Alice and merchant Bob, who compete with each
other. Sending:</p>
<pre>Content-Security-Policy: <a data-link-type=dfn href=#frame-ancestors title=frame-ancestors>frame-ancestors</a> https://alice https://bob
</pre>
<p>would allow Bob to re-frame Alice’s resource and create fraudulent clicks,
perhaps discrediting Alice with her customers or the payments service. If the
payments service used additional information (e.g. as part of a URL like
<code>https://payments/makeEmbedded?merchant=alice</code>) to send
individually-tailored headers listing only the source-list expressions
needed by each merchant, this attack would be eliminated.</p>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=7.8 id=directive-frame-src><span class=secno>7.8 </span><span class=content><code>frame-src</code></span><a class=self-link href=#directive-frame-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=frame-src>frame-src<a class=self-link href=#frame-src></a></dfn></code> directive is <em>deprecated</em>.
Authors who wish to govern nested browsing contexts SHOULD use the
<code>child-src</code> directive instead.</p>
<p>The <code>frame-src</code> directive restricts from where the
protected resource can embed frames. The syntax for the name
and value of the directive are described by the following ABNF
grammar:</p>
<pre>directive-name = "frame-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-frame-sources>allowed frame sources<a class=self-link href=#allowed-frame-sources></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>frame-src</code>
directive’s value as a source list</a> if the policy contains an
explicit <code>frame-src</code>, or otherwise to the list of
<a data-link-type=dfn href=#allowed-child-sources title="allowed child sources">allowed child sources</a>.</p>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URI in the course of one of the
following activities, if the URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-frame-sources title="allowed frame sources">allowed frame sources</a>,
the user agent MUST act as if there was a fatal network error
and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>:</p>
<ul>
<li>Requesting data for display in a <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing context">nested browsing context</a> in the
protected resource created by an <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-iframe-element title=iframe>iframe</a></code> or
a <code><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/obsolete.html#frame title=frame>frame</a></code> element.</li>
<li><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#navigate title=navigated>Navigated</a> such a <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing context">nested browsing context</a>.</li>
</ul>
</section>
<section>
<h3 class="heading settled heading" data-level=7.9 id=directive-img-src><span class=secno>7.9 </span><span class=content><code>img-src</code></span><a class=self-link href=#directive-img-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=img-src>img-src<a class=self-link href=#img-src></a></dfn></code> directive restricts from where the
protected resource can load images. The syntax for the name and value
of the directive are described by the following ABNF grammar:</p>
<pre>directive-name = "img-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-image-sources>allowed image sources<a class=self-link href=#allowed-image-sources></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>img-src</code>
directive’s value as a source list</a> if the policy contains an
explicit <code>img-src</code>, or otherwise to the list of
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a>.</p>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URI in the course of one of the
following activities, if the URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-image-sources title="allowed image sources">allowed image sources</a>,
the user agent MUST act as if there was a fatal network error
and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>:</p>
<ul>
<li>Requesting data for an image, such as when processing the
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-img-src title=src>src</a></code> or
<code>srcset</code> attributes of an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element title=img>img</a></code> element, the
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-img-src title=src>src</a></code> attribute of an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/forms.html#the-input-element title=input>input</a></code> element with a type of
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/forms.html#attr-input-type-image-keyword title=image>image</a></code>,
the <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster title=poster>poster</a></code> attribute of a
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#video title=video>video</a></code> element,
the <span class=css data-link-type=maybe title=url()>url()</span>, <a class="production css-code" data-link-type=function href=http://dev.w3.org/csswg/css-images-4/#funcdef-image title=image()>&lt;image()&gt;</a> or <a class="production css-code" data-link-type=function href=http://dev.w3.org/csswg/css-images-4/#funcdef-image-set title=image-set()>&lt;image-set()&gt;</a> values on any
Cascading Style Sheets (CSS)
property that is capable of loading an image <a data-biblio-type=normative data-link-type=biblio href=#biblio-css4-images title=biblio-css4-images>[CSS4-IMAGES]</a>, or
the <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-base-href title=href>href</a></code> attribute of a
<code><a data-link-type=element href=http://www.w3.org/TR/html5/document-metadata.html#the-link-element title=link>link</a></code> element with an image-related
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-link-rel title=rel>rel</a></code> attribute, such as
<code><a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/links.html#rel-icon-0 title=icon>icon</a></code>.</li>
</ul>
</section>
<section>
<h3 class="heading settled heading" data-level=7.10 id=directive-media-src><span class=secno>7.10 </span><span class=content><code>media-src</code></span><a class=self-link href=#directive-media-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=media-src>media-src<a class=self-link href=#media-src></a></dfn></code> directive restricts from where the
protected resource can load video, audio, and associated text tracks.
The syntax for the name and value of the directive are described by the
following ABNF grammar:</p>
<pre>directive-name = "media-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-media-sources>allowed media sources<a class=self-link href=#allowed-media-sources></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>media-src</code>
directive’s value as a source list</a> if the policy contains an
explicit <code>media-src</code>, or otherwise to the list of
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a>.</p>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URI in the course of one of the
following activities, if the URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-media-sources title="allowed media sources">allowed media sources</a>,
the user agent MUST act as if there was a fatal network error
and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>:</p>
<ul>
<li>Requesting data for a video or audio clip, such as when
processing the <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-img-src title=src>src</a></code> attribute of a
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#video title=video>video</a></code>, <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#audio title=audio>audio</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-source-element title=source>source</a></code>, or <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-track-element title=track>track</a></code>
elements.</li>
</ul>
</section>
<section>
<h3 class="heading settled heading" data-level=7.11 id=directive-object-src><span class=secno>7.11 </span><span class=content><code>object-src</code></span><a class=self-link href=#directive-object-src></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=object-src>object-src<a class=self-link href=#object-src></a></dfn></code> directive restricts from where
the protected resource can load plugins. The syntax for the name and value
of the directive are described by the following ABNF grammar:</p>
<pre>directive-name = "object-src"
directive-value = <a data-link-type=dfn href=#source-list title=source-list>source-list</a>
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-object-sources>allowed object sources<a class=self-link href=#allowed-object-sources></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-source-list title="parse a source list">parsing the <code>object-src</code>
directive’s value as a source list</a> if the policy contains an
explicit <code>object-src</code>, or otherwise to the list of
<a data-link-type=dfn href=#default-sources title="default sources">default sources</a>.</p>
<p>Whenever the user agent <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#fetch title=fetches>fetches</a> a URI in the course of one of the
following activities, if the URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-object-sources title="allowed object sources">allowed object sources</a>,
the user agent MUST act as if there was a fatal network error
and no resource was obtained, <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a>:</p>
<ul>
<li>Requesting data for a plugin, such as when processing the
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-object-data title=data>data</a></code> attribute of an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code> element, the
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/embedded-content-0.html#attr-img-src title=src>src</a></code> attribute of an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code> elements, or the
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/obsolete.html#attr-object-code title=code>code</a></code> or
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/obsolete.html#attr-object-archive title=archive>archive</a></code> attributes of an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/obsolete.html#the-applet-element title=applet>applet</a></code> element.</li>
<li>Requesting data for display in a <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing context">nested browsing context</a>
in the protected resource created by an <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code>
or an <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code> element.</li>
<li>Navigating such a <a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing context">nested browsing context</a>.</li>
</ul>
<p>It is not required that the consumer of the element’s data be a
<a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#plugin title=plugin>plugin</a> in order for the <code>object-src</code> directive to be
enforced. Data for any <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code>,
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code>, or <code><a data-link-type=element href=http://www.w3.org/TR/html5/obsolete.html#the-applet-element title=applet>applet</a></code>
element MUST match the <a data-link-type=dfn href=#allowed-object-sources title="allowed object sources">allowed object sources</a> in order to be fetched.
This is true even when the element data is semantically equivalent to
content which would otherwise be restricted by one of the other
<a data-section="" href=#sec-directives>directives</a>, such as an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code> element with a <code>text/html</code>
MIME type.</p>
<p>Whenever the user agent would load a <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#plugin title=plugin>plugin</a> without an associated
URI (e.g., because the <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code> element lacked a
<code>data</code> attribute), if the protected resource’s URI does not
<a data-link-type=dfn href=#match-a-source-list title="match a source list">match</a> the <a data-link-type=dfn href=#allowed-object-sources title="allowed object sources">allowed object sources</a>,
the user agent MUST NOT load the plugin.</p>
</section>
<section>
<h3 class="heading settled heading" data-level=7.12 id=directive-plugin-types><span class=secno>7.12 </span><span class=content><code>plugin-types</code></span><a class=self-link href=#directive-plugin-types></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=plugin-types>plugin-types<a class=self-link href=#plugin-types></a></dfn></code> directive restricts the set
of plugins that can be invoked by the protected resource by limiting
the types of resources that can be embedded. The syntax for the name
and value of the directive are described by the following ABNF
grammar:</p>
<pre>directive-name = "plugin-types"
directive-value = media-type-list
</pre>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=allowed-plugin-media-types>allowed plugin media types<a class=self-link href=#allowed-plugin-media-types></a></dfn> refers to the result of
<a data-link-type=dfn href=#parse-a-media-type-list title="parse a media type list">parsing the <code>plugin-types</code>
directive’s value as a media type list</a>.</p>
<p>Whenever the user agent would instantiate a <a data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#plugin title=plugin>plugin</a>
to handle <var>resource</var> while enforcing the <code>plugin-types</code>
directive, the user agent MUST instead act as though the plugin reported an
error <em>and</em> <a data-link-type=dfn href=#report-a-violation title="report a violation">report a violation</a> if any of the following
conditions hold:</p>
<ul>
<li>The plugin is embedded into the protected resource via an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code> or
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code> element that does not explicitly
declare a <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/infrastructure.html#mime-type title="mime type">MIME type</a> via a
<code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-link-type title=type>type</a></code> attribute.</li>
<li><var>resource</var>’s media type does not
<a data-link-type=dfn href=#match-a-media-type-list title="match a media type list">match</a> the list of <a data-link-type=dfn href=#allowed-plugin-media-types title="allowed plugin media types">allowed
plugin media types</a>.</li>
<li>The plugin is embedded into the protected resource via an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code> or
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code> element, and the media type declared
in the element’s <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-link-type title=type>type</a></code> attribute is not
a case-insensitive match for the <var>resource</var>’s media
type.</li>
<li>The plugin is embedded into the protected resource via an
<code><a data-link-type=element href=http://www.w3.org/TR/html5/obsolete.html#the-applet-element title=applet>applet</a></code> element, and <var>resource</var>’s
media type is not a case-insensitive match for
<code>application/x-java-applet</code>.</li>
</ul>
<p class=note>Note: In any of these cases, acting as though the plugin reported an
error will cause the user agent to display the <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/dom.html#fallback-content title="fallback content">fallback
content</a>.</p>
<p>Whenever the user agent creates a <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#plugin-document title="plugin document">plugin document</a> in a
<a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing context">nested browsing context</a> in the <a data-link-type=dfn href=#protected-resource title="protected resource">protected resource</a>, if the user
agent is enforcing any <code>plugin-types</code> directives for the
protected resource, the user agent MUST <a data-link-type=dfn href=#enforce title=enforce>enforce</a> those
<code>plugin-types</code> directives on the plugin document as well.</p>
<p>Whenever the user agent creates a <a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#plugin-document title="plugin document">plugin document</a> in a
<a data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#nested-browsing-context title="nested browsing context">nested browsing context</a> in the <a data-link-type=dfn href=#protected-resource title="protected resource">protected resource</a>, if the user
agent is monitoring any <code>plugin-types</code> directives for the
protected resource, the user agent MUST <a data-link-type=dfn href=#monitor title=monitor>monitor</a> those
<code>plugin-types</code> directives on the plugin document as well.</p>
<section class=informative>
<h4 class="heading settled heading" data-level=7.12.1 id=plugin-types-usage><span class=secno>7.12.1 </span><span class=content>Usage</span><a class=self-link href=#plugin-types-usage></a></h4>
<p><em>This section is not normative.</em></p>
<p>The <code>plugin-types</code> directive whitelists a certain set
of MIME types that can be embedded in a protected resource. For
example, a site might want to ensure that PDF content loads, but that
no other plugins can be instantiated. The following directive would
satisfy that requirement:</p>
<pre>Content-Security-Policy: <a data-link-type=dfn href=#plugin-types title=plugin-types>plugin-types</a> application/pdf</pre>
<p>Resources embedded via an <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code> or
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code> element delivered with an
<code>application/pdf</code> content type would be rendered in the
appropriate plugin; resources delivered with some other content type
would be blocked. Multiple types can be specified, in any order. If the
site decided to additionally allow Flash at some point in the future, it
could do so with the following directive:</p>
<pre>Content-Security-Policy: <a data-link-type=dfn href=#plugin-types title=plugin-types>plugin-types</a> application/pdf application/x-shockwave-flash</pre>
<p class=note>Note: Wildcards are not accepted in the <code>plugin-types</code>
directive. Only the resource types explicitly listed in the directive
will be allowed.</p>
</section>
<section class=informative>
<h4 class="heading settled heading" data-level=7.12.2 id=plugin-types-predeclaration><span class=secno>7.12.2 </span><span class=content>
Predeclaration of expected media types
</span><a class=self-link href=#plugin-types-predeclaration></a></h4>
<p><em>This section is not normative.</em></p>
<p>Enforcing the <code>plugin-types</code> directive requires that
<code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element title=object>object</a></code> and <code><a data-link-type=element href=http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element title=embed>embed</a></code>
elements declare the expected media type of the resource they include via
the <code><a data-link-type=element-attr href=http://www.w3.org/TR/html5/document-metadata.html#attr-link-type title=type>type</a></code> attribute. If an author expects
to load a PDF, she could specify this as follows:</p>
<pre>&lt;object data="<var>resource</var>" type="application/pdf"&gt;&lt;/object&gt;</pre>
<p>If <var>resource</var> isn’t actually a PDF file, it won’t
load. This prevents certain types of attacks that rely on serving
content that unexpectedly invokes a plugin other than that which the
author intended.</p>
<p class=note>Note: <var>resource</var> will not load in this scenario even
if its media type is otherwise whitelisted: resources will only load
when their media type is whitelisted <em>and</em> matches the
declared type in their containing element.</p>
</section>
</section>
<section>
<h3 class="heading settled heading" data-level=7.13 id=directive-referrer><span class=secno>7.13 </span><span class=content><code>referrer</code></span><a class=self-link href=#directive-referrer></a></h3>
<p>The <code><dfn data-dfn-type=dfn data-noexport="" id=referrer>referrer<a class=self-link href=#referrer></a></dfn></code> directive specifies a referrer
policy that the user agent applies when determining what referrer
information should be included with requests made, and with
<a data-link-spec=HTML5 data-link-type=dfn href=http://www.w3.org/TR/html5/browsers.html#browsing-context title="browsing contexts">browsing contexts</a> created from the context of the
protected resource. The syntax for the name and value of the directive
are described by the following ABNF grammar:</p>
<pre>directive-name = "referrer"
directive-value = "none" / "none-when-downgrade" / "origin" / "origin-when-cross-origin" / "unsafe-url"
</pre>
<p class=note>Note: The directive name does not share the HTTP header’s misspelling.</p>
<p>The term <dfn data-dfn-type=dfn data-noexport="" id=referrer-policy>referrer policy<a class=self-link href=#referrer-policy></a></dfn> refers to the value of the
<code>referrer</code> directive, or to <code>none-when-downgrade</code>
if no <code>referrer</code> directive is present in the protected
resource’s policy.</p>
<p>If the value of the <code>referrer</code> directive is invalid,
the user agent SHOULD set the referrer policy to <code>never</code>.</p>
<p>Replace step 7 of the
<a href=http://fetch.spec.whatwg.org/>"Determine referrer" algorithm defined in Fetch</a>
with the following:</p>
<ol start=7>
<li>If <var>referrer</var> is null, or if the <a data-link-type=dfn href=#referrer-policy title="referrer policy">referrer policy</a> is
<code>none</code>, return <strong>null</strong>.</li>
<li>If the <a data-link-type=dfn href=#referrer-policy title="referrer policy">referrer policy</a> is
<code>origin</code>, return the ASCII serialization of
<var>referrer</var>’s origin. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc6454 title=biblio-rfc6454>[RFC6454]</a></li>
<li>If the <a data-link-type=dfn href=#referrer-policy title="referrer policy">referrer policy</a> is
<code>origin-when-cross-origin</code>, return <var>referrer</var>
if <var>referrer</var>’s origin is the same as the origin of the
resource being fetched, and otherwise the ASCII serialization of
<var>referrer</var>’s origin. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc6454 title=biblio-rfc6454>[RFC6454]</a></li>
<li>If the <a data-link-type=dfn href=#referrer-policy title="referrer policy">referrer policy</a> is <code>unsafe-url</code>, return
<var>referrer</var>. Note that this might cause HTTPS referrer
information to be sent over the network as part of unencrypted HTTP
requests.</li>
<li>If the <a data-link-type=dfn href=#referrer-policy title="referrer policy">referrer policy</a> is <code>none-when-downgrade</code>,
then:
<ul>
<li>Return <strong>null</strong> if the scheme component of
<var>referrer</var> represents a protocol that uses
transport-layer security and the scheme component of the
resource being fetched does not.</li>
<li>Otherwise return <var>referrer</var>.</li>
</ul>
</li>
</ol>
<p class=note>Note: This specification should not be interpreted as limiting
user agents' ability to apply other restrictions to limit referrer
leakage.</p>
<section>
<h4 class="heading settled heading" data-level=7.13.1