CSP Header Generator

Build Content Security Policy headers visually with presets, directives, and source customization.

  1. Home
  2. Hash & Security
  3. CSP Header Generator
Presets:

Fallback for all directives

Allowed script sources

Allowed stylesheet sources

Allowed image sources

Allowed font sources

Allowed API/WebSocket origins

Allowed frame/iframe sources

Allowed audio/video sources

Allowed <object>/<embed>/<applet>

Allowed Worker/ServiceWorker

Allowed manifest sources

Allowed <base> tag URIs

Allowed form submission targets

Allowed parent frames (clickjacking)

Block mixed HTTP content on HTTPS pages

Automatically upgrade HTTP to HTTPS


Content-Security-Policy Header

What Is a CSP Header Generator?

Content Security Policy (CSP) is an HTTP security header that helps prevent cross-site scripting (XSS), clickjacking, and other code injection attacks by controlling which resources the browser is allowed to load for a given page. A CSP Header Generator helps you build these policies visually without manually writing the header syntax.

CSP works by defining a set of directives that specify allowed sources for different resource types — scripts, styles, images, fonts, and more. When a page violates the policy, the browser either blocks the resource (enforce mode) or sends a report (report-only mode). Common use cases include securing web applications against XSS attacks, preventing clickjacking via frame-ancestors, enforcing HTTPS with upgrade-insecure-requests, and restricting plugin content with object-src 'none'.

How to Use This CSP Header Generator

  1. Choose a preset — Select from Strict, Moderate, or Permissive presets to get started quickly, or configure each directive manually.
  2. Enable directives — Check the directives you want (e.g., script-src, style-src, img-src) and enter the allowed sources.
  3. Configure sources — Enter source expressions like 'self', https://example.com, 'unsafe-inline', or 'nonce-abc123'.
  4. Copy the header — The generated CSP header appears in the output area. Click Copy to copy it to your clipboard and add it to your server configuration.

Frequently Asked Questions

What CSP preset should I use?

Strict: Maximum security. Blocks all inline scripts/styles, requires nonces or hashes. Best for applications with full CSP support.
Moderate: Balanced security. Allows 'unsafe-inline' styles but blocks inline scripts. Good for most websites.
Permissive: Minimal security. Widest compatibility with existing sites. Use as a starting point to tighten gradually.

What is the difference between 'self' and 'none'?

'self' allows resources from the same origin (same protocol, host, and port). 'none' blocks all sources for that directive. Use 'none' for directives like object-src to completely disable plugin content.

Is this tool generating a policy or validating one?

This tool generates CSP headers based on your selections. For testing and validation of existing policies, use the Security Headers Checker tool or browser developer tools.

Last updated: 9 Jul 2026