About this tool
A handful of response headers block whole classes of attacks: HSTS stops HTTPS downgrades, a Content-Security-Policy limits the damage of cross-site scripting, nosniff stops content-type confusion, and frame protection stops clickjacking. This generator builds a sensible set and outputs it in the exact syntax for your server or host, along with optional CORS and caching headers.
What each header does
- Strict-Transport-Security: browsers use HTTPS only, for
max-ageseconds. Start short while testing; preloading is hard to undo. - Content-Security-Policy: where scripts, styles, images and connections may come from. Begin with Report-only, fix what it flags, then enforce.
- X-Content-Type-Options: nosniff: browsers trust your Content-Type instead of guessing.
- Referrer-Policy: how much of your URLs other sites see.
strict-origin-when-cross-originis the modern default. - X-Frame-Options / frame-ancestors: stops other sites embedding your pages to trick users into clicks.
- Permissions-Policy: turns off powerful features (camera, microphone, location) you don’t use.
Before you deploy
- Test the CSP in report-only mode; a strict policy will break inline scripts and third-party widgets until you allow them.
- Never combine
Access-Control-Allow-Origin: *with credentials; browsers reject it. - Check the result with the HTTP Header Parser: paste the output of
curl -sI https://yoursite.com.
FAQ
Which security headers should every site have?
Strict-Transport-Security, Content-Security-Policy, X-Content-Type-Options: nosniff, Referrer-Policy and frame protection (CSP frame-ancestors or X-Frame-Options).
How do I add security headers in nginx?
Choose nginx above and add the add_header lines to your server block. The always flag makes them apply to error responses too.
Will a Content-Security-Policy break my site?
A strict one can block inline scripts and third-party resources. Start with the report-only option, check the browser console, and adjust before enforcing.
What HSTS max-age should I use?
Two years (63072000) for production once HTTPS works everywhere; a few minutes while testing.