Home

Content Security Policy (CSP Level 3) Policy Builder

Visually build, audit, and validate strict Content-Security-Policy (CSP) headers with nonce/hash support, script-src, frame-ancestors, and server export.

Fallback & Defaults

Default fallback for all fetch directives if not explicitly defined.

Standard Keywords:Click to toggle
Configured Values:
'none'
Navigation & Form Control

Restricts valid URLs for the document <base> element to prevent hijacking.

Standard Keywords:Click to toggle
Configured Values:
'none'
Navigation & Form Control

Restricts valid endpoints for HTML form submissions.

Standard Keywords:Click to toggle
Configured Values:
'self'
Framing & Plugins

Restricts valid sources for <object>, <embed>, and plugin applets.

Standard Keywords:Click to toggle
Configured Values:
'none'
JavaScript & XSS Defenses

Restricts valid sources for JavaScript execution and web workers.

Standard Keywords:Click to toggle
Popular Providers & Origins:
Configured Values:
'nonce-r4nd0mStr1ng''strict-dynamic'https:'unsafe-inline'
JavaScript & XSS Defenses

Applies specifically to <script> elements and script tags.

JavaScript & XSS Defenses

Applies specifically to inline event handlers (onclick, onload).

Stylesheets & CSS Injection

Restricts valid sources for stylesheets and CSS @import declarations.

Standard Keywords:Click to toggle
Popular Providers & Origins:
Configured Values:
'self''unsafe-inline'
Stylesheets & CSS Injection

Applies specifically to <style> tags and rel="stylesheet" links.

Stylesheets & CSS Injection

Applies specifically to inline style="" HTML attributes.

Images & Media Assets

Restricts valid sources of images, SVGs, and favicons.

Standard Keywords:Click to toggle
Popular Providers & Origins:
Configured Values:
'self'https:data:
Images & Media Assets

Restricts valid sources for fonts loaded via @font-face.

Standard Keywords:Click to toggle
Popular Providers & Origins:
Configured Values:
'self'data:
Images & Media Assets

Restricts valid sources for <audio>, <video>, and media streams.

Network & API Endpoints

Restricts endpoints for fetch(), XMLHttpRequest, WebSocket, and EventSource.

Standard Keywords:Click to toggle
Popular Providers & Origins:
Configured Values:
'self'
Network & API Endpoints

Restricts valid worker script origins (Worker, SharedWorker, ServiceWorker).

Network & API Endpoints

Restricts valid sources for Web App Manifest (manifest.json) files.

Framing & Plugins

Restricts valid URLs for <iframe> and <frame> embedded contexts.

Framing & Plugins

Controls which external parents can embed this page (Clickjacking defense).

Standard Keywords:Click to toggle
Configured Values:
'none'
Security Flags & ReportingBoolean Flag

Directs browsers to automatically upgrade HTTP URLs to HTTPS.

Security Flags & ReportingBoolean Flag

Deprecated CSP2 flag that blocks mixed HTTP content over HTTPS.

Security Flags & Reporting

Legacy endpoint URI to receive violation report JSON payloads.

Security Flags & Reporting

Modern W3C Reporting API endpoint group for violation logs.

Compiled CSP Header

Enforcing
Header: Content-Security-Policy
Security Health Forecast:Grade F (72/100)

Switch to the Security Evaluator tab to inspect full XSS injection vectors, base-tag hijacking checks, and remediation guidance.

Google Recommended Strict CSP

  • Always set object-src 'none' to prevent plugin-based script execution.
  • Always set base-uri 'none' or 'self' to block relative script hijacking.
  • Avoid domain whitelists for scripts; prefer 'nonce-...' 'strict-dynamic'.
  • Never add 'unsafe-inline' without an accompanying nonce or hash.

CSP Level 3 Specification Compliance

Supports modern W3C directives including script-src-elem, strict-dynamic, trusted-types, and frame-ancestors.

XSS & Data Injection Mitigation

Restricts executable script sources to cryptographic nonces or SHA hashes, eliminating unsafe-inline script vulnerabilities.

Zero-Downtime Server Export Snippets

Generates tested header injection snippets for Nginx, Apache httpd, Caddy, Cloudflare Workers, and Next.js headers config.

Technical Reference & Architecture Guide

Csp Policy Builder Developer Reference

Developer utility for csp-policy-builder.

Csp Policy Builder Developer Reference — Client-Side In-Memory Architecture & Data Flow
Csp Policy Builder Developer Reference — Client-Side In-Memory Architecture & Data Flow

Key Parameters & Controls

Key Parameters & Controls
ParameterType / UnitDescriptionDefault
directivestringThe CSP directive token defining the policy boundary for a specific resource type, such as default-src, script-src, or frame-ancestors."default-src"
sourceListstring[]Array of authorized source expressions, including host origins, protocol schemes, cryptographic nonces, or reserved keywords.["'self'"]
isFlagbooleanIndicates standalone boolean directive flags that take no source arguments, such as upgrade-insecure-requests.false
initialMode"builder" | "evaluator"Workspace operational mode toggling between interactive visual directive assembly and raw policy AST parsing with audit scoring."builder"

Pro Tips & Best Practices

Enforce Nonce-Based Strict CSP

Pair 'strict-dynamic' with random cryptographic nonces on script-src to allow dynamically loaded trusted scripts while deprecating brittle domain allowlists.

Stage via Report-Only Headers

Deploy updates first with Content-Security-Policy-Report-Only and a valid report-to endpoint to monitor policy violations without breaking live production assets.

Lock Framing with Frame-Ancestors

Replace obsolete X-Frame-Options headers with frame-ancestors 'none' or explicit origins, as default-src does not govern framing permissions.

Common Gotchas & Troubleshooting

⚠️Missing single quotes around CSP keywords

Wrap reserved tokens like 'self', 'none', 'unsafe-inline', and 'unsafe-eval' in single quotes. Without quotes, browsers interpret them as hostnames and attempt DNS lookups.

⚠️Directives not falling back to default-src

Explicitly declare form-action, frame-ancestors, and base-uri. The W3C CSP Level 3 specification excludes navigation and framing directives from default-src fallback.

⚠️Meta tag ignoring frame-ancestors directive

Serve framing, sandbox, and reporting directives exclusively via HTTP response headers. Browsers discard frame-ancestors and report-uri when declared in HTML meta tags.

Frequently Asked Questions

Why are frame-ancestors and report-uri ignored in HTML meta tags?▼

W3C CSP Level 3 specifications explicitly disallow framing and reporting directives inside HTML meta elements because framing boundaries and violation endpoints must be registered prior to document parsing.

Does Content Security Policy degrade DOM parsing or network latency?▼

Parsing an HTTP CSP header adds negligible sub-millisecond CPU overhead during document initialization. However, excessively long header strings exceeding MTU sizes can trigger extra TCP packets, so avoid bloated domain lists.

How does 'strict-dynamic' interact with existing domain allowlists?▼

In CSP Level 3 compliant browsers, specifying 'strict-dynamic' alongside a valid nonce or hash causes the engine to ignore domain allowlists and 'unsafe-inline', maintaining backward compatibility for older CSP Level 2 engines.

Are generated CSP policies evaluated locally or sent to external servers?▼

All AST parsing, syntax validation, and security auditing occur entirely client-side in the browser using Web APIs. No policy fragments, hostnames, or internal architecture details are transmitted over the network.