self Source List Keywordself Content Security Policy (CSP) keyword is an alias for the same origin of the current document.self mean in a CSP Policy?When you encounter the self keyword in a Content-Security-Policy header directive it is an alias for the same origin. The same origin includes the scheme (http:// or https://) as well as the domain name. So if you type the following into the address bar of a browser:
https://app.example.com/sub-app/
The origin is: https://app.example.com
Suppose you are setting a Content-Security-Policy header for the site: https://app.example.com
If you set the following header:
Content-Security-Policy: default-src 'none'; img-src 'self';
The following are allowed by the CSP 'self' keyword in the policy above:
<img src="/images/logo.png"> <img src="https://app.example.com/images/logo.png">
The following would be blocked by the policy.
<img src="https://other-app.example.com/images/logo.png">
If we wanted to allow images to load from other-app.example.com, then we need to allow it in our CSP policy:
Content-Security-Policy: default-src 'none'; img-src 'self' https://other-app.example.com;
If you're not sure what default-src or img-src are, then check out our CSP Reference Guide for details.
self not working?Here are some reasons why your CSP self keyword is not working:
self and not 'self' the single quotes are required.selfThe CSP self source list keyword has been part of the Content Security Policy Specification since the first version of it (CSP Level 1).
Internet Explorer 11 and below do not support the CSP self keyword.
Want to learn the ins and outs CSP? Grab a copy of the CSP Developer Field Guide. It's a short and sweet guide to help developers get up to speed quickly.
Grab a CopyAdvisory Week is a weekly roundup of all the security advisories published by the major software vendors.