HTTP Security Headers — Analysis
docAnalyze your browser's security headers. Check CSP, HSTS, X-Frame-Options, and other protections in practice.
HTTP security headers are instructions a server sends with its response that tell the browser how to handle the page: whether to allow framing, where resources may load from, how long to insist on HTTPS, and what browser features the page may use. They are not a firewall and they do not fix vulnerabilities in the application itself, but they define the browser-side rules that determine how an attack attempt behaves once it reaches the page.
HSTS: forcing HTTPS and its costs
HTTP Strict Transport Security tells the browser that the site must be reached over HTTPS on future visits, so a downgrade attempt to plain HTTP is refused before it starts. The core parameters matter:
- max-age. How long, in seconds, the browser remembers the rule. A short age is a reversible test; a long age commits future visits to HTTPS.
- includeSubDomains. Extends the rule to every subdomain of the host. If any subdomain cannot serve HTTPS, that property breaks it.
- preload. Requests inclusion in browser shipped lists, so the HTTPS rule applies on the very first visit. Preload is hard to reverse: once a domain enters those lists, withdrawal takes time and the listing must be removed deliberately.
A common mistake is enabling preload or includeSubDomains before every subdomain and staging environment supports valid certificates. The result is breakage that looks like an outage rather than a security setting.
Content Security Policy: restricting where resources come from
Content Security Policy tells the browser which sources may supply scripts, styles, images, connections and other resources. The default source acts as the fallback; specific directives override it for each resource type. It is the main defense against injected content running in the page.
- Allowlist versus nonce or hash. Listing trusted origins works for known third parties; a per-request nonce or a cryptographic hash of inline code covers scripts that cannot be moved to external files.
- Report-only mode. A report-only policy monitors what would have been blocked without blocking it. It is the sane way to roll out a CSP: observe violations first, then enforce.
- Common over-permissiveness. A broad wildcard, allowing arbitrary inline script, or permitting scripts from large shared CDNs weakens the policy to the point where it blocks little.
The remaining response headers
| Header | Purpose | Frequent misconfiguration |
|---|---|---|
| X-Frame-Options / frame-ancestors | Controls whether the page may be embedded in a frame, against clickjacking | Legacy X-Frame-Options is limited to one directive; frame-ancestors in CSP is the modern replacement |
| Referrer-Policy | Controls how much of the source URL is sent when navigating to another site | Leaving the default can leak full paths and query strings to third parties |
| Permissions-Policy | Restricts browser features such as camera, microphone, geolocation and sensors per origin | Granting every feature the page could use, rather than only what it needs |
| X-Content-Type-Options: nosniff | Stops the browser from guessing a file type away from the declared MIME type | Missing on downloads and mixed content paths, enabling type-confusion handling |
| COOP / COEP / CORP | Govern cross-origin isolation: window access, resource loading and process sharing | Enabling COEP without preparing subresources to allow cross-origin loading breaks the site |
How to read a header result
A header inspection tool lists each response header with its value. You can also inspect responses in the browser's developer tools network panel, or request headers with a simple head request from the command line. Read each header against the site's actual needs, not against a generic checklist.
- Confirm the header is present on the real responses. Some servers send headers only on the main document, not on static assets or error pages.
- Read the value, not just the name. A CSP that allows everything and an HSTS with a tiny max-age carry little protection.
- Check interactions. COEP can block third-party scripts and images; an aggressive referrer policy can break partner redirects. Headers act on the whole page and its subresources.
- Compare report-only and enforced state. If a CSP exists in report-only only, violations are recorded, not stopped.
Common misreads
- "A CSP header means the site is secure." CSP limits how injected content can run. It does not remove the underlying injection flaw, and a permissive policy blocks almost nothing.
- "HSTS preload is free extra protection." It locks the domain and its subdomains into HTTPS by browser default. A broken certificate or an HTTP-only subdomain under that scope causes real outages before the listing can be undone.
- "More headers always mean safer." Misconfigured isolation headers break legitimate integrations, and redundant legacy headers do not add protection beyond the modern directives.
- "Headers protect against server-side breaches." They govern browser behavior. A stolen database, exposed credentials or compromised backend remains fully exposed regardless of response headers.
Frequently asked questions
Which header matters most for an ordinary site?
HSTS with a sensible max-age and a tight CSP that restricts script sources address the most common browser-side risks. The exact policy depends on the third-party scripts the site actually loads.
Can headers compensate for a missing security patch?
No. They may change how an exploit behaves in the browser, but the vulnerable component still exists. Patching and access controls remain the primary fixes.
What does report-only CSP tell me before I enforce it?
It reports which resources and inline code would have been blocked, without stopping the page. Use that report to fix the allowlist or migrate inline scripts, then switch the policy to enforcement.