Security Headers Builder
站点场景 先选预设,再按实际资源微调
CSP 资源白名单 一行一个来源,留空即只允许本站
隔离与上报 跨源隔离、报告模式与旧浏览器兼容
Report-Only 不会拦截请求,适合灰度观察;跨源隔离启用后,第三方图片与脚本必须显式提供 CORP/CORS。
风险自检 按当前配置实时判断
部署配置 按服务器类型选择
上线前先在测试域名观察 CSP 报告,确认没有漏掉真实资源再收紧策略。
How to Use
📖 What it does
Security headers are more than one `X-Frame-Options` line. A Content-Security-Policy must name the sources for scripts, styles, images, fonts and API calls. HSTS depends on HTTPS and is hard to roll back once browsers cache it. `frame-ancestors` and `X-Frame-Options` overlap but do not mean the same thing. Permissions-Policy requires explicit decisions for camera, microphone and geolocation. Server syntax also differs: Nginx uses `add_header`, Apache uses `Header always set`, Next.js puts headers in `next.config.js`, and Cloudflare Pages reads a `_headers` file.
This generator turns those relationships into visible choices. Pick a preset for a static site, API, admin console or storefront, then enter allowed script, style, image and API origins. The CSP is assembled from `default-src`, `script-src`, `style-src`, `img-src`, `connect-src`, `frame-ancestors` and related directives. HSTS, Referrer-Policy, Permissions-Policy and Cross-Origin-Opener-Policy are generated together. The right column switches between four server formats and lets you copy or download the matching snippet.
Nothing is sent to a server, and no live response is inspected. Before production, test the policy on a staging domain, watch the CSP reports, and only then decide whether to move away from `unsafe-inline`.
✨ Features
- Five presets for static sites, APIs, admin consoles, storefronts and multi-tenant SaaS, each with its own CSP and isolation defaults.
- Visual CSP assembly for scripts, styles, images and API origins, with de-duplication and rejection of unknown values.
- Linked headers for HSTS, content-type sniffing, framing, referrer, permissions and COOP.
- Cross-origin isolation through CORP, COEP and Origin-Agent-Cluster for capabilities such as SharedArrayBuffer.
- Report-only rollout with a CSP report URL and Reporting-Endpoints, so policy can be observed before enforcement.
- Four deployment formats and an A–E grade: Nginx, Apache, Next.js and Cloudflare `_headers` share one policy.
🚀 How to use it
- Choose a preset and confirm the HSTS lifetime, framing policy, referrer policy and preload state.
- Fill the CSP allowlists for scripts, styles, images and API origins; do not rely on `unsafe-inline` in strict mode.
- In the isolation and reporting card, select CORP and COEP, then enable report-only mode and an HTTPS report URL if needed.
- Read the risk checks and grade, addressing `unsafe-inline`, plaintext origins, missing HSTS and preload preconditions.
- Pick Nginx, Apache, Next.js or Cloudflare output, copy or download it, and observe reports on a test host before production.
⚠️ Before you rely on it
- Observe CSP before enforcing it: a strict policy can block real scripts; collect reports in report-only mode, then switch to enforcement.
- HSTS is not a simple toggle: browsers remember `max-age`, so every subdomain needs a valid certificate before you shorten or remove it.
- Preload has prerequisites: the apex and all subdomains must serve HTTPS, the HSTS lifetime must cover at least one year, and `includeSubDomains` must be present.
- Unsafe-inline weakens CSP: compatibility mode is a migration aid, not a permanent setting; replace inline code with nonces or hashes where possible.
- Nginx add_header inherits in layers: a `server`-level header replaces the same header from `http`, so check every layer and path.
- Cross-origin isolation requires CORP or CORS on third-party assets; keep `X-Frame-Options` and `frame-ancestors` on the same policy.