CSP Generator - Free Online SEO Tool

Content Security Policy Generator

Pick a preset, toggle the sources you trust, and copy a ready-to-paste CSP header.

1. Choose a starting preset

2. Configure directives

default-src

Fallback for any directive you don't override.

Quick tokens:
script-src

Where JavaScript can load from.

Quick tokens:
style-src

Where stylesheets can load from.

Quick tokens:
img-src

Where images can load from.

Quick tokens:
font-src

Where web fonts can load from.

Quick tokens:
connect-src

fetch / XHR / WebSocket / EventSource endpoints.

Quick tokens:
frame-src

Where iframes can load from.

Quick tokens:
media-src

audio and video sources.

Quick tokens:
object-src

object, embed, applet sources.

Quick tokens:
form-action

Where forms can submit to.

Quick tokens:
base-uri

Restricts the <base href> value.

Quick tokens:
frame-ancestors

Who is allowed to embed your site in a frame.

Quick tokens:

3. Copy your policy


                        
                        
                        
                    
Tip: 'self' = your own domain. 'none' = block everything for that directive. 'unsafe-inline' weakens XSS protection — avoid if possible.

The Content Security Policy Generator is an interactive tool that helps you build robust CSP headers to protect your website from XSS attacks and other security vulnerabilities. This free CSP builder provides an intuitive interface for creating custom Content Security Policy headers with ready-to-use code for Apache, Nginx, and HTML meta tag implementation.

How to Use the CSP Generator

Select the content sources you want to allow for scripts, styles, images, fonts, and other resources using the interactive interface. The tool automatically generates the corresponding Content-Security-Policy header syntax. You can choose between enforcement mode or report-only mode, and the generator provides implementation code for different server configurations and HTML meta tags.

Key Features of the CSP Builder

  • Interactive policy builder with visual controls
  • Support for all CSP directives and sources
  • Ready-to-use code for Apache, Nginx, and meta tags
  • Report-only mode for safe testing
  • Nonce and hash support for inline content
  • Real-time policy validation and syntax checking

CSP Implementation Best Practices

Start with a Content-Security-Policy-Report-Only header to monitor violations without blocking content. Avoid 'unsafe-inline' and 'unsafe-eval' directives whenever possible, using nonces or hashes instead for legitimate inline scripts. Regularly review CSP violation reports to identify and fix policy issues. Test thoroughly in staging environments before deploying strict policies to production.

This CSP generator tool simplifies the complex process of creating Content Security Policies, making advanced XSS protection accessible to developers and website owners. A well-configured CSP is one of the most effective defenses against cross-site scripting attacks and unauthorized content injection.

Frequently Asked Questions

Recommended

Your IP Address is Exposed!

Hide your real IP and encrypt your connection with NordVPN.

Hide Your IP Encryption 6,400+ Servers
Protect My IP Now