A Practical Guide to HTTP Security Headers
Response headers that tell the browser to enforce security rules for a site, such as which sources scripts may load from and whether the site must always be reached over HTTPS.
On this page
What is at stake
They are a cheap server-side layer of defense against common attacks such as cross-site scripting and clickjacking, and anyone can check them from outside in seconds.
The playbook
- Roll out Content-Security-Policy in report-only mode first
- Enable HSTS only once every subdomain serves HTTPS
- Send nosniff on every response
- Restrict framing unless the site is meant to be embedded
- Recheck headers after any CDN or hosting change
Where it goes wrong
Avoid:
- Policies that allow unsafe-inline and so defeat their own purpose
- Submitting to the HSTS preload list before all subdomains support HTTPS
- Headers set on the origin server but stripped by the CDN
- Copying another site's policy without testing it on yours
The numbers behind it
| Measure | Figure |
|---|---|
| Content-Security-Policy | limits where scripts, styles, images and frames may load from |
| Strict-Transport-Security | tells browsers to use only HTTPS for the site for the max-age given |
| X-Content-Type-Options: nosniff | stops browsers guessing a file's type from its content |
| Clickjacking protection | the CSP frame-ancestors directive, or the older X-Frame-Options header |
| Referrer-Policy | controls how much of the current URL is sent to other sites |
Getting outside help
When to hand it over: Bring in help when a security scan flags missing headers, when a CSP breaks third-party tools, or before enabling HSTS preload on a domain with many subdomains.
Where this comes from
- MDN Web Docs — HTTP headers
- MDN Web Docs — Content Security Policy
- OWASP — HTTP Security Response Headers Cheat Sheet
The figures and practices above come from the sources listed.
Working on something like this?
We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.
Where to go next
Spotted something wrong? Report an error on this page. We correct on the page and say what changed.