Loading tool...
Generate Subresource Integrity (SRI) hashes for scripts and stylesheets. Protect against CDN compromise and tampering
Complete HTTP status code reference with descriptions. Search all 1xx, 2xx, 3xx, 4xx, and 5xx status codes with explanations
Decode and analyze PEM-encoded X.509 SSL/TLS certificates. View subject, issuer, validity, extensions, and fingerprints
Build Content Security Policy (CSP) headers visually without complex syntax using an intuitive interface that generates ready-to-use policies for web servers and applications. Content Security Policy is a critical security header that protects websites from Cross-Site Scripting (XSS), clickjacking, code injection, and other attacks by controlling which content sources browsers trust. This tool provides visual policy building with toggle switches for 15+ CSP directives, quick presets for common security levels (Strict, Moderate, Permissive), and suggestions for common source values ('self', 'https:', 'data:', specific domains). Build policies visually without memorizing CSP syntax—the tool generates proper directives and formats. Export policies in multiple formats: HTTP headers for nginx and Apache, meta tags for HTML, and CSP report formats. Real-time policy preview shows the generated directives as you adjust settings. Test policies in browser console to verify correct behavior before deploying, with violations logged for debugging.
Configure CSP to block inline scripts and restrict script sources, preventing Cross-Site Scripting attacks.
Add CSP headers to web servers as part of comprehensive browser security header configuration.
Control which sources images, scripts, styles, and other resources can be loaded from.
Use frame-ancestors directive to prevent your site from being embedded in malicious iframes.
Gradually deploy strict CSP policies, starting with report-only mode to identify issues before enforcement.
Test CSP configuration thoroughly in development to ensure legitimate functionality while blocking attacks.
Content Security Policy (CSP) is a W3C security standard, first introduced in 2012 (CSP Level 1) and refined through CSP Level 2 (2016) and CSP Level 3 (current), that provides a declarative mechanism for web applications to specify which content sources the browser should trust. CSP is primarily designed to mitigate Cross-Site Scripting (XSS), the most prevalent class of web security vulnerability, by establishing a whitelist of approved content sources that the browser enforces, blocking any resources or scripts that originate from unapproved sources.
CSP directives form the building blocks of a policy, each controlling a specific type of resource. The default-src directive sets the fallback policy for all resource types not explicitly specified. The script-src directive controls which scripts can execute, and is the most critical for XSS prevention. The style-src directive governs CSS sources, img-src controls image loading, connect-src restricts AJAX and WebSocket connections, font-src manages font loading, and frame-src (or child-src) controls embedded iframes. The frame-ancestors directive, which replaces the X-Frame-Options header, specifies which sites can embed the current page in a frame, preventing clickjacking attacks. Each directive accepts source expressions including 'self' (same origin), 'none' (block all), specific domains, scheme-based sources (https:, data:), and hash or nonce values.
Nonce-based CSP policies represent the most secure approach for allowing inline scripts while maintaining strong XSS protection. A nonce (number used once) is a randomly generated value that the server includes in both the CSP header (script-src 'nonce-abc123') and the script tag (script nonce="abc123"). Because the nonce changes with every page load and must match exactly, an attacker who injects a script tag cannot predict the required nonce value, and the browser blocks execution. This approach is superior to 'unsafe-inline' (which defeats CSP's XSS protection entirely) and hash-based policies (which become unwieldy with many inline scripts). Google's strict CSP recommendation uses nonces combined with 'strict-dynamic', which automatically trusts scripts loaded by nonced scripts without needing to whitelist their origins.
Deploying CSP effectively requires a careful rollout strategy. The Content-Security-Policy-Report-Only header allows a policy to be tested without enforcement: violations are reported (to a URL specified by the report-to directive) but resources are not blocked. This enables teams to discover what a policy would break before it actually breaks it. Common deployment challenges include third-party scripts that load additional resources from unknown origins, inline event handlers (onclick, onload) that violate script-src policies, and dynamically generated CSS that conflicts with style-src restrictions. The report-uri and report-to directives send violation reports as JSON to a specified endpoint, providing visibility into what the policy blocks in production.
Content Security Policy is an HTTP header that tells browsers which sources of content to trust. It prevents XSS attacks by blocking inline scripts and unauthorized external resources.
Start with Strict for new projects and relax as needed. For existing sites, start with Permissive and tighten gradually while monitoring the browser console for blocked resources.
CSP blocks inline scripts by default. Either move scripts to external files and whitelist the source, or use nonces/hashes for inline scripts (not recommended).
All processing happens directly in your browser. Your files never leave your device and are never uploaded to any server.