# HTTP Security Headers: HSTS, nosniff, COOP, COEP, and Frame Ancestors

> Set HSTS, nosniff, Referrer-Policy, Permissions-Policy, COOP, COEP, CORP, frame-ancestors, and Clear-Site-Data on every response, errors included, then verify with curl.

**Quick answer:** Security headers tell the browser to constrain its own behavior: HSTS forces HTTPS, nosniff stops MIME confusion, Referrer-Policy limits URL leakage, Permissions-Policy gates powerful APIs, COOP/COEP/CORP separate origins, frame-ancestors and X-Frame-Options stop clickjacking, and Clear-Site-Data wipes local state on logout. Set them at the edge on every response, errors included, and verify with curl and DevTools.

## Key takeaways

- Security headers are browser-enforced constraints, not server-side authorization; they remove specific attack paths and do nothing for a compromised backend.
- HSTS protects returning visitors and preload closes the first-visit gap, but includeSubDomains and preload are long commitments that take months to undo.
- nosniff and Referrer-Policy are cheap universal defaults; Permissions-Policy needs an explicit allowlist because unknown feature names are ignored silently.
- COOP, COEP, and CORP answer different questions; enable COEP require-corp only when you need cross-origin isolation, because it breaks unprepared embeds.
- Headers must come from one edge layer on every response, including 404, 500, and redirects; curl against production is the only proof.

---

Security headers are instructions a server gives the browser about how to handle its own document and subresources. They do not authenticate users, validate input, or replace server-side authorization. What they do is remove classes of browser behavior that attackers rely on: accepting an insecure request, guessing a content type, leaking a URL through the Referer header, opening a powerful API without consent, sharing a process group with another origin, framing your interface, or leaving session data on a shared machine.

The distinction matters because a header can look correct in a configuration file while the production response never carries it. Every control here is enforced by the client, so its value depends on the browser, the response it arrives on, and the layer that emitted it. A strict policy on HTML does not cover JSON, redirects, or an nginx-generated 502 page. The operational half of the topic is verification: reading the bytes production returns across every response class.

## What security headers can and cannot prevent

Think of the headers in this guide as a narrow contract between the origin and the browser. HSTS constrains transport, nosniff constrains type interpretation, Referrer-Policy constrains what leaves with a request, Permissions-Policy constrains feature access, COOP, COEP, and CORP constrain cross-origin relationships, frame-ancestors constrains embedding, and Clear-Site-Data constrains what remains stored after logout. Each one removes a specific primitive that a browser would otherwise offer to an attacker who can influence a URL, a response, or a document.

None of them stops SQL injection, broken access control, a leaked bearer token, or a compromised dependency. They shrink the browser-side blast radius of those failures. HSTS prevents a downgraded login page, nosniff prevents an uploaded file from executing as script, and frame-ancestors prevents a logged-in user from clicking a hidden transfer button. When the backend itself is compromised, headers are irrelevant.

A header that is misspelled, duplicated, or applied only to application routes is worse than no header, because it creates the appearance of control without the behavior. Start by inventorying what production returns. The [HTTP header analyzer](/tools/http-headers) parses a captured response and separates what the origin, proxy, and CDN each contributed, which is usually the first surprise in an audit.

## HSTS: max-age, includeSubDomains, and preload

`Strict-Transport-Security` tells the browser that this host, and optionally its subdomains, must only be contacted over HTTPS for a number of seconds. It is the practical defense against SSL stripping: an attacker who can rewrite the first HTTP request can keep the victim on plain HTTP before the redirect to HTTPS arrives. The header is ignored when delivered over HTTP, so it must be sent on a valid HTTPS response with a trusted certificate.

A production policy looks like `Strict-Transport-Security: max-age=63072000; includeSubDomains; preload`. `max-age` is the commitment window in seconds; 63,072,000 is two years. `includeSubDomains` extends the rule to every name below the current host, including hosts that may not exist yet. `preload` asks browser vendors to ship the domain in their built-in HSTS list, which closes the first-visit gap; acceptance typically requires a valid certificate, a redirect from HTTP, a max-age of at least one year, and `includeSubDomains`. The `preload` token does nothing by itself, and removal from browser lists takes months.

The common failures are predictable. A one-week max-age expires before the next audit and recreates the downgrade window. Sending HSTS only on the apex while `www` still redirects loses protection for the host users actually type. Enabling `includeSubDomains` before an internal tool has a certificate breaks that tool immediately and is difficult to reverse. Setting `max-age=0` removes the policy only after the browser receives that response over HTTPS; it does not recall copies already stored elsewhere. Most teams should start with a short max-age, raise it after monitoring, add `includeSubDomains` after a subdomain inventory, and submit to the preload list last.

## X-Content-Type-Options and Referrer-Policy

`X-Content-Type-Options: nosniff` disables MIME sniffing. Modern browsers refuse to execute a script whose declared type is not a JavaScript type and refuse to apply a stylesheet whose declared type is not `text/css`. Without the header, a response labeled `text/plain` or `image/png` can be interpreted as HTML or JavaScript in some contexts, which turns an upload endpoint or a misconfigured proxy into a script execution path. The header is cheap, has no compatibility cost when types are correct, and belongs on every response, not only on static assets.

`Referrer-Policy` controls how much of the current URL is attached to navigations and subresource requests. That URL may contain a password-reset token, a session identifier in a query string, an internal hostname, or a customer number. `strict-origin-when-cross-origin` is the modern browser default: it sends the full URL for same-origin requests, only the origin for cross-origin HTTPS requests, and nothing when the destination is downgraded to HTTP. `no-referrer` is stricter but breaks affiliate attribution, some analytics, and partner flows that expect a source. `same-origin` hides the referrer from every other site while preserving it internally. Choose deliberately per route rather than copying the strictest value everywhere.

A meta referrer tag can set a document-level policy, but the response header is the authoritative default and also covers non-HTML responses. If you maintain a legacy meta tag, keep it consistent with the header; a page that sends `no-referrer` and also claims `unsafe-url` in markup creates a policy conflict that is hard to debug.

## Permissions-Policy: gating features without breaking integrations

`Permissions-Policy` controls which powerful browser features the document and its iframes may use: camera, microphone, geolocation, payment, USB, fullscreen, autoplay, and dozens more. It replaces the older `Feature-Policy` header, whose syntax is different enough that copied policies often do nothing. A modern policy names a feature and an allowlist, for example `Permissions-Policy: geolocation=(), camera=(), microphone=(), payment=(self "https://checkout.example.com")`.

The syntax has three useful forms. `()` blocks the feature for the document and every frame. `(self)` allows the current origin. `*` allows every origin and usually defeats the purpose. A quoted origin grants a specific partner, and a feature may combine `self` with several quoted origins. Unknown feature names are ignored, which is convenient for forward compatibility and dangerous for audits: a typo produces no error and no protection. Keep the policy in version control and lint feature names against the current registry.

Blocking a feature in the header does not automatically grant it to an embedded frame. The embedding document must also delegate it with the iframe `allow` attribute, and a frame cannot receive a feature the parent does not hold. Test payment, maps, video-call, and authentication widgets after tightening the policy, because `camera=()` on a support page that hosts a call widget is a production outage disguised as hardening. Reproduce the exact document request with the [HTTP request workbench](/tools/http-request) to confirm that proxies and CDNs preserve the header unchanged.

## COOP, COEP, and CORP: three different isolation boundaries

The three `Cross-Origin-*` headers are often enabled together and then blamed as one feature, but they answer separate questions.

`Cross-Origin-Opener-Policy` tells the browser whether a document may share a browsing context group with a cross-origin opener. `same-origin` severs `window.opener` ties to cross-origin windows and places the document in its own group; `same-origin-allow-popups` keeps popups it opens alive but isolates other references; `unsafe-none` is the default. COOP mitigates cross-window attacks such as XS-Leaks and some Spectre-style scenarios, and it breaks OAuth or payment popups that call back through `window.opener`, which is exactly why the allow-popups variant exists.

`Cross-Origin-Embedder-Policy` requires every cross-origin subresource to opt in through CORP or CORS. `require-corp` is the strict mode; `credentialless` allows no-cors requests without credentials. COEP is the gate to `crossOriginIsolated`, which unlocks `SharedArrayBuffer` and high-resolution timers. Enabling it globally without auditing images, fonts, scripts, and iframes produces broken pages, often only in production where third-party assets differ from staging.

`Cross-Origin-Resource-Policy` is set by the resource, not by the document. `same-origin` prevents other origins from loading the response in no-cors mode, `same-site` allows same-site origins, and `cross-origin` opts out. It protects private JSON, user uploads, and fonts from being embedded by another site, and it is required on your own subresources when a consuming page enforces COEP. CORS and CORP are not interchangeable: CORS grants a fetch client permission to read a response, while CORP blocks cross-origin no-cors embedding of the resource. A missing CORP header on a public logo is harmless; a missing CORP header on a private avatar endpoint can leak content through a cache or a side channel.

## X-Frame-Options versus CSP frame-ancestors

`X-Frame-Options: DENY` or `SAMEORIGIN` prevents a document from being rendered inside a frame. It was the first clickjacking defense and is still worth sending for older browsers. Its weaknesses are structural: `ALLOW-FROM` was never supported consistently and is ignored by Chrome and modern Firefox, the header cannot express more than one allowed origin, and duplicate headers from a proxy and an application can produce contradictory instructions.

CSP `frame-ancestors` is the modern replacement. `frame-ancestors 'none'` blocks all embedding, while `frame-ancestors 'self' https://partner.example.com` allows the origin and one named partner. It accepts multiple sources, applies to redirects more predictably, and takes precedence in browsers that support both mechanisms. It is ignored in a meta tag, so a meta-only deployment cannot enforce it. A typical response carries `X-Frame-Options: SAMEORIGIN` for legacy clients and `Content-Security-Policy: frame-ancestors 'self' https://partner.example.com` for modern ones.

Clickjacking survives when the defense is applied only to the login page. An attacker can frame any page that performs a state-changing action, including settings, checkout, and admin consoles, and overlay invisible controls on top of it. Apply framing protection to every HTML response, including error pages, and do not rely on JavaScript frame-busting. A [meta tag generator](/tools/meta-tag-generator) can produce document metadata, but `frame-ancestors` has no meta equivalent; only a response header enforces it.

## Clear-Site-Data and what headers cannot do

`Clear-Site-Data` tells the browser to delete stored data for the current origin after a response: `"cache"`, `"cookies"`, `"storage"` for localStorage, IndexedDB and service workers, and `"executionContexts"`. It is the correct header for a logout endpoint on a shared device, because deleting a cookie on the server does not remove the browser's cached HTML, a localStorage token, or a service worker that can keep serving authenticated pages.

Send it on the logout response over HTTPS with `Cache-Control: no-store`, and make sure the browser actually processes that response. A cross-origin redirect or an opaque error response can prevent clearing, and `Clear-Site-Data: "*"` wipes everything, which is rarely appropriate. The header cannot revoke a stolen bearer token, terminate a server-side session, or clear another origin's storage; those remain server-side and scope decisions.

The same boundary applies to every header in this guide. Headers cannot enforce authorization, encrypt a response, validate a JWT, or replace output encoding. They are requests to a cooperating browser, and a non-browser client can ignore every line of them. Treat them as defense in depth, not as the defense.

## Header matrix for common response types

Use this matrix as a reviewed baseline to discuss, not a score to maximize. Each value has a cost, and the correct answer depends on whether the response is a document, an API payload, a static asset, or a redirect. A document response carrying the baseline looks like this:

```http
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Strict-Transport-Security: max-age=63072000; includeSubDomains
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: geolocation=(), camera=(), microphone=()
Cross-Origin-Opener-Policy: same-origin
Content-Security-Policy: frame-ancestors 'self'
```

| Header | Typical value | What it reduces | Common misconfiguration |
| --- | --- | --- | --- |
| `Strict-Transport-Security` | `max-age=63072000; includeSubDomains; preload` | protocol downgrade and SSL stripping | enabling `includeSubDomains` before every host has HTTPS |
| `X-Content-Type-Options` | `nosniff` | MIME confusion and upload-based script execution | trusting `Content-Type` alone on user files |
| `Referrer-Policy` | `strict-origin-when-cross-origin` | URL, token, and internal-host leakage | using `unsafe-url` or inconsistently overriding it |
| `Permissions-Policy` | `geolocation=(), camera=(), microphone=()` | feature abuse and permission-prompt spam | copying legacy `Feature-Policy` syntax |
| `Cross-Origin-Opener-Policy` | `same-origin` or `same-origin-allow-popups` | cross-window leaks and opener abuse | breaking OAuth popups that need `window.opener` |
| `Cross-Origin-Embedder-Policy` | `require-corp` only when isolation is needed | cross-origin reads and timing attacks | enabling it globally without auditing subresources |
| `Cross-Origin-Resource-Policy` | `same-origin` or `same-site` | cross-origin embedding of private resources | setting `cross-origin` on private JSON or uploads |
| `X-Frame-Options` | `DENY` or `SAMEORIGIN` | clickjacking in legacy browsers | using obsolete `ALLOW-FROM` |
| CSP `frame-ancestors` | `'none'` or a short origin list | clickjacking in modern browsers | expecting a meta tag to enforce it |
| `Clear-Site-Data` | `"cache", "cookies", "storage"` on logout | session residue on shared devices | assuming it revokes the server session |

Two rows deserve emphasis. `includeSubDomains` and `preload` are commitments, not toggles; do not enable them until every subdomain has a valid certificate and an HTTPS listener. `COEP: require-corp` is not a default hardening header; it is an isolation switch that breaks third-party embeds that have not adopted CORP or CORS. The safe baseline for most sites is HSTS, nosniff, `strict-origin-when-cross-origin`, a narrow Permissions-Policy, frame-ancestors, and COOP. Add COEP and CORP when the application actually needs cross-origin isolation.

## Why every response, including errors, needs the same policy

The most common production failure is not a wrong value; it is a missing header on a response class nobody tested. Application middleware often sets security headers on routes that render HTML, then returns early for `401`, `403`, `404`, and `500`. A reverse proxy may generate its own error page when the upstream is down, and that page never passes through the application. A CDN may strip or append headers on cached responses. The result is a site that passes a homepage scan and loses framing protection, referrer policy, and MIME protection exactly when an error page reflects user input or exposes a stack trace.

Errors deserve the same policy because they are still documents. A `500` page can be framed, sniffed, and leak its URL through Referer. HSTS must be present on the HTTPS response that follows the redirect from HTTP, or the first hop remains downgradable. `Clear-Site-Data` must survive the logout flow even if the session is already invalid. JSON error bodies should carry `no-store` and nosniff, and they should never echo tokens or internal hostnames.

Enforce headers at the outermost layer you control: a CDN rule, a reverse proxy, or framework middleware that wraps every response, including errors and redirects. Then test the layer, not the configuration. Duplicate security headers are a real failure mode: two `X-Frame-Options` values or two HSTS values can be interpreted inconsistently, and a proxy that appends instead of replaces turns a correct origin policy into an ambiguous one.

## Verification checklist with concrete pass criteria

Verify from the public edge, over HTTPS, in the same order a browser encounters the response. Start with curl because it shows the bytes without a cache or an extension rewriting them:

```bash
# 1. Inspect the security headers on a normal document
curl -sSI https://www.example.com/ | grep -iE '^(strict-transport-security|x-content-type-options|referrer-policy|permissions-policy|cross-origin-(opener|embedder|resource)-policy|x-frame-options|content-security-policy):'

# 2. Repeat for an error page and for the HTTP redirect
curl -sSI https://www.example.com/does-not-exist | grep -iE '^(strict-transport-security|x-content-type-options|referrer-policy|x-frame-options|content-security-policy):'
curl -sSI http://www.example.com/ | grep -iE '^(HTTP/|location|strict-transport-security):'

# 3. Check the logout response without following redirects
curl -sS -D - -o /dev/null -X POST -H 'Cookie: session=test' https://www.example.com/logout | grep -iE '^(HTTP/|clear-site-data|cache-control):'
```

Then open DevTools, load the same URL, and inspect the Network panel's response headers. The Security panel reports HSTS and certificate state, the Console reports CSP and COOP/COEP warnings, and `document.crossOriginIsolated` in the Console confirms whether isolation is active. Disable the cache and repeat, because an old response can hide a header regression. Finish in a second browser and a private window, since header support and default referrer policies differ.

Treat a check as passed only when every row holds:

| Check | How to test | Pass criteria |
| --- | --- | --- |
| HSTS delivery | `curl -sSI https://www.example.com/` | Header present with `max-age` of at least 31,536,000; `includeSubDomains` only after inventory |
| HTTP redirect | `curl -sSI http://www.example.com/` | `301` or `308` to HTTPS; no content served over HTTP |
| MIME protection | Request a script, a stylesheet, and an API response | `nosniff` present on all; declared types match the payload |
| Referrer leakage | Click a cross-origin link from a page with a query string | Cross-origin `Referer` contains the origin only, never the path or query |
| Permissions policy | Exercise a blocked feature in an iframe and an allowed partner | Blocked call fails and logs a policy warning; partner call succeeds |
| Framing | Load a page in an iframe from another origin | Frame is refused; `frame-ancestors` present; no legacy header conflict |
| Isolation | Evaluate `document.crossOriginIsolated` in the Console | `true` only on pages that intentionally enable COEP and CORP |
| Error and logout paths | Repeat curl checks on 404, 500, and logout | Same security headers; `Clear-Site-Data` on logout; `no-store` on sensitive responses |

A header is only real when it appears on the response the user received. Treat the matrix as a code-reviewed default, the edge as the enforcement point, and this checklist as the release gate.

## Frequently asked questions

### Does HSTS includeSubDomains break subdomains that only serve HTTP?

Yes. Once a browser sees includeSubDomains over HTTPS, it refuses plain HTTP for every subdomain under that name, so an internal tool, a legacy portal, or a staging host without a certificate becomes unreachable. Inventory subdomains before enabling it, and add the directive only after every host has a valid certificate and an HTTPS listener.

### Why is X-Content-Type-Options: nosniff needed when Content-Type is correct?

Because one wrong response is enough. A proxy, upload endpoint, or legacy handler can label an HTML or JavaScript payload as an image, and without nosniff some browsers sniff the bytes and execute them. nosniff makes the declared type authoritative for scripts and styles, turning a content-type mistake into a harmless download instead of script execution.

### What is the difference between X-Frame-Options and CSP frame-ancestors?

X-Frame-Options is the older header and accepts only DENY or SAMEORIGIN; ALLOW-FROM is obsolete and ignored. CSP frame-ancestors accepts a list of origins and schemes, works across redirects more predictably, and takes precedence in browsers that support it. Send both, using frame-ancestors for the real policy and X-Frame-Options as a fallback for old clients.

### Do COOP and COEP belong on API responses as well as HTML?

COOP and COEP are document policies and have no effect on a JSON payload fetched by script. They belong on HTML responses that need process isolation or protection from cross-window attacks. CORP is the opposite: it is set on the resource, so it belongs on images, fonts, scripts, and private JSON that other origins might try to embed.

### Why do security headers disappear on 404 and 500 responses?

Application middleware commonly adds headers on routes that render HTML and returns early for errors, while a reverse proxy generates its own error page when the upstream is unavailable. Put the policy at the outermost layer that handles every response, then test 404, 500, redirect, and logout paths with curl instead of assuming the framework covers them.

## References

- [RFC 6797: HTTP Strict Transport Security](https://www.rfc-editor.org/rfc/rfc6797)
- [W3C: Referrer Policy](https://www.w3.org/TR/referrer-policy/)
- [MDN: Permissions-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Permissions-Policy)
- [OWASP Secure Headers Project](https://owasp.org/www-project-secure-headers/)

---

- Canonical: https://www.jsonmind.com/guides/http-security-headers
- Locale: en
- Published: 2026-11-17
- Updated: 2026-11-17
- Tools: http-headers, http-request, meta-tag-generator