Security Headers Architect & Policy Generator
Configure, lint, and export hardened HTTP security headers. Includes contextual risk analysis, breaking change prevention, and copy-ready syntax for Cloudflare Pages, Nginx, Caddy, and Apache.
Policy Directives
Interactive BuilderHardened zero-trust baseline ideal for pre-rendered content sites with no external scripts.
Transport & Metadata Policies
Contextual Risk Assessment & Linter
Policy is in active enforcement mode.
Test initial CSP rules using Content-Security-Policy-Report-Only first to identify blocked assets without breaking user experience.
Generated Configuration
/*
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self'; frame-src 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()
Four-Stage Zero-Downtime CSP Rollout Protocol
Deploying a strict Content-Security-Policy in production without testing will break legitimate analytics, fonts, and customer payment widgets. Follow this proven four-phase procedure.
Telemetry Gathering
Ship Content-Security-Policy-Report-Only headers pointing to a collection endpoint. The browser executes all scripts normally while logging violations in background threads.
Third-Party Triage
Review log data over 14 days to capture rare cron triggers, payment gateways, and tag managers. Add necessary origins to script-src and connect-src directives.
Kill Unsafe-Inline
Replace dangerous 'unsafe-inline' declarations with cryptographic SHA-256 hashes for static script blocks or server-generated nonces for dynamic server rendering.
Active Enforcement
Switch the header name to Content-Security-Policy. Browsers now actively block injection attempts and untrusted script execution across your entire application.
Configuration Gotchas Across Web Servers
Different hosting platforms process header inheritance differently. Be aware of these server-specific behaviors before deploying configuration files.
| Platform | Configuration File | Critical Architecture Traps |
|---|---|---|
| Cloudflare Pages | public/_headers | Rules match line-by-line. Does not support regex wildcards or server-side environment variables. |
| Nginx | nginx.conf | Defining add_header inside a child location block cancels all add_header directives from parent blocks completely. |
| Caddy | Caddyfile | Caddy manages TLS and basic HSTS automatically. Avoid duplicate header declarations in custom directives. |
| Apache | .htaccess | Requires mod_headers enabled. Always use "Header always set" to ensure headers attach to error pages (such as 404 and 500). |
Frequently Asked Questions
Concise answers regarding HTTP security headers, policy testing, and safe production deployment.