What security headers are
Security headers are HTTP response headers that tell the browser to apply extra protections to your pages. They cost almost nothing to send and reduce the impact of common attacks, but they are one layer among many, not a substitute for secure code and updated software.
The six headers to know
Strict-Transport-Security (HSTS)
Tells browsers to use HTTPS only for your domain for a set time, for example max-age=31536000; includeSubDomains. Enable it only when every subdomain works over HTTPS, because browsers will refuse plain HTTP until it expires.
Content-Security-Policy (CSP)
Lists the sources from which scripts, styles, images, and frames may load. It is the strongest defence against cross-site scripting, and the hardest to roll out. Start with Content-Security-Policy-Report-Only so the browser reports problems without blocking anything, then tighten and enforce.
X-Content-Type-Options
nosniff stops the browser from guessing a file’s type and executing a file that claims to be something else.
Referrer-Policy
Controls how much of the page address is sent to other sites. strict-origin-when-cross-origin is a sensible default.
Permissions-Policy
Switches off browser features you do not use, for example camera=(), microphone=(), geolocation=().
Clickjacking protection
X-Frame-Options: SAMEORIGIN or the CSP directive frame-ancestors 'self' stops other sites from embedding your pages in a hidden frame.
How to check them
Enter your address in the Security Headers Checker. It marks each header Good, Review, or Missing and shows the actual value. From a terminal, curl -I https://example.com/ prints all headers. Check the final page after redirects, and check an important inner page as well, because headers can differ by path.
How to add them
The cleanest place is the web server or CDN. Examples:
# Nginx
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# Apache (mod_headers)
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
On managed hosting or WordPress, a CDN rule or a reputable security plugin can set them. Always test after changing: some headers, especially CSP and HSTS, can break pages.
Safe order of rollout
- Move the whole site to HTTPS with a single redirect.
- Add
X-Content-Type-Options,Referrer-Policy, and framing protection. - Add
Permissions-Policy. - Add HSTS with a short max-age, then raise it.
- Add CSP in report-only mode, fix violations, then enforce.
Remove what leaks
Headers such as X-Powered-By and detailed Server versions reveal your software. Removing them is optional hygiene, not a fix for any vulnerability.
FAQ
Will security headers improve my SEO?
Not directly. They protect visitors, and HTTPS itself is a lightweight ranking signal.
Can a header break my site?
Yes. CSP in particular blocks anything not allowed. That is why report-only mode exists.
Is a site safe if all headers are present?
No. Headers reduce certain risks. They do not fix vulnerable code, weak passwords, or outdated plugins.