CSP 生成器
为您的网站生成 Content Security Policy (CSP) 标头。使用安全级别预设配置指令,添加自定义来源,并复制完整的标头值。
安全预设
default-srcFallback for other directives
script-srcJavaScript sources
style-srcStylesheet sources
img-srcImage sources
font-srcFont sources
connect-srcAJAX, WebSocket, fetch
frame-srcIframe sources
object-srcPlugin sources
media-srcAudio/video sources
worker-srcWeb Worker sources
额外选项
生成的 CSP 标头
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'
什么是 CSP?
Content Security Policy 是一个 HTTP 响应标头,有助于防止 XSS 和数据注入攻击。以 Content-Security-Policy: [值] 的形式添加到响应标头中。
使用方法
为您的网站生成 Content Security Policy (CSP) 标头。使用安全级别预设配置指令,添加自定义来源,并复制完整的标头值。
- 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.
- 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.
- 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.
- 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.
主要功能
- 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