Content Security Policy Directives

Technical reference for content security policy directives

Content-Security-Policy directives define the categories of content and behaviors that a policy can restrict on a page.

A Strict CSP focuses on the three high-impact XSS mitigation directives (script-src, object-src, and base-uri) plus reporting (report-uri / report-to). Other fetch directives (style-src, img-src, font-src, connect-src, etc.) are optional defense-in-depth controls and were historically used in allowlist-based policies.

Core Strict CSP Directives

Security Criticality (How important it is to configure the directive properly for XSS protection)
High
Core Strict CSP directive — required for strong XSS protection
Medium
Optional defense-in-depth / legacy allowlist directive
Low
Optional hardening / legacy allowlist directive
Directive Example Value Description
script-src 'nonce-random123' 'strict-dynamic' 'report-sample' Defines which JavaScript is allowed to load and execute.

This is the most important directive for XSS protection. With Strict CSP, use a per-request nonce (or SHA-256 hash) with 'strict-dynamic' rather than a domain allowlist.
object-src 'none' Defines where the website is allowed to load and execute plugins/objects from (<object>, <embed>, <applet>).

Should almost always be set to 'none'.
base-uri 'none' Restricts the URLs that can appear in a page's <base> element, preventing attackers from hijacking relative script URLs. Set to 'none' (or 'self' if your app uses <base>).

Optional / Legacy Allowlist Fetch Directives

These directives are not required for a Strict CSP to prevent XSS, but can be added for additional defense-in-depth or when maintaining a legacy allowlist policy.

Directive Example Value Description
style-src 'self' 'nonce-random123' Defines where the website is allowed to load and apply CSS stylesheets from.
connect-src 'self' Defines where the website is allowed to make fetch/XHR, WebSocket, and EventSource requests.
frame-src / child-src 'self' Defines where the website is allowed to point iframes. child-src also acts as a fallback for worker-src.
font-src 'self' https://fonts.gstatic.com Defines where the website is allowed to load and apply fonts from.
img-src data: 'self' https: Defines where the website is allowed to load and display images from.
media-src 'self' Defines where the website is allowed to load and play <audio> and <video> sources from.

Reporting and Other Directives

Directive Example Value Description
report-to csp-endpoint Modern CSP3 reporting directive that sends JSON violation reports to the endpoint named in the Reporting-Endpoints HTTP header. Recommended alongside report-uri for full browser support.
report-uri https://exampleendpoint.endpoint.csper.io/?v=1 Defines a URL where the browser sends CSP violation reports. Pair with report-to so both older and newer browsers deliver reports to Csper.
frame-ancestors 'none' Defines which origins are allowed to embed this page in an iframe. Prevents Clickjacking / UI Redressing and supersedes the X-Frame-Options header.
form-action 'self' Defines the URLs that the webpage is allowed to submit HTML forms to.
upgrade-insecure-requests (no value) Instructs the browser to automatically upgrade all http:// subresource requests to https://.
sandbox allow-forms allow-same-origin allow-scripts Applies iframe-style sandbox restrictions to the top-level page.
plugin-types (Deprecated) application/pdf Deprecated directive that previously restricted plugin MIME types. Use object-src 'none' instead.