HTTP Security Headers: The Web Platform Standard Your Site Is Probably Missing
Most "security headers checklists" skip the part that matters: which ones are still in the spec, which are legacy, and what actually replaces them.
Most "security headers checklists" skip the part that matters: which ones are still in the spec, which are legacy, and what actually replaces them.
A security header is a response header the server sends so the browser enforces a protection on its own, instead of relying on application code to get it right every time. Most checklists float around the web mixing current spec guidance with headers browsers quietly stopped honoring years ago. This guide sorts the two apart: what the living specs still define, what's legacy, and the exact set worth shipping in 2026.
Strip away the marketing language and a security header is just a response header: a name-value pair the server sends alongside the HTML, defined by the same HTTP and Fetch specifications that govern every other header a browser reads. What makes this subset "security" headers is simply that the browser's own fetch and rendering algorithms branch on them: refusing to frame a page, upgrading a connection to HTTPS, or declining to execute a script that wasn't explicitly allow-listed. None of this is application logic you write; it's behavior the user agent already has, waiting for you to switch it on.
Three headers show up on nearly every competent security checklist, and for good reason: they're cheap to set, have no real downside, and close off entire classes of accidental exposure.
By default, a browser sends the full URL of the page a user came from in the Referer header of outgoing requests, including query strings that might contain session tokens, search terms, or internal paths. Referrer-Policy: strict-origin-when-cross-origin trims that down to just the origin when the destination is cross-site, keeping the convenience of referrer data without leaking the path.
X-Content-Type-Options: nosniff tells the browser to trust the Content-Type you declared and stop guessing. Without it, some browsers will "sniff" a file's bytes and decide to execute a user-uploaded image as a script if it looks enough like one: a classic vector for stored-content attacks on sites that accept uploads.
X-Frame-Options: DENY stops your page from being loaded inside an <iframe> on someone else's site, which is the foundation of clickjacking: tricking a user into clicking a transparent, framed version of your page while they think they're clicking something else. It still works, and plenty of production sites still send it. But it's a single-value header competing with a far more capable mechanism: frame-ancestors, a directive inside Content-Security-Policy that can allow-list specific origins instead of an all-or-nothing block. The CSP directive is what current browsers consult first, and X-Frame-Options is kept around mostly for the handful of older clients that never learned to read CSP.
Content-Security-Policy, or CSP, is the one header that genuinely changes what a page is allowed to do, not just how it's displayed. Instead of trusting every script tag that ends up in your HTML, CSP lets you declare, up front, which origins are allowed to serve scripts, styles, images, and frames, and the browser enforces that allow-list on every request the page makes. It's the same discipline you'd want applied to any other production surface, which is exactly the kind of gap covered in YuSMP's guide to essential web application security best practices. This article focuses specifically on getting the HTTP headers right.
A minimal, workable policy looks like this:
Content-Security-Policy: default-src 'self';
script-src 'self' https://cdn.example.com;
style-src 'self' 'unsafe-inline';
img-src 'self' data: https:;
frame-ancestors 'none';
base-uri 'self';default-src is the fallback for any directive you don't set explicitly, script-src and style-src narrow where those resource types can load from, and frame-ancestors 'none' does the job X-Frame-Options: DENY used to do, but as part of a policy browsers evaluate as a single coherent unit rather than a scatter of unrelated headers. The CSP Level 3 specification is the normative source for every directive name and value here.
A redirect from http:// to https:// protects a visitor on their second request, not their first, which still goes out in plaintext and can be intercepted before the redirect ever happens. HTTP Strict Transport Security closes that window by telling the browser to rewrite every future request to the domain as HTTPS automatically, without touching the network:
Strict-Transport-Security: max-age=63072000; includeSubDomains; preloadmax-age is how long (in seconds) the browser should remember the rule, with two years as the common convention. includeSubDomains extends it to every subdomain, and preload submits the domain to a list baked directly into browser binaries, so the very first connection a user ever makes is already HTTPS-only. That last part is also the riskiest: once a domain is in the preload list, getting it removed takes months, so only add preload after every subdomain is confirmed to serve valid HTTPS. RFC 6797 defines the header in full.
Permissions-Policy (the successor to the earlier Feature-Policy) controls which browser APIs a page, and any iframe it embeds, is allowed to call at all, regardless of whether the user would grant permission if asked. If your site never uses the camera, microphone, or geolocation API, there's no reason to leave those doors unlocked for a compromised third-party script to try:
Permissions-Policy: camera=(), microphone=(), geolocation=()The difference from CSP is one of scope: CSP governs where resources can load from, while Permissions-Policy governs which capabilities loaded code is allowed to invoke once it's running. The two are complementary, not redundant.
This one deserves a direct warning rather than a recommendation: X-XSS-Protection controlled a browser's built-in cross-site-scripting filter, and that filter has been removed from every current major browser engine. Setting the header today does nothing in Chrome, Firefox, or Safari, and in a few historical configurations it actually introduced new vulnerabilities of its own. Modern guidance, including the OWASP Secure Headers Project, recommends setting X-XSS-Protection: 0 explicitly to disable any legacy behavior, or simply omitting the header and relying on a correctly scoped CSP, which is the mechanism that actually stops reflected XSS today.
| Header | Purpose | Example value | Status in 2026 |
|---|---|---|---|
| Content-Security-Policy | Allow-lists script/style/frame/image sources | default-src 'self' | Current, do this first |
| Strict-Transport-Security | Forces HTTPS on every future request | max-age=63072000; includeSubDomains | Current |
| X-Content-Type-Options | Blocks MIME-type sniffing | nosniff | Current |
| Referrer-Policy | Limits data sent in the Referer header | strict-origin-when-cross-origin | Current |
| Permissions-Policy | Disables unused browser capabilities | camera=(), microphone=() | Current |
| X-Frame-Options | Blocks framing on older clients | DENY | Superseded by frame-ancestors, still safe to keep |
| X-XSS-Protection | Toggled a browser XSS filter | 0 | Legacy: filter removed from current browsers |
Headers belong as close to the edge of your infrastructure as possible, so every response, including error pages and static assets, gets them without relying on application code to remember. On an nginx-fronted server, that's a block in the server config:
add_header Content-Security-Policy "default-src 'self'; frame-ancestors 'none'" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;On a Next.js project, the same thing is declared once in next.config.js via the headers() function, applied to a route pattern. On static hosts fronted by a CDN or edge network, the equivalent is usually a plain-text rules file the platform reads at deploy time and applies before a request ever reaches your origin. The mechanism changes; the requirement doesn't: set once, apply everywhere, never depend on a template remembering to include it.
The fastest check costs nothing: open the browser's developer tools, go to the Network panel, click any request to your domain, and read the Response Headers section. If a header you configured isn't listed there, it isn't being sent, full stop. No amount of correct server config matters if a caching layer in front of it is stripping the header before it reaches the browser. For a second opinion, several free online header-scanning tools will fetch a URL and flag missing or misconfigured headers without you needing to install anything; treat their output as a prompt to re-check the spec, not as a final grade.
'unsafe-inline' in script-src the moment CSP breaks something, which quietly cancels out most of what CSP was protecting against.report-uri or report-to directive, so violations happen silently in production and nobody finds out until something breaks visibly.preload before confirming that every subdomain, including the ones nobody remembers exist, actually serves valid HTTPS.Yes. These headers cost essentially nothing to send and apply uniformly across a site, so they belong in your global server or edge configuration rather than being added page by page.
By default, yes: a strict script-src without 'unsafe-inline' or a matching nonce will block inline <script> tags. The fix is to move scripts to external files served from an allow-listed origin, or use a per-request nonce, rather than relaxing the policy.
Yes, as a fallback. Pair frame-ancestors in your CSP with X-Frame-Options: DENY so the small set of clients that don't evaluate CSP's framing directive still get the protection.
Every browser that has the domain in its preload list will refuse to load it over plain HTTP, even if HTTPS is temporarily broken, and removal from major preload lists can take months. Confirm HTTPS works everywhere before adding preload.
Not directly. They're response headers, not render-blocking resources. The indirect effect is positive: HSTS removes an HTTP-to-HTTPS redirect hop, which shaves a small amount of load time off every first visit.
Often yes. Most CDNs, static-site hosts, and reverse proxies support setting headers through their own dashboard or a rules file, without touching origin server configuration at all.
Any time you add a new third-party script, analytics tool, embed, or font provider, each one needs an entry in the relevant CSP directive, or it will simply fail to load.