skip to content

When you enable HSTS on Cloudflare's Edge Certificates page, what do its settings control, and which later changes lock visitors out?

level: middleimportance: should knowfreq 38%

answer

  1. one header for the whole zone
  2. Max Age Header counted in months
  3. HTTPS must keep working
  4. gray clouds and pausing hurt

basics

~20 s

Cloudflare's HSTS setting sends Strict-Transport-Security on the zone's HTTPS responses, with a Max Age Header of 1 to 12 months and optional includeSubDomains, Preload and No-Sniff. Afterwards, anything that breaks HTTPS, such as DNS-only records or pausing Cloudflare, locks returning browsers out.

solid answer

~40 s

HSTS sits on the **Edge Certificates** page (API zone setting `security_header`) on every plan. Turning it on makes Cloudflare send `Strict-Transport-Security` on HTTPS responses only, never on plain HTTP. You choose a **Max Age Header** (Disable, or 1 to 12 months), **Apply HSTS policy to subdomains** (`includeSubDomains`), **Preload**, and an optional **No-Sniff Header** that adds `X-Content-Type-Options: nosniff`. The setting covers the whole zone; for one subdomain only, use a subdomain setup, the origin, or a response header Transform Rule. Because browsers remember the policy for the max-age, HTTPS must keep working: switching records to DNS only, pausing Cloudflare, moving nameservers away, redirecting HTTPS to HTTP, or a lapsed or mismatched certificate, including disabling Universal SSL with nothing else active, leaves those browsers unable to reach the site, with no click-through.

go deeper

for a junior

Know where the setting lives, the Edge Certificates page, and that it makes browsers insist on HTTPS for as long as the Max Age Header says.

for a middle

Explain each setting, why it applies zone-wide, how to scope HSTS to one subdomain instead, and which later changes leave returning visitors locked out.

for a senior

Plan a safe rollout: certificate coverage first, a short max-age, subdomain coverage after an inventory, preload last, and keep a written list of the changes that are off-limits afterwards.

for a principal

Treat preload as a long-term commitment for the whole domain, and agree who may change proxy status, nameservers or certificates once HSTS is live.

## What the setting does **HTTP Strict Transport Security (HSTS)** is a response header, `Strict-Transport-Security`, that tells a compliant browser to use only HTTPS for a host for a stated time and not to let the user click past certificate errors. On Cloudflare it is a zone setting on the **Edge Certificates** page, available on every plan; through the API it is the zone setting `security_header`. When it is on, Cloudflare serves the header on HTTPS requests to the zone. Plain HTTP responses never carry it, which is why HTTPS must already work before the setting is turned on. ## The settings | Setting | What it sends | Options | |---|---|---| | Enable HSTS (Strict-Transport-Security) | the header itself | Off / On | | Max Age Header | the `max-age` directive | Disable (0), or 1 to 12 months | | Apply HSTS policy to subdomains | `includeSubDomains` | Off / On | | Preload | `preload` | Off / On | | No-Sniff Header | a separate `X-Content-Type-Options: nosniff` header | Off / On | Enabling it means acknowledging a warning dialog first. The setting is quick to turn on and slow to undo, because each browser keeps the policy for the max-age it last saw. ## Scope: the whole zone - The setting applies across the zone; the Edge Certificates page has no per-hostname switch. - For one subdomain only, the docs offer three routes: give that subdomain its own zone with a **subdomain setup**, send the header from the origin, or add it with a **response header Transform Rule**. - With **Apply HSTS policy to subdomains**, the policy also reaches subdomains a browser has never visited, and any of them without working HTTPS becomes inaccessible. - **Preload** only adds the directive. Getting onto the browsers' preload list means submitting the domain yourself, and the list requires a Max Age Header of 12 months. ## What must stay true afterwards For as long as the max-age it published, every returning browser will insist on a valid certificate. Cloudflare's docs list what to avoid once HSTS is on: - changing DNS records from **Proxied** to **DNS only**, which hands TLS to the origin's own certificate; - **pausing Cloudflare** on the site, with the same effect; - pointing the nameservers away from Cloudflare; - redirecting HTTPS to HTTP; - letting the certificate become invalid, expired or mismatched, which includes disabling Universal SSL with no other certificate active, and a proxied hostname deeper than Universal SSL covers. The Universal SSL docs make the same point from the other side: before disabling Universal SSL, upload a custom certificate or buy Advanced Certificate Manager, because they list HSTS, Always Use HTTPS and HTTPS redirects among the setups that may produce errors once no valid edge certificate is left. If HTTPS goes away before HSTS is disabled and the old max-age has run out, the site is unreachable for those visitors for the rest of that max-age, or until HTTPS comes back. ## Turning it on safely 1. Confirm every proxied hostname has an edge certificate, including deep names that need Total TLS, an advanced certificate or a custom certificate. 2. Start with a short Max Age Header, such as 1 month, and watch for breakage. 3. Turn on subdomain coverage only after an inventory of every subdomain in use, including ones served outside Cloudflare. 4. Raise the Max Age Header to 12 months and turn on Preload last, and only if the whole domain will stay on HTTPS for good. ## Turning it off To back out, open the same HSTS settings, set **Max Age Header** to **0 (Disable)** and save; turn the No-Sniff Header off as well if it is no longer wanted. Browsers that visit again receive the zero max-age and drop the policy. Browsers that do not come back keep the old policy until their stored max-age runs out, so HTTPS has to keep working through that window.

  • Why is subdomain coverage risky on a zone that relies only on Universal SSL?
    On a full setup Universal SSL covers only the apex and first-level subdomains. A proxied name such as api.eu.example.com has no edge certificate, and once browsers hold an includeSubDomains policy they refuse to let users past the error. Cover deep names with Total TLS, an advanced or a custom certificate before turning the option on.
  • What does Cloudflare's Preload toggle do on its own, and what else does preloading need?
    The toggle only adds the `preload` directive to the header. To be preloaded, the domain must be submitted to the browsers' preload list, which requires a Max Age Header of 12 months. Once listed, browsers enforce HTTPS before the first visit, so a domain without HTTPS everywhere becomes unreachable.

  • Cloudflare's HSTS setting also sends the header on plain HTTP responses.
  • The Edge Certificates page can turn HSTS on for a single hostname in the zone.
  • Pausing Cloudflare is a safe way to debug the origin once HSTS is on.
  • Setting Max Age Header to 0 instantly frees browsers that never visit again.
  • HSTS on Cloudflare is a paid-plan feature.