TL;DR
Get privacy and security gear delivered free — and shop member deals
- Fast, free delivery on millions of items
- Access to Prime Big Deal Days deals on October 6–7
- Prime Video, Amazon Music and more included
Security headers are HTTP response headers that tell browsers how to handle a website’s content — which scripts may run, whether the page can be framed, and whether HTTPS is required. Headers like Content Security Policy, HSTS, and Referrer Policy can limit the damage from cross-site scripting, clickjacking, and protocol downgrade attacks, but they don’t fix vulnerable code. The safe approach is to inventory your site, test policies in report-only mode first, and verify the headers users actually receive.
Every time your website responds to a visitor, it sends more than HTML. Hidden in that response are HTTP response headers — small lines of text that tell browsers what’s allowed, what’s forbidden, and how to handle your content.
Most site owners never look at them. Attackers hope you don’t either. When headers are missing, the browser falls back to permissive defaults: any script can run, any site can embed your pages in a frame, and an old HTTP connection is fine. That permissiveness is exactly what several common attack techniques rely on.
In this guide, you’ll learn what security headers actually do, which ones are worth your time in 2025, which are obsolete relics of an older web, and how to deploy them without breaking your own site. No fear-mongering, no checklist worship — just practical guidance you can act on this week.
Security headers are browser-enforced instructions, not a server-side filter — they reduce the impact of attacks like XSS, clickjacking, and protocol downgrade…
Start with CSP, HSTS, X-Content-Type-Options, Referrer Policy, and Permissions Policy, then tune each to your site instead of copying a scanner template.
Always test CSP in report-only mode first, and enable HSTS only after HTTPS works across your domain and every included subdomain.
X-XSS-Protection and Expect-CT are obsolete; prefer CSP’s frame-ancestors over X-Frame-Options for new embedding rules.
A high scanner grade proves headers exist, not that they protect you — verify the headers users actually receive, including on error pages, APIs, and subdomain…
Why Security Headers Matter for Modern Websites
Every response your site sends carries more than HTML. Hidden inside are HTTP headers — small lines of text telling browsers what’s allowed, what’s forbidden, and how content may be handled. Most site owners never look at them. Attackers hope you don’t either.
What Security Headers Actually Do
Think of them as the settings on a front door lock. Your application code is the door; headers are the deadbolt, the chain, and the peephole. A flimsy door with good locks still fails — but a solid door with no locks is asking for trouble. Defense works in layers.
Cross-Site Scripting
A restrictive Content Security Policy limits which scripts the browser is allowed to execute, blunting the impact of injected code.
Deceptive Framing
frame-ancestors stops other sites from embedding your page in an invisible or deceptive frame.
Protocol Interception
HSTS tells browsers to always use HTTPS, blocking downgrade attacks and Wi-Fi interception.
Unnecessary Capabilities
Permissions Policy restricts camera, microphone, and geolocation access to pages that genuinely need them.
Information Leaks
Referrer Policy limits how much URL detail browsers hand to third-party sites when users follow links.
Cached Private Data
Careful Cache-Control keeps account-specific pages from being stored by shared proxies and served to the wrong person.
The Five Headers Worth Setting Up First
A starting point, not a copy-paste template — the right settings depend on your site. Tune each one instead of cloning a scanner’s recommendation.
| Header | What it does | Common pitfall | Risk to add |
|---|---|---|---|
| Content-Security-Policy | Defines approved sources for scripts, styles, and images; can require nonces or hashes | Overly broad allowlists that quietly defeat the policy | High — breaks things |
| Strict-Transport-Security | Forces HTTPS for a set period; includeSubDomains and preload extend coverage | Enabling before HTTPS works everywhere — locks users out | Medium — verify first |
| X-Content-Type-Options | nosniff stops browsers from guessing a file’s content type | Almost none | Low — cheap win |
| Referrer-Policy | Controls URL detail in the Referer header; strict-origin-when-cross-origin is a common default | A value that breaks analytics or partner integrations | Low |
| Permissions-Policy | Restricts browser features like camera and geolocation | Blocking features your app legitimately uses | Medium |
| X-Frame-Options / X-XSS-Protection / Expect-CT | Legacy embedding, XSS auditor, and certificate-transparency directives | Obsolete: prefer CSP frame-ancestors; the others are relics | Retire |
Deploy CSP Without Breaking Your Site
The Friday-deploy horror story: strict CSP goes live, and by Monday the analytics tag silently died, the chat widget vanished, and checkout broke on Safari. Frustrated teams then weaken or disable the policy — leaving you less secure than before. Follow this sequence instead.
Inventory Resources
List every script, style, font, image host, API, and embedded third-party widget your pages load.
Report-Only Mode
Content-Security-Policy-Report-Only reveals violations without blocking anything.
Review Reports
Each report names a resource your policy would have blocked — decide if it’s legitimate.
Tighten Gradually
Prefer nonces and hashes over broad host allowlists; avoid unsafe-inline exceptions.
Enforce & Watch
Ship the real policy and keep report monitoring for new third-party additions.
HSTS Lockout Risk & Where Grades Mislead
Once a browser sees Strict-Transport-Security: max-age=31536000, it refuses plain HTTP to your domain for a full year. If your certificate expires or a subdomain still serves HTTP only, users are locked out — with no quick undo. Verify everything users actually receive.
A header may stop the blast; it won’t disarm the bomb. A CSP can blunt the consequences of an XSS flaw — it does not make unsafe code safe. Treat headers as one layer alongside secure code, access controls, patching, and monitoring. Enable HSTS only after HTTPS works across your domain and every included subdomain.
From Inventory to Enforcement
What Security Headers Actually Do for Your Site
Security headers are instructions your server attaches to every response, telling the browser what rules to follow when rendering your site. They don’t filter traffic at the server like a firewall does — the browser enforces them. That’s their strength and their limit: they work at the last mile, right where the user is looking at your page.
Think of them as the settings on a front door lock. Your application code is the door itself; headers are the deadbolt, the chain, and the peephole. A flimsy door with good locks still fails, but a solid door with no locks is asking for trouble. Defense works in layers.
When configured correctly, headers can reduce the impact of real, named attacks:
- Cross-site scripting (XSS): a restrictive Content Security Policy limits which scripts the browser may execute.
- Clickjacking:
frame-ancestorsstops other sites from embedding your page in a deceptive frame. - Protocol downgrade and interception: HSTS tells browsers to always use HTTPS.
- Unnecessary browser features: Permissions Policy restricts camera, microphone, and geolocation access.
- Information leaks: Referrer Policy limits how much URL data browsers send to third-party sites.
Here’s the honest part, though: headers don’t fix vulnerabilities. A CSP may blunt the consequences of an XSS flaw, but it doesn’t make unsafe code safe. Treat headers as one layer in a broader program — alongside secure code, careful access controls, patching, and monitoring.
A header may stop the blast; it won’t disarm the bomb.
As an affiliate, we earn on qualifying purchases.
The Five Headers Worth Setting Up First
Which security headers should a modern website start with? The usual candidates are Content Security Policy, HSTS, X-Content-Type-Options, Referrer Policy, and Permissions Policy — but the right settings depend on your site, so treat this as a starting point, not a copy-paste template.
| Header | What it does | Common pitfall |
|---|---|---|
| Content-Security-Policy | Defines approved sources for scripts, styles, and images; can require nonces or hashes | Overly broad allowlists that quietly defeat the policy |
| Strict-Transport-Security | Forces HTTPS for a set period; includeSubDomains and preload extend coverage | Enabling before HTTPS works everywhere — locks users out |
| X-Content-Type-Options | nosniff stops browsers from guessing a file’s content type | Almost none — cheap and low-risk to add |
| Referrer-Policy | Controls how much URL detail leaks in the Referer header; strict-origin-when-cross-origin is a common privacy-friendly default | Choosing a value that breaks analytics or partner integrations |
| Permissions-Policy | Restricts browser features like camera and geolocation | Blocking features your app legitimately uses |
A quick example: imagine a small e-commerce site with a live-chat widget. A Permissions Policy that disables geolocation everywhere except the store-locator page is a genuine win — the chat widget, and any script injected through it, simply can’t request location. That’s the browser doing enforcement work for you, for free.
Don’t forget caching, either. Cache-Control isn’t usually filed under security headers, but pages with account-specific or private data need careful cache policies so shared caches don’t store and serve them to the wrong person. A checkout confirmation page cached at a shared proxy is a privacy incident waiting to happen.
HTTP security headers configuration
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
How to Deploy Content Security Policy Without Breaking Your Site
CSP is the header most likely to break things — and the most valuable when done right. It defines approved sources for every script, style, and image your page loads, and a strict policy using nonces or hashes for scripts makes many injected scripts much harder to execute.
Here’s a scenario every developer eventually hits: you add a strict CSP on a Friday, and by Monday the marketing team reports their analytics tag silently died, the chat widget vanished, and the checkout button stopped working on Safari. Frustrated teams weaken or disable the policy entirely, and you end up less secure than before you started.
The safe rollout looks like this:
- Inventory your resources. List every script, style, font, image host, API, and embedded third-party widget your pages load.
- Start in report-only mode.
Content-Security-Policy-Report-Onlyreveals violations without blocking anything. - Review the violation reports. Each report names a resource your policy would have blocked — decide if it’s legitimate.
- Tighten gradually. Prefer nonces or hashes over broad host allowlists and avoid
unsafe-inlineexceptions. - Enforce, then keep watching. Ship the real policy, and keep report monitoring in place for new third-party additions.
The shift in modern guidance is real: CSP advice has moved away from long allowlists and inline-script exceptions toward per-request nonces and hashes. Browser support for newer directives varies, so verify behavior against the browsers your users actually run — not just the latest Chrome.
Content Security Policy (CSP) testing tools
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Why HSTS Can Lock You Out — and How to Avoid It
HSTS tells browsers that your site must be accessed only over HTTPS for a specified period, blocking protocol downgrade attacks and stripping interception on public Wi-Fi. It’s simple, effective, and the one header most capable of locking real users out of your site.
Here’s the mechanism. Once a browser sees Strict-Transport-Security: max-age=31536000, it refuses plain HTTP connections to your domain for a full year. If your certificate expires, or an internal subdomain still lives on HTTP-only hosting, visitors get a hard error — no click-through, no workaround. The includeSubDomains flag extends the rule to every subdomain, and preload asks to be baked into browser-maintained preload lists, which are extremely difficult to reverse.
Picture this: you enable HSTS with includeSubDomains on a Tuesday. On Wednesday, someone remembers the old intranet tool at reports.yourdomain.com that never got HTTPS. That tool is now unreachable for anyone who visited the main site. The thud of a help-desk ticket pile landing on your desk is the sound of a header deployed out of order.
The rule is straightforward: enable HSTS only after HTTPS works reliably across the domain and every included subdomain. Start with a short max-age — say, a few minutes or an hour — and ramp up once you’ve confirmed nothing breaks. Only then consider preload.
As an affiliate, we earn on qualifying purchases.
Headers to Retire: What’s Obsolete in 2025
Not every header on an old checklist still earns its place. Modern security-header advice has shifted from “add this list” toward context-aware, tested policies — and that means retiring some familiar names.
X-XSS-Protection is the clearest example. It activated an old browser-side XSS auditor that modern browsers removed years ago. Sending it today does essentially nothing, and presenting it as a primary defense gives a false sense of security.
Expect-CT is another retired item. It was a transitional mechanism for Certificate Transparency enforcement that browsers have since deprecated; it’s no longer a deployment priority.
X-Frame-Options sits in between. It remains relevant for compatibility with older browsers, but CSP’s frame-ancestors is generally the more flexible control — it supports fine-grained rules about which sites may embed your page, where X-Frame-Options offers only coarse options.
| Header | Status | What to do |
|---|---|---|
| X-XSS-Protection | Obsolete | Remove it; modern browsers ignore the auditor |
| Expect-CT | Deprecated | Skip it; not a current priority |
| X-Frame-Options | Legacy but useful | Keep for compatibility; prefer frame-ancestors for new rules |
| CSP, HSTS, Referrer-Policy, Permissions-Policy | Current | Deploy with tested, site-appropriate settings |
If a scanner grades you down for missing X-XSS-Protection, that’s the scanner being out of date — not your site being insecure. Distinguishing current controls from legacy checklist items is half the job.
Why Your A+ Scanner Grade Doesn’t Mean You’re Secure
Automated scanners can spot missing or weak headers, and they’re useful for that. But a high score does not prove an application is secure. A header may be present yet ineffective, incompatible, or undermined by application behavior — and no scanner can tell the difference.
Consider a site with a CSP that looks strict but includes unsafe-inline for scripts because a legacy tag manager needed it. The scanner sees Content-Security-Policy in the response and awards full marks. In reality, that policy blocks almost nothing an attacker would actually use. Green checkmark, hollow protection.
There’s a second trap: frameworks, CDNs, reverse proxies, and hosting platforms can all modify response headers. Your origin server might send a perfect CSP that a CDN strips or overrides before it reaches the user. The only headers that matter are the ones users actually receive — including on error pages, API endpoints, redirects, and subdomains, which are exactly the paths most teams forget to check.
So treat automated grades as prompts for investigation, not proof of security:
- Inspect actual responses at the edge and at the origin.
- Test error pages, redirects, and API routes — not just the homepage.
- Recheck after changes to scripts, vendors, hosting, or CDN infrastructure.
- Ask whether each policy genuinely restricts something, or just exists to satisfy a scanner.
Because browser behavior and recommendations evolve, verify implementation guidance against current browser documentation and your specific technology stack — advice that was correct two years ago may already be stale.
A Practical Rollout Plan You Can Run This Week
How do you put all of this into practice without a security team? You follow a short, repeatable process that fits your actual site rather than copying a generic template. Here’s the sequence:
- Inventory everything: pages, APIs, subdomains, embedded content, third-party scripts, and browser features your site actually uses.
- Choose policies that fit the application — not the ones a scanner template recommends.
- Test CSP in report-only mode and review every violation before enforcement.
- Confirm full HTTPS coverage before enabling HSTS, especially with
includeSubDomainsorpreload. - Add the low-risk headers now:
X-Content-Type-Options: nosniffand a sensible Referrer Policy rarely break anything. - Verify actual responses at the edge and origin, including redirects, error pages, and API endpoints.
- Recheck after any change to scripts, vendors, hosting, or delivery infrastructure.
And yes — headers are useful for small websites too. A personal blog with HTTPS, a decent Referrer Policy, and nosniff gets real value for about ten minutes of work. A three-person SaaS with customer data should go further: tested CSP, HSTS, Permissions Policy, and careful cache controls on anything account-specific.
Revisit the whole set every few months. Third-party scripts change, vendors get swapped, CDNs get reconfigured — and yesterday’s correct header set can quietly become today’s gap.
Frequently Asked Questions
Do security headers prevent hacking?
No. Security headers can reduce certain risks or limit the impact of attacks — for example, a strict CSP makes injected scripts harder to execute — but they cannot replace secure code, authentication, patching, or monitoring. They are one layer in a broader security program.
Can security headers break my website?
Yes. CSP can block scripts or styles your site relies on, and HSTS can lock users out if HTTPS isn’t fully working — especially with includeSubDomains. Test policies in report-only mode and confirm HTTPS coverage before enforcing anything broadly.
Should I use CSP in report-only mode?
It’s usually the best starting point. Report-only mode reveals policy violations without blocking resources, so your team can refine the policy before enforcement. Skipping this step is the most common cause of broken checkout flows and dead analytics tags.
What’s the difference between CSP and a web application firewall?
CSP is enforced by the browser and controls how a page may load or execute resources. A web application firewall filters or analyzes traffic at the server or network edge. They address different parts of the security picture and work well together.
Are security headers useful for small websites?
Yes, if they’re configured appropriately. Smaller sites still benefit from HTTPS, nosniff, a sensible Referrer Policy, and attention to sensitive data and third-party resources. Some headers take minutes to add and carry almost no breakage risk.
Do headers affect SEO or site speed?
They aren’t a direct SEO factor. Their main purpose is security and privacy, and performance effects are usually small — though a policy error can prevent resources from loading, which indirectly hurts everything. That’s another reason to test before enforcing.
Are missing headers always a vulnerability?
Not necessarily. A missing header can be a useful finding, but its importance depends on the application, the threat model, browser support, and whether another control already addresses the same risk. Context beats checklists.
Conclusion
If you remember one thing: well-tested security headers add a browser-enforced layer of defense — nothing more, nothing less. They won’t make your site hack-proof, and a perfect scanner score guarantees nothing. But a set of policies built for your actual site, tested before enforcement, and verified at the edge is one of the cheapest security wins on the web today.
Start small. Add nosniff and a Referrer Policy this afternoon. Put a CSP in report-only mode this week and read what it tells you. Security is built in layers — and headers are a layer you can lay down before lunch.
Fall Picks
fall essentials
As an affiliate, we earn on qualifying purchases.
