ToolPal

CSP Generator

Generate Content Security Policy (CSP) headers for your website. Configure directives with preset security levels, add custom sources, and copy the complete header value.

Security Presets

default-src

Fallback for other directives

script-src

JavaScript sources

style-src

Stylesheet sources

img-src

Image sources

font-src

Font sources

connect-src

AJAX, WebSocket, fetch

frame-src

Iframe sources

object-src

Plugin sources

media-src

Audio/video sources

worker-src

Web Worker sources

Extra Options

Generated CSP Header

Content-Security-Policy:
default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-src 'none'; object-src 'none'

What is CSP?

Content Security Policy is an HTTP response header that helps prevent XSS and data injection attacks. Add it as a response header: Content-Security-Policy: [value]

How to Use

Generate Content Security Policy (CSP) headers for your website. Configure directives with preset security levels, add custom sources, and copy the complete header value.

  1. 1Choose a security preset — Strict, Moderate, or Open — based on your site's needs. Strict blocks nearly everything except your own domain; Moderate is good for most sites; Open allows more third-party resources.
  2. 2Configure directives by clicking the source chips to toggle them on/off. Add custom domains using the text input — useful for CDNs, analytics services, and payment processors.
  3. 3Enable extra options: upgrade-insecure-requests to automatically upgrade HTTP to HTTPS, and block-all-mixed-content to block HTTP resources on HTTPS pages. Add a report-uri to collect CSP violations.
  4. 4Click Copy to get the CSP value. Add it to your server as the Content-Security-Policy response header. Test in report-only mode first using Content-Security-Policy-Report-Only.

Key Features

  • Visual directive builder — toggle sources with clickable chips instead of typing raw strings
  • Security level presets — Strict, Moderate, and Open presets based on real-world security recommendations
  • Custom source support — add any domain, URL pattern, or CSP keyword for CDNs, fonts, and analytics
  • Extra security directives — one-click toggles for upgrade-insecure-requests, block-all-mixed-content, and report-uri

Frequently Asked Questions

Learn More