How to use it
- Pick a preset or start empty, then type the sources for each directive.
- Read the warnings and fix what applies to your site.
- Copy the header into your web server or application config, or the meta tag into your page’s
<head>.
The directives
default-src: fallback for any fetch directive you do not set.script-src,style-src,img-src,connect-src,font-src,frame-src: where scripts, styles, images, fetch/XHR/WebSocket connections, fonts and frames may come from.frame-ancestors: who may embed your page in a frame. Header only.form-action: where forms may submit.base-uri: allowed values for<base>.object-src: plugins.upgrade-insecure-requests: asks the browser to load http resources over https.report-uriandreport-to: where violation reports are sent. Header only.
Example
The Strict preset gives default-src 'self'; script-src 'nonce-…' 'strict-dynamic'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'. Scripts need the nonce attribute and scripts they load are trusted by ‘strict-dynamic’.
Tips
- Test with Report-Only before enforcing.
- Avoid wildcards and whole-scheme sources in script-src.
- Hash a static inline script with SHA-256 and list it as
'sha256-…'instead of using unsafe-inline.