?
X-CONTENT-SECURITY-POLICY/ X-WEBKIT-CSP (est 2011)
X-CONTENT-SECURITY-POLICY/ X-WEBKIT-CSP (est 2011)
CONTENT-SECURITY-POLICY (est 2013)
CONTENT-SECURITY-POLICY (est 2013)
CONTENT-SECURITY-POLICY (est 2015)
a.k.a. Level 2
CONTENT-SECURITY-POLICY (est 2017)
a.k.a. Level 3
Content-Security-Policy: script-src 'self' https://goog.com;
{ }{ }{ }Header name
Directive
Directive values
Content
img-src style-src font-src script-src
object-src media-src plugin-types prefetch-src
URI
frame-src connect-src
child-src frame-ancestors base-uri form-action
worker-src manifest-src
Behavior
default-src report-uri sandbox
report-to navigate-to
Keywords
'none' 'self' 'unsafe-inline' 'unsafe-eval'
'nonce-' 'sha256-'
'strict-dynamic' 'unsafe-hashes'
Scheme source
http: https: data: blob: filesystem:
Host source
http://*.goog.com mail.goog.com:443 https://goog.com *.goog.com *
There is also a Content-Security-Policy-Report-Only header that can be used for reporting instead of blocking violations
The 'report-uri' and 'report-to'* directives allow the inclusion of an endpoint to POST violations to
*'report-to' is used in conjunction with the 'Reporting-Endpoints' header, which can define endpoints as variables to be used in other headers
// example report
{
"csp-report": {
"document-uri": "http://example.org/page.html",
"referrer": "http://evil.example.com/",
"blocked-uri": "http://evil.example.com/evil.js",
"violated-directive": "script-src 'self' https://apis.google.com",
"original-policy": "script-src 'self' https://apis.google.com; report-uri http://example.org/my_amazing_csp_report_parser"
}
}Reporting allows you to monitor and adjust your CSP based on actual user experience
The CSP can also be set as a meta tag
You can use CONTENT-SECURITY-POLICY-REPORT-ONLY header in tandem to test new directives without breaking your site!
Most directives* use a fallback strategy, ultimately falling back to 'default-src' directive values
*excluding base-uri, form-action, frame-ancestors, plugin-types, report-uri, sandbox - be sure to set these explicitly!
Obviously new directive values not recognized by agents using previous versions, but some old values are ignored when certain new values are present. (more on that later)
Content-Security-Policy: default-src 'none'; script-src 'self' *.goog.com; img-src 'self'; style-src 'self';CSP is parsed by user agent at page load
Refused to load the script 'evil-script.js' because it violates the following Content Security Policy directive: "script-src".
If script origin is not included in approved hosts, loading is blocked, and an error is thrown
Content-Security-Policy: script-src 'nonce-r@nd0m' 'self' *.goog.com;<script nonce="r@nd0m">
doWhatever();
</script>A nonce is a randomly generated value used by the browser to authenticate elements (not limited to script tags) before parsing
Content-Security-Policy: script-src 'sha256-RFWPLDbv2BY+rCkDzsE+0fr8ylGr2R2faWMhq4lfEQc=' 'self' *.goog.com;<script>
doWhatever();
</script>A hash is a value generated using the element contents and is used by the browser to authenticate specific elements (not limited to script tags) before parsing
Content-Security-Policy: script-src 'nonce-r@nd0m' 'strict-dynamic' 'self' *.goog.com;// trusted-script.js
var s = document.createElement('script');
s.text = "doSomething();";
document.body.appendChild(s);Strict Dynamic is a level 3 directive value that permits scripts that have been safely loaded to perform or load inline scripts
<script src="https://goog.com/trusted-script.js" nonce="r@nd0m"></script>CSP Links and resources will be included with the recording email