Directives and source values
Commonly used directives, their fallback order, and the scope of each source expression. Definitions follow CSP Level 3.1 Browser support per directive is listed by MDN.2
Directives
| Directive | Controls | Falls back to | Typical value |
|---|---|---|---|
default-src | Fallback for the fetch directives below | none | 'self' |
script-src | JavaScript files, inline scripts, eval | default-src | Nonces or hashes. No 'unsafe-*'6 |
script-src-elem | <script> elements only | script-src | Usually unset |
connect-src | fetch, XHR, WebSocket, sendBeacon, EventSource | default-src | APIs the page calls |
img-src | Images, favicons | default-src | 'self' data: and image CDNs |
style-src | Stylesheets and inline styles | default-src | 'self' |
frame-src | Iframes your page embeds | child-src, then default-src | Payment and media providers |
object-src | <object> and <embed> plugins | default-src | 'none' |
base-uri | The <base> element | no fallback | 'self' or 'none' |
form-action | Where forms may submit | no fallback | 'self' |
frame-ancestors | Who may embed your page (clickjacking) | no fallback | 'self' or 'none' |
report-to | Reporting endpoint name, defined in Reporting-Endpoints4 | n/a | Set |
upgrade-insecure-requests | Rewrites http:// requests to https:// | n/a | Set |
Source values
| Value | Allows | Risk |
|---|---|---|
'self' | The document's origin | LOW |
'none' | Nothing | LOW |
'nonce-…' / 'sha256-…' | Elements carrying the nonce, or scripts matching the hash | LOW |
https://cdn.vendor.com | Any resource the host serves, including JSONP endpoints and old library versions5 | VENDOR-DEPENDENT |
*.vendor.com | Every subdomain, including unreviewed ones | MEDIUM |
'strict-dynamic' | Any script a trusted script inserts. Host entries are ignored.1 | MEDIUM |
'unsafe-eval' | eval(), new Function(), string timers | HIGH |
'unsafe-inline' | Any inline script or event handler. Ignored when a nonce or hash is present.3 | HIGH |
https: / * | Any host | HIGH |
data: in script-src | Scripts built from data URLs | HIGH |
Risk ratings follow the OWASP CSP Cheat Sheet and Google's strict CSP guidance.7,6
References
- [1]Content Security Policy Level 3. W3C, Web Application Security Working Group. Working Draft. The normative definition of directives, source matching and fallback.
- [2]
- [3]CSP: script-src. MDN Web Docs.
- [4]Reporting-Endpoints header. MDN Web Docs.
- [5]CSP Is Dead, Long Live CSP! On the Insecurity of Whitelists and the Future of Content Security Policy. Weichselbaum, Spagnuolo, Lekies, Janc. ACM CCS, 2016. Analysis of 26,011 unique policies from 1,680,867 hosts.
- [6]Mitigate cross-site scripting (XSS) with a strict Content Security Policy. web.dev (Google).
- [7]Content Security Policy Cheat Sheet. OWASP Cheat Sheet Series.