Website Security Headers Explained
Every time your server sends a page, it also sends a set of HTTP headers, small instructions for the browser. Some of these headers tighten security by telling the browser what it is allowed to do with your pages. They are a cheap, effective layer, but a few can break your site if set carelessly, so add them thoughtfully.
Where to set them
Headers are set by your web server, hosting platform, or CDN. Many static hosts let you define headers in a configuration file or settings page. WordPress hosts may offer a setting or plugin. The exact method depends on your platform, so check its documentation.
Strict-Transport-Security (HSTS)
Tells browsers to always use HTTPS for your site for a period of time, which prevents downgrade attacks. Make sure HTTPS works everywhere first. Be cautious with options that include all subdomains or ask browsers to preload your domain, since they are hard to undo if some subdomain is not ready. See what is SSL and why HTTPS matters.
Content-Security-Policy (CSP)
Defines which sources a page may load scripts, styles, images, and frames from. A good policy can limit the damage of injected scripts. It is also the hardest header to get right, since it can block legitimate features such as analytics or embeds. Start in report-only mode, review what would be blocked, then enforce. Sites with many third-party scripts need a longer policy. See third-party scripts and website speed.
X-Content-Type-Options
Set to nosniff, it tells browsers not to guess file types, which prevents some attacks where a file is treated as a script. It is simple and widely recommended.
Referrer-Policy
Controls how much of your page's address is shared with other sites when visitors click links or load resources. A common privacy-friendly choice is to send only the origin to other sites. Check that analytics you rely on still work.
Permissions-Policy
Lets you switch off browser features your site does not use, such as camera, microphone, or location, and limit what embedded content can use. Disable what you do not need.
Clickjacking protection
To stop other sites from embedding yours in a frame to trick visitors, use the frame-ancestors directive in CSP, or the older X-Frame-Options header. If you intentionally allow embedding, configure it accordingly.
How to test
- Use your browser's developer tools to check the response headers on your pages.
- Use a free header-checking service to see what is present and missing.
- Test forms, checkouts, embeds, maps, and analytics after changing anything.
- Keep a list of what you set and why. See how to keep a website changelog.
Scores from header checkers are a guide, not a goal. A grade does not mean your site is secure, and a low grade does not mean it is hacked.
What headers cannot do
Headers do not replace updates, strong passwords, or backups. See how to keep your website secure and what is a web application firewall.
Common mistakes
- Enabling a strict CSP without testing
- Using HSTS before HTTPS is fully working
- Copying a header set from another site without understanding it
If the worst happens, you need a plan. Read how to handle a hacked website.