What is CSP Starter Policy Generator for Static Sites?
Content-Security-Policy (CSP) is a browser security header that controls which resources a page is allowed to load. It helps prevent cross-site scripting, data injection, and other code injection attacks. For static sites, a CSP header can be simple and conservative because most static pages load resources from predictable, controlled origins.
Quick answer
A Content Security Policy blocks cross-site scripting and data injection attacks by restricting which resources the browser can load. Start with a restrictive policy and widen only when needed.
Limitations
- CSP does not protect against server-side vulnerabilities or compromised third-party libraries already included in the policy.
- Inline event handlers and javascript: URLs are blocked unless 'unsafe-inline' or a hash/nonce is set.
- GitHub Pages does not support custom HTTP headers; use a meta tag-based CSP instead, which has limited directive support compared to the HTTP header.
How to use this tool
- Pick a preset that matches your site type: static, with CDN, with analytics, or with embedded content.
- Review the generated directives and toggle additional sources your site needs.
- Copy the CSP header into your hosting configuration or as a meta tag.
- Deploy the report-only version first and check the browser console for violations before enforcing.
What you can use it for
- Create a conservative CSP for a plain HTML static site with no external resources.
- Add script and font sources for Google Fonts, Bootstrap CDN, or Google Analytics.
- Prepare a CSP for GitHub Pages that accounts for the hosting origin.