HTTP Security Headers That Matter

On this page
  1. Which headers does a modern site actually need?
  2. How do you deploy them without breaking things?
  3. Why is CSP the header worth the most effort?
  4. What do headers not fix?

HTTP security headers are one-line instructions your server sends that switch on browser defenses: forced HTTPS, script allowlists, frame blocking, and referrer trimming. They cost nothing at runtime and deploy in minutes. This guide covers the headers that matter in 2026, what each defends against, and configs you can ship.

Which headers does a modern site actually need?#

HeaderDefends againstRecommended value
Strict-Transport-SecurityProtocol downgrade, cookie hijackingmax-age=31536000; includeSubDomains
Content-Security-PolicyXSS payload execution, injected framesNonce-based; see below
X-Content-Type-OptionsMIME-sniffing confusionnosniff
Referrer-PolicyURL/query leakage to third partiesstrict-origin-when-cross-origin
Permissions-PolicySilent sensor/API abuseDeny what you don’t use, e.g. camera=()
X-Frame-OptionsClickjacking (legacy browsers)DENY (superseded by frame-ancestors)
Cross-Origin-Opener-PolicyCross-window attacks (XS-Leaks)same-origin

Two entries you may still see in old checklists are gone for good reason: X-XSS-Protection controlled a browser auditor that no longer exists, and Expect-CT did its job and retired when Certificate Transparency became mandatory.

How do you deploy them without breaking things?#

The failure mode is not “too little security” — it is an over-tight policy shipped blind. Sequence the rollout:

  1. Ship the harmless four first: X-Content-Type-Options, Referrer-Policy, Permissions-Policy, and frame controls.
  2. Add Strict-Transport-Security with a modest max-age=86400, confirm every subdomain serves HTTPS, then raise it to a year.
  3. Run your Content-Security-Policy in Content-Security-Policy-Report-Only mode against real traffic until the report noise is zero — then enforce.
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Content-Security-Policy "default-src 'self'; frame-ancestors 'none'; base-uri 'none'" always;

Why is CSP the header worth the most effort?#

Because it is the only one that fights back after a bug ships. Correct output encoding should prevent cross-site scripting, but a strict CSP decides what an injected payload can actually do — and the modern nonce-based pattern is dramatically more robust than the old allowlist approach:

Content-Security-Policy: script-src 'nonce-r4nd0m123' 'strict-dynamic';
  object-src 'none'; base-uri 'none'; frame-ancestors 'none'

The nonce changes every response, so an attacker who can inject markup still cannot execute script without guessing it. 'strict-dynamic' lets your legitimately-loaded scripts load their own dependencies, which is what makes this deployable on real applications.

What do headers not fix?#

Headers harden the browser’s handling of your responses; they do not repair broken application logic. SQL injection sails straight past every header on this page, and a misconfigured CORS policy — covered in the same-origin policy explainer — is an application decision, not a header omission. Treat this layer as armor over correct code, and find the rest of the armor at the Web Security hub.

Frequently asked questions#

Which security headers should every site set, at minimum?

Four are near-universal: Strict-Transport-Security to lock in HTTPS, X-Content-Type-Options: nosniff to stop MIME confusion, a frame-ancestors directive (or X-Frame-Options) against clickjacking, and Referrer-Policy: strict-origin-when-cross-origin to limit data leakage. Add a Content-Security-Policy as the site matures.

Are X-Frame-Options and X-XSS-Protection still needed?

X-Frame-Options survives only as a fallback for old browsers — CSP frame-ancestors supersedes it. X-XSS-Protection is obsolete: modern browsers removed the auditor it controlled, and setting it can introduce issues in old ones. Set frame-ancestors, keep X-Frame-Options if you must, and drop X-XSS-Protection.

Can security headers break my site?

Two of them can, badly: a wrong Content-Security-Policy can block your own scripts, and HSTS with includeSubDomains and preload can lock out an HTTP-only subdomain for months. Roll CSP out in Report-Only mode first, and start HSTS with a short max-age you grow over time.

Sources & further reading