Home/Tools/CSP Generator

CSP Generator

Generate Content Security Policy headers to prevent XSS attacks. Visual CSP builder with directive explanations and best practices.

Security Header Builder

Craft a hardened Content Security Policy and complementary response headers.

Launch Security Headers Analyzer

Quick Start Templates

🔒

Strict Policy

Maximum security for modern web applications

⚖️

Moderate Policy

Balance between security and compatibility

⚠️ Less secure than strict policy due to 'unsafe-inline'

📦

Legacy Compatible

Maximum compatibility for older websites

⚠️ Less secure - migrate to stricter policy over time

📊

Report-Only Mode

Monitor violations without blocking

Build Your Policy

📥 Fetch Directives (Resource Loading)

Fallback for all fetch directives

'self'

JavaScript sources

CSS sources

Image sources

Font sources

AJAX, WebSocket, EventSource

Audio & video sources

Plugins: <object>, <embed>, <applet>

Iframe sources

Web workers & nested contexts

Web app manifest

Web workers

📄 Document Directives

Restrict <base> tag URLs

Enable sandbox restrictions

🧭 Navigation Directives

Form submission targets

Embedding in iframes

Navigation targets

⚠️ Limited browser support

📊 Reporting Directives

Violation report endpoint

Reporting API group

⚙️ Other Directives

Automatically upgrades HTTP to HTTPS

Block HTTP on HTTPS

Trusted Types API

Trusted Types policy names

Validation & Security Grade

1

Passes

5

Warnings

0

Errors

F

Security Grade

Valid CSP syntax

⚠️ object-src not configured

Set object-src to 'none' to disable plugins

⚠️ base-uri not configured

Set base-uri to 'self' to prevent base tag injection

⚠️ form-action not configured

Set form-action to 'self' to prevent form hijacking

⚠️ frame-ancestors not configured

Set frame-ancestors to prevent clickjacking

⚠️ No reporting configured

Add report-uri or report-to to monitor violations

Browser Compatibility

Chrome 90+

✓ Full support

Firefox 89+

✓ Full support

Safari 14+

No report-to support

⚠ Partial

Edge 90+

✓ Full support

IE 11 11

CSP 1.0 only, no Level 2/3 features

⚠ Partial

Generated Policy

Content-Security-Policy: default-src 'self';
Permissions-Policy: accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), notifications=(), payment=()
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Resource-Policy: same-origin
X-Permitted-Cross-Domain-Policies: none

Need Help Implementing Web Security?

Our security team can audit your web application, implement CSP and other security headers, and protect against XSS and injection attacks.

Understanding CSP Directives

Content Security Policy uses directives to control which resources can be loaded and executed.

Common Directives

  • default-src: Fallback for all resource types
  • script-src: JavaScript sources
  • style-src: CSS stylesheets
  • img-src: Image sources
  • connect-src: AJAX, WebSocket, fetch
  • font-src: Web fonts
  • frame-src: Iframe sources

Common Source Values

  • 'self': Same origin only
  • 'none': Block all sources
  • 'unsafe-inline': Allow inline code (avoid)
  • 'unsafe-eval': Allow eval() (avoid)
  • https: Any HTTPS source
  • domain.com: Specific domain

Frequently Asked Questions

Common questions about the CSP Generator

Content Security Policy (CSP) is a browser security feature that helps prevent Cross-Site Scripting (XSS), clickjacking, and other code injection attacks. It works by defining which sources of content the browser should consider valid for loading scripts, styles, images, and other resources.

⚠️ Security Notice

This tool is provided for educational and authorized security testing purposes only. Always ensure you have proper authorization before testing any systems or networks you do not own. Unauthorized access or security testing may be illegal in your jurisdiction. All processing happens client-side in your browser - no data is sent to our servers.