Security headers explained: the six lines that protect your visitors

Six short lines in your server response tell browsers how to treat your site. What each one does, what happens without it, and which to set first.

3 minread 752words last updated

The short answer

Every time a browser loads a page from your site, your server sends a few lines of text along with it. Some of those lines are instructions about security: only use encrypted connections, do not let other websites embed this page, only run scripts that come from here. Browsers follow them. Without them, browsers fall back to permissive defaults that were designed for a friendlier web.

Six headers cover most of the ground. A security scan checks all six, and a site that has never been configured is missing at least four.

The six, in one table

HeaderWhat it tells the browserWhat can happen without it
Strict-Transport-Security (HSTS)Only ever use HTTPS for this domainThe first request can be intercepted on hostile networks
X-Content-Type-OptionsDo not guess file types, trust what I sayA disguised file can be executed as a script
X-Frame-Options or CSP frame-ancestorsDo not let other sites put this page in a frameClickjacking: your page overlaid with invisible buttons on a malicious site
Referrer-PolicyHow much of the current address to share when a visitor clicks awayPrivate URLs and query details leak to third parties
Permissions-PolicyWhich browser features this page may use, such as camera, microphone, locationEmbedded scripts can request powerful features in your name
Content-Security-Policy (CSP)Exactly where scripts, styles, images and frames may come fromAn injected script runs with full access to the page

The quick five

Five of the six are safe defaults. They rarely break anything and can be set in an afternoon.

  1. HSTS. Set it once every page, image and subdomain already works over HTTPS. Start with a short max-age, then raise it. Details in What is HSTS.
  2. X-Content-Type-Options: nosniff. One value, no options, no side effects. Set it and forget it.
  3. Frame protection. Either X-Frame-Options: DENY, or the frame-ancestors rule in CSP if you use one. Only allow framing if you know a partner site embeds you on purpose.
  4. Referrer-Policy: strict-origin-when-cross-origin. Sends your domain, not the full address, when visitors leave to another site. A sensible middle ground that keeps analytics useful.
  5. Permissions-Policy. Turn off what you do not use: camera, microphone, geolocation, payment. A brochure site needs none of them.

The one that takes longer: Content Security Policy

CSP is the most powerful header and the only one that needs real work. It lists where scripts, styles, images, fonts and frames may be loaded from. Anything not on the list is blocked. That is exactly why it stops injected scripts, and exactly why it breaks things when the list is incomplete. One value decides how much of that protection you keep: where script-src contains 'unsafe-inline', a script written straight into the page still runs, and the policy only covers what is loaded from elsewhere. The article on Content Security Policy sets out the two ways around that.

Where the headers live

On modern static hosting, headers are a small configuration file in the project, deployed with the site and versioned with the code. On traditional hosting they are set in the web server configuration. On a content system with plugins, they are sometimes set by a plugin, which works until the plugin is updated or removed.

Whichever it is: check the headers after every migration, every hosting change and every new tag. They are the first thing to silently disappear when something moves.

What this means for you

Ask for the response headers of your homepage, or run a scan. If four or more of the six are missing, the quick five are an afternoon of work for whoever runs your hosting, and CSP is a week of careful testing. Both are cheaper than the incident they prevent.

Written by the CivSec S.M.A.R.T team

We build and run websites, software and AI systems for businesses. We write about what we see in that work, in plain language, and we update articles when things change.

Last checked . Spotted something outdated? Tell us.

Frequently asked questions

Do security headers make my website slower?

No. They are a few hundred bytes of text sent with each response. The browser reads them once and applies the rules. There is no measurable performance cost.

Which header should I set first?

HSTS, once every page loads over HTTPS. Then X-Content-Type-Options and X-Frame-Options or the frame-ancestors rule, because they are safe defaults that break nothing. Referrer-Policy and Permissions-Policy next. Content Security Policy last, because it needs testing.

Can a security header break my website?

Two of them can, if set carelessly. HSTS locks visitors into HTTPS, so every page must already work over HTTPS. Content Security Policy blocks scripts and styles that are not on its list, so it must be tested in report-only mode first. The other four are safe to enable as is.

My site is static. Do I still need them?

Yes. Headers protect the visitor's browser against attacks that use your page as a stage, such as being framed by a malicious site or having an injected script run. A static site has fewer server-side risks, not fewer browser-side ones.

Sources

  1. OWASP Secure Headers Project (accessed 2026-09-11)
  2. MDN Web Docs: Content Security Policy (accessed 2026-09-11)
  3. MDN Web Docs: X-Content-Type-Options (accessed 2026-09-11)
  4. MDN Web Docs: Referrer-Policy (accessed 2026-09-11)