HTTP Security Headers Explained: A Practical Guide for Website Owners
Security headers are one of the cheapest, most overlooked wins in web security. Here's what each major header actually does, and how to check yours for free.
What Are HTTP Security Headers?
Every time a browser requests a page, the server sends back a set of HTTP response headers alongside the actual content. Most of these are mundane — content type, cache rules, server name. A specific group of them exist purely to tell the browser how to defend the page against common attacks: cross-site scripting, clickjacking, protocol downgrade attacks, and data leakage through referrers.
Adding them costs nothing in performance and usually takes a few lines of server configuration. Most sites still ship without several of them, simply because nobody checked.
Content-Security-Policy: Your First Line of Defense
Content-Security-Policy, or CSP, tells the browser exactly which sources are allowed to load scripts, styles, images, and fonts on your page. Without it, a single injected script tag — through a compromised third-party widget, a stored XSS vulnerability, or a malicious browser extension affecting a logged-in admin — can run with full access to the page.
A strict CSP turns an injected script into a dead end: the browser refuses to execute anything from a source not explicitly allowed. The tradeoff is that CSP needs to be configured deliberately — a default-deny policy with explicit allowances for the third-party scripts you actually use, not a blanket allow-all that defeats the purpose.
Strict-Transport-Security: Closing the HTTP Window
Strict-Transport-Security, or HSTS, tells the browser to never attempt an unencrypted HTTP connection to your domain again, even if a user types http:// manually or clicks an old link. Without it, every visit starts with a brief, exploitable window where a connection could be downgraded to plain HTTP before the redirect to HTTPS happens.
HSTS closes that window permanently, for as long as the policy's max-age specifies. Sites that have had HTTPS for years sometimes still lack this header simply because it was never added after the HTTPS migration.
X-Frame-Options and Clickjacking
X-Frame-Options controls whether your page can be loaded inside an iframe on another site. Without it, an attacker can embed your login page or a sensitive action button inside an invisible iframe layered under their own page, tricking users into clicking something they cannot see — this is clickjacking.
Setting this header to DENY or SAMEORIGIN closes that attack entirely for pages that have no legitimate reason to be framed elsewhere, which is most pages on most sites.
X-Content-Type-Options and Referrer-Policy
X-Content-Type-Options: nosniff stops the browser from trying to guess a file's type based on its content instead of trusting the declared Content-Type. Without it, a file uploaded as an image but containing executable script can sometimes be interpreted and run as that script — a class of attack called MIME-sniffing.
Referrer-Policy controls how much of your URL gets sent to other sites when a user clicks an outbound link. A loose policy can leak session tokens or internal page structure embedded in your URLs to every site your users click through to; a stricter setting like strict-origin-when-cross-origin sends only the minimum necessary.
How to Check Your Own Headers
You do not need to memorize header syntax to know whether you are protected. The fastest way to find out is to scan your own domain and see exactly which of these headers are present, which are missing, and which are misconfigured.
Try it free: Security Headers Checker
Checks CSP, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Permissions-Policy with a weighted score.
Analyze your YouTube channel for free
Enter any channel handle and get a full analytics dashboard with AI insights — no sign-in required.
Written by
Jayesh Gavit
Founder, StatFlare
Jayesh Gavit is the founder of StatFlare, a free YouTube channel analytics platform used by thousands of creators and marketers. He has spent years studying the YouTube algorithm, audience behavior, and creator monetization patterns. Outside of building StatFlare, Jayesh creates videos at @jayeshverse covering software, indie product building, and the creator economy.
Free Tools