CSP Directives Cheatsheet 2026

Updated April 2026

Quick Answer CSP directives control which resources a page can load. default-src is the fallback for all. script-src controls JavaScript. style-src controls CSS. connect-src controls fetch/XHR. frame-ancestors replaces X-Frame-Options. Source values: 'self' = same origin, 'none' = block all, 'nonce-VALUE' = specific inline script.

Every Content Security Policy directive in one place — what it controls, valid source values, and examples. Updated for CSP Level 3.

Quick reference — fetch directives

DirectiveControlsFalls back to
default-srcFallback for all fetch directives not listed
script-srcJavaScript files and inline scriptsdefault-src
style-srcCSS files and inline stylesdefault-src
img-srcImages (src attribute, CSS background-image)default-src
font-srcFont files (woff, woff2, ttf)default-src
connect-srcfetch, XHR, WebSocket, EventSourcedefault-src
media-srcAudio and video elementsdefault-src
frame-srcFrames loaded by your page (iframes)child-src → default-src
child-srcWorkers and frames (legacy)default-src
worker-srcWeb Workers, Service Workerschild-src → default-src
object-srcFlash, Java plugins (object, embed)default-src
manifest-srcWeb app manifestsdefault-src

Document directives

DirectiveControls
base-uriURLs usable in <base> tag. Set to 'self' to prevent base tag injection
frame-ancestorsWho can embed your page in an iframe. Replaces X-Frame-Options
form-actionURLs forms can submit to
sandboxApplies iframe-like sandbox restrictions to the page

Other directives

DirectiveControls
upgrade-insecure-requestsRewrites HTTP to HTTPS for all subresource requests
report-toEndpoint for violation reports (modern, use with Reporting-Endpoints header)
report-uriURL for violation reports (deprecated, use for compatibility)
require-trusted-types-forRequires Trusted Types for DOM XSS sinks

Source values

ValueMeaning
'none'Block everything
'self'Same origin only
'unsafe-inline'Allow inline scripts/styles (defeats XSS protection)
'unsafe-eval'Allow eval() and similar (dangerous)
'strict-dynamic'Trust scripts loaded by already-trusted scripts (with nonce)
'nonce-VALUE'Allow specific inline script/style with matching nonce attribute
'sha256-HASH'Allow inline script/style matching this hash
https:Any HTTPS source
data:data: URIs (base64 images, etc)
blob:Blob URLs
https://example.comSpecific origin
*.example.comAll subdomains of example.com

Minimal secure CSP

Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self';

Report-only mode (deploy first)

# Use this header name to log violations without blocking anything
Content-Security-Policy-Report-Only: default-src 'self'; report-to csp-endpoint

Common third-party additions

# Google Analytics 4
script-src 'self' https://www.googletagmanager.com;
connect-src 'self' https://www.google-analytics.com;

# Google Fonts
style-src 'self' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com;

# Stripe
script-src 'self' https://js.stripe.com;
connect-src 'self' https://api.stripe.com;
frame-src 'self' https://js.stripe.com;
Generate CSP from your live page → CSPFixer Build CSP from scratch → CSP Generator