Guides · Website security
Website security headers explained
When a browser loads your page, your server can answer with instructions attached: Strict-Transport-Security forcing HTTPS instead of plain HTTP, X-Content-Type-Options: nosniff stopping browsers from guessing a file's type, a Content-Security-Policy naming which scripts are allowed to run. Security headers are a handful of lines your server sends with every page, telling browsers how to behave — and they are among the highest-value, lowest-cost defences on the web. They cost nothing, break almost nothing when set carefully, and prevent entire classes of attacks. Yet most small sites send none of them. This guide explains the seven that matter, in the order to set them.
By the Ingenious AI team · Published 14 November 2026 · Reviewed 14 November 2026
The short answer
Set these seven security headers first: Strict-Transport-Security (force HTTPS), Content-Security-Policy (control what can load), X-Content-Type-Options (stop MIME guessing), X-Frame-Options or frame-ancestors (stop clickjacking), Referrer-Policy (limit what leaks on navigation), Permissions-Policy (disable camera, microphone and geolocation), and Cross-Origin-Opener-Policy (isolate your window). Start with the three that never break anything (HSTS, nosniff, referrer) and add CSP in report-only mode before enforcing it.
Try it free: BreachHunter — run a free scan and see which of the seven headers your site is actually sending — with the exact fix for each missing one.
What is a security header?
an HTTP response header that instructs a visitor's browser to apply a security behaviour — such as loading only over HTTPS, refusing to frame your page, or blocking scripts from unapproved sources. Headers are server configuration, not code: once set, they protect every visitor automatically, including visitors who will never think about security at all.
HSTS: HTTPS, enforced, not suggested
Strict-Transport-Security tells browsers to use HTTPS for your domain for a set period (start with max-age of six months, then a year) and never to accept the plain-HTTP version. Without it, an attacker on a shared network can downgrade a visitor to HTTP and intercept or alter the page. Add includeSubDomains once you are confident every subdomain serves HTTPS, and consider preload only after the policy has run stably — preload is powerful and hard to undo, so it belongs at the end of the journey, not the beginning.
Content-Security-Policy: the one that stops script injection
CSP is the strongest header you can set, and the one that needs care. It declares which origins may supply scripts, styles, images and other resources; anything else is blocked by the browser. A good policy stops most cross-site scripting attacks cold, because an attacker's injected script has no approved origin. Deploy it in report-only mode first, watch the violation reports for a week, fix the legitimate sources you forgot, then enforce. A policy written by copying someone else's example without the reporting phase is how sites break their own checkout.
The quiet three: nosniff, frame protection, referrer
X-Content-Type-Options: nosniff stops browsers guessing a file's type — the trick that lets an uploaded 'image' execute as a script. X-Frame-Options (or CSP frame-ancestors, which is the modern form) stops your pages being framed by other sites, killing clickjacking. Referrer-Policy limits the URL data sent when visitors navigate away — strict-origin-when-cross-origin is the sensible default. All three are one line each, safe to set immediately, and together they close attack classes that have been exploited for a decade.
Permissions-Policy and opener isolation
Permissions-Policy (formerly Feature-Policy) lets you disable browser features your site does not use — camera, microphone, geolocation, payment — so a compromised script cannot reach them. Cross-Origin-Opener-Policy and its partner Cross-Origin-Embedder-Policy isolate your page's browsing context, protecting against cross-window attacks. These are the headers sophisticated audits check and most sites lack; they are also the easiest to set, because disabling features you never use breaks nothing.
Testing, breaking, and keeping them set
After setting headers, test from outside: a free external scan reports exactly what a visitor's browser receives, including headers that a proxy or CDN stripped on the way out. Test after every hosting, CDN or framework change — headers set in one layer are silently lost when another layer takes over serving. The classic failure: headers perfect on the origin, absent on the CDN that actually serves visitors. A monthly scan is the only reliable way to know they are still there.
Your 5-action checklist
- Scan your site today and record which of the seven headers are actually reaching visitors.
- Set the safe three immediately: HSTS (6-month max-age), nosniff, and a sensible Referrer-Policy.
- Add frame protection and Permissions-Policy disabling camera, microphone and geolocation.
- Deploy CSP in report-only mode for a week, fix legitimate sources, then enforce it.
- Re-scan after every hosting, CDN or framework change — headers are silently lost in migrations.
Worked example: Blue Hole Dive Charters
Blue Hole Dive Charters, a fictional tour operator taking bookings online, set all seven headers in an afternoon after a scan showed they sent none. The CSP report-only week surfaced one surprise: their booking widget loaded a script from a domain their developer had not listed, which would have broken bookings had CSP gone straight to enforce. They fixed the allowlist, enforced, and moved on. Six months later their host was hit by a stored-XSS attempt targeting the booking form's review field; the injected script was blocked by the CSP in every visitor's browser, and the only evidence was a violation report. The headers cost nothing and the attack's impact was zero — the combination every security control aspires to.
Frequently asked questions
Do security headers slow down my website?
No — they add a few bytes to response headers and no rendering work. If anything, some policies (blocking unwanted resources) reduce what browsers fetch. Headers are the rare security measure with effectively zero performance cost.
Will CSP break my site?
It can, if enforced before you have seen what your pages actually load. That is what report-only mode is for: a week of real traffic reveals every legitimate source, after which enforcement is safe. Sites that break from CSP almost always skipped the reporting phase.
My site is on a website builder. Can I set headers?
Some builders expose header settings, some set sensible defaults, and some offer no control at all. Check what your builder sends with a free scan; if it sends none and offers no settings, that is a real factor in whether the builder suits a business site.
Do headers replace a firewall or a scanner?
No — they are one layer. Headers limit what browsers allow; a scanner finds exposed files and misconfigurations; a firewall filters traffic. The three complement each other, and none substitutes for the others.
What about HSTS preload — should I submit?
Only after HSTS has run stably with includeSubDomains for months across every subdomain, because preload is effectively permanent and a mistake blocks your domain from plain HTTP everywhere. For most small sites, a long max-age without preload is plenty.
Related guides and tools
- How to choose a website security scanner
- DMARC setup guide for small businesses
- Website security checklist for small businesses
- AI agent security: a buyer's guide
- How much does a website security audit cost?
- DMARC vs SPF vs DKIM: what each one actually does
- How to stop email spoofing of your domain
- AI chatbot security checklist
- All Ingenious AI guides
- The full Ingenious AI platform suite
- The security suite overview
- BreachHunter — free tool