Guide

THE TOOLBOX / WEB SECURITY & INFRASTRUCTURE

Build & audit strict
CSP security headers.

Compose W3C Content-Security-Policy Level 3 directives, audit existing headers for XSS bypasses, and export production configs for Next.js, Nginx, Apache, and Cloudflare.

  • [GOOD · default-src] Fallback policy is locked down to 'self'.
  • [GOOD · object-src] Legacy plugin execution is blocked via object-src 'none'.
  • [GOOD · base-uri] Base tag hijacking is prevented via base-uri 'self'.
  • [GOOD · frame-ancestors] Clickjacking framing is restricted via frame-ancestors 'none'.
●   W3C CSP3 static auditor
SERVER CONFIG EXPORTGrade A+ · 100/100

CSP Security Score: 100/100 (Grade A+). Exported for NEXTJS.

default-src'self'script-src'self' 'nonce-2726c7f26c' 'strict-dynamic'style-src'self'img-src'self' data:connect-src'self'font-src'self'object-src'none'base-uri'self'frame-ancestors'none'form-action'self'upgrade-insecure-requests(flag)

THE DETAILS

W3C Content Security Policy Level 3 directives, XSS mitigation, and companion HTTP security headers.

1. Defense-in-Depth Against XSS

A properly configured Content-Security-Policy response header restricts where scripts, styles, images, fonts, and fetch requests can be loaded from—and blocks unauthorized inline script execution, eval(), and clickjacking frames.

2. Automated Security Grader (A+ to F)

Paste any raw CSP header string or edit directives visually to run an instant static audit. The analyzer checks for dangerous 'unsafe-eval' and 'unsafe-inline' tokens, overly broad * or data: script sources, missing object-src 'none' or base-uri 'self' guards, and unquoted keyword typos.

3. Companion HTTP Hardening Headers

Pair your CSP with Strict-Transport-Security (HSTS 2-year preload), X-Content-Type-Options: nosniff (blocking MIME-sniffing attacks), Referrer-Policy: strict-origin-when-cross-origin, and Permissions-Policy hardware feature locks.

4. Multi-Platform Server Config Transpiler

Switch between Raw HTTP Header, Next.js (`next.config.ts`), Nginx (`add_header`), Cloudflare Pages (`_headers`), Vercel (`vercel.json`), Apache (`.htaccess`), and HTML `<meta>` output tabs. Inspecting TLS certificates or escaping untrusted HTML? Use the X.509 Certificate Decoder or HTML Entity Encoder.

CSP Directives & HTTP Security Headers Matrix

Directive / HeaderRecommended Strict ValueAttack Vector Mitigated
default-src'self' or 'none'Fallback restriction for all unconfigured fetch directives
script-src'self' 'nonce-...' 'strict-dynamic'Cross-Site Scripting (XSS) & unauthorized third-party scripts
object-src / base-uri'none' / 'self'Plugin execution & injected <base href> relative URL hijacking
frame-ancestors'none' or 'self'Clickjacking / UI redressing via malicious <iframe>
Strict-Transport-Securitymax-age=63072000; includeSubDomains; preloadSSL stripping & protocol downgrade attacks (RFC 6797)

Common CSP Deployment Pitfalls & Troubleshooting

Missing Single Quotes Around Keywords

Writing script-src self instead of script-src 'self' causes browsers to treat self as a domain name. The auditor flags unquoted CSP keywords immediately.

Nginx add_header Inheritance Trap

In Nginx, adding an add_header directive inside a nested location block silently drops all add_header directives defined in the parent server block. Include security headers consistently or use an include snippet.

Directives Ignored in HTML <meta>

frame-ancestors, report-uri, and sandbox have no effect inside <meta http-equiv> tags. Our HTML Meta exporter automatically strips unsupported directives and adds a reminder comment.

Testing with Content-Security-Policy-Report-Only

When rolling out a strict CSP on a legacy application, deploy it first as Content-Security-Policy-Report-Only to monitor violation reports without breaking production scripts.

Frequently Asked Questions

Why does adding unsafe-inline to script-src defeat Content Security Policy XSS protection?

Cross-Site Scripting (XSS) overwhelmingly relies on injecting inline <script> blocks or inline event handlers (onload, onerror). Permitting 'unsafe-inline' in script-src without a cryptographic nonce or 'strict-dynamic' allows any injected script to execute freely. Use per-request nonces ('nonce-...') or SHA-256 script hashes instead.

Why did the auditor flag unquoted self or none as a critical error?

In W3C CSP syntax, keywords such as 'self', 'none', 'unsafe-inline', and 'strict-dynamic' must be wrapped in single quotes. Writing self without single quotes instructs the browser to permit resources from an external host literally named http://self/ rather than the current origin.

Why is frame-ancestors ignored inside an HTML <meta http-equiv="Content-Security-Policy"> tag?

Per the W3C Content Security Policy Level 3 specification, frame-ancestors, report-uri, and sandbox directives are not supported inside <meta> elements because framing decisions must be enforced before the HTML document body is parsed. Always deliver frame-ancestors via HTTP response headers (Nginx, Cloudflare, Vercel, or Next.js).

What is the difference between frame-ancestors and X-Frame-Options?

CSP frame-ancestors supersedes the legacy X-Frame-Options header. While X-Frame-Options only supports DENY or SAMEORIGIN in modern browsers, frame-ancestors 'self' https://trusted.partner.com supports multiple explicit parent origins and wildcard subdomains.

Does this CSP analyzer connect to my server or log my security policy?

No. All CSP directive parsing, security scoring, and Nginx/Next.js/Cloudflare config generation run 100% locally in your browser with zero external requests.