Content Security Policy Sources

Technical reference of content security policy sources

Sources specify which scripts or resources are allowed to be executed. In a Strict CSP, 'nonce-...', 'strict-dynamic', 'report-sample', and 'none' are all sources:

Source Types

Source Examples Description
Nonce Source 'nonce-random123' The recommended source for Strict CSP on dynamic sites. The server generates a fresh, cryptographically random nonce per request (16 bytes) and adds it to both the header and allowed script tags: <script nonce="random123" src="/main.js"></script>.
Hash Source 'sha256-abc123...' Recommended for static or CDN-cached pages where per-request nonces aren't possible. The browser hashes an inline script block and allows it if it matches the sha256-, sha384-, or sha512- digest in the policy. Collisions are unlikely so sha256 is most likely fine.
Host Source https://example.com/something.js
example.com
example.com:1337
*.example.com
Matches resources loaded from a specific host or path. Historically used for allowlist-based script-src, though ignored by modern browsers when 'strict-dynamic' is present. Still useful for secondary directives like frame-ancestors or connect-src.
Scheme Source https:
wss:
data:
Matches anything with the specified scheme (for example, https: as a legacy-browser fallback alongside 'strict-dynamic', or data: in img-src).

Keyword Sources

Source Description
'strict-dynamic' Propagates trust from scripts explicitly allowed via a nonce or hash to any additional scripts they dynamically load. It also instructs modern browsers to ignore host allowlists and 'unsafe-inline'.
'none' Don't allow anything for this directive to be loaded (commonly used with object-src 'none' and base-uri 'none').
'report-sample' When the browser generates a violation report for report-uri or report-to, it includes the first 40 characters of the violating inline payload.
'self' Matches resources from the same origin the policy was delivered from. Useful for directives like base-uri 'self', frame-ancestors 'self', or legacy allowlist policies.
'unsafe-inline' Allows arbitrary inline scripts or styles. For script-src without a nonce or hash, this defeats XSS protection (No More Unsafe Inline). Note: when paired with a nonce/hash and 'strict-dynamic', modern browsers ignore 'unsafe-inline' and only legacy browsers fall back to it.
'unsafe-eval' Allows the usage of eval(), new Function(), and setTimeout/setInterval with string arguments. Should be avoided whenever possible.

Reference

Content Security Policy Directives

Technical reference for content security policy directives

Why It's Bad to Use 'unsafe-inline' in script-src

Why 'unsafe-inline' negates the primary benefit of content-security-policy, and ways to avoid using 'unsafe-inline'

Other Security Features of Content Security Policy

Other security features of content security policy including upgrade-insecure-requests, block-all-mixed-content, frame-ancestors, sandbox, form-actions, and more