Security & SEO · CSP

Content-Security-Policy (CSP) & Nginx Security Header Builder

Assemble clean HTTP security headers (`Content-Security-Policy`, `nosniff`, `Referrer-Policy`, `Permissions-Policy`) ready to drop straight into your Nginx vhost block.

✓ 100% Browser-Local · Zero Upload Reviewed: 2026-11-26

Initializing local browser workspace...

Harden Static Sites and Nginx VPS Hosts Against XSS & Clickjacking

A misconfigured Content-Security-Policy either leaves your site open to script injection or accidentally blocks Google Fonts, GA4, and AdSense ads overnight. Building explicit directives with tested presets lets you roll out hardened Nginx headers cleanly.

  • Visual directive editors for default-src, script-src, style-src, font-src, img-src, and frame-ancestors
  • One-click presets for Strict Static Sites and Monetized Sites (Google Analytics GA4 + AdSense)
  • Outputs ready-to-paste Nginx add_header blocks alongside raw HTTP header values
  • Automatically pairs CSP with X-Content-Type-Options, Referrer-Policy, and Permissions-Policy
  • Includes frame-ancestors 'none' clickjacking defense replacing legacy X-Frame-Options
  • 100% local generation without exposing internal origin domains

Step-by-Step Guide

  1. Start from Strict Static Site (pure self-hosted assets) or Static + GA4 + AdSense if running Google Fonts, Analytics, or AdSense.
  2. Customize individual directives such as img-src (keep data: and blob: enabled if running local Canvas/QR tools) and font-src.
  3. Inspect both the Nginx server block snippet and raw HTTP header output below.
  4. Click Copy Nginx Headers, paste into your vhost server block, and run nginx -t before reloading.

Common CSP Deployment Gotchas

Forgetting blob: and data: in img-src for Client-Side Tools

Local Canvas image compressors, SVG previews, and QR downloads rely on data: and blob: URLs. Omitting them from img-src silently breaks client-side media previews.

Deploying Enforcing CSP Without Testing Report-Only First

On complex sites with third-party ad scripts, test new headers first with Content-Security-Policy-Report-Only and watch Chrome DevTools Console for blocked hosts before enforcing.

Missing 'always' Flag in Nginx add_header Directives

Without the trailing always parameter, Nginx omits security headers on 404 and 5xx error responses. Our generated Nginx block includes always automatically.

VPS Hardening & Web Security Audits

  • Improving Mozilla Observatory and SecurityHeaders.com scores on self-hosted BT Panel Nginx static sites.
  • Preventing clickjacking and unauthorized iframe embedding using frame-ancestors 'none'.
  • Allowlisting Google Fonts, GA4, and AdSense hosts cleanly without opening wildcard script-src *.

Frequently Asked Questions

Why does Nginx require nginx -t after adding a CSP header?

Single or double quote mismatches inside add_header break Nginx configuration parsing. Running nginx -t verifies syntax safely before nginx -s reload applies changes.

Does CSP replace HTML escaping against XSS?

No—CSP is defense-in-depth. Always escape untrusted input in code AND enforce CSP headers to limit blast radius if a bug occurs.

What does frame-ancestors 'none' do?

It instructs modern browsers never to allow third-party sites to embed your pages inside an <iframe>, stopping clickjacking attacks cleanly.

Local Privacy Guarantee: Security header construction executes 100% client-side with zero logging of your domains or policies.