How to Enable Cloudflare HSTS Safely Without Locking Out Subdomains

Turning on HTTP Strict Transport Security (HSTS) in Cloudflare is a one-click toggle in the dashboard, which makes it dangerously easy to break a staging site, legacy subdomain, or internal tool for months. Once a visitor’s browser receives a long Strict-Transport-Security header, it refuses plain HTTP connections to that hostname—and if includeSubDomains or preload is enabled prematurely, even fixing the server certificate afterward will not help visitors whose browsers already cached the policy.

Editorial illustration of safely enabling Cloudflare HSTS without locking out subdomains

Editorial illustration: confirm Full (strict) encryption and test every subdomain before extending HSTS max-age.

Summary

  • HTTP Strict Transport Security (HSTS) tells browsers to connect strictly over HTTPS and blocks users from clicking through SSL certificate warnings.
  • Before enabling HSTS, set Cloudflare’s SSL/TLS mode to Full (strict) with valid origin certificates and audit every active subdomain.
  • Roll out HSTS in stages: start with a short max-age (such as 5 minutes or 1 hour) without includeSubDomains or preload, then extend to 6 or 12 months only after testing.
  • Treat the HSTS Preload flag as a long-term commitment because removing a domain from browser preload lists can take months.

What HSTS actually does (and why redirects alone are not enough)

Many site owners assume turning on Always Use HTTPS in Cloudflare is the same as HSTS. They solve two different parts of the connection:

  • Always Use HTTPS sends a 301 redirect when a browser requests http://. That first plaintext HTTP request still crosses the network before the redirect arrives, leaving a brief window where an attacker on public Wi-Fi could intercept or downgrade the connection.
  • HSTS sends a Strict-Transport-Security response header over HTTPS. Once a browser reads that header, it automatically upgrades future http:// requests locally before sending anything over the network and refuses to let users bypass broken certificate warnings.

That strictness is why HSTS protects users on untrusted networks—and why misconfiguring it causes painful lockouts.

Prerequisites before you touch HSTS

  1. Switch Cloudflare SSL/TLS to Full (strict). As documented in Cloudflare’s Full (strict) encryption guide, Flexible mode talks to your origin over unencrypted HTTP, while Full (strict) enforces a valid, trusted origin certificate (such as a Cloudflare Origin CA certificate or Let’s Encrypt). Never pair HSTS with Flexible SSL.
  2. Inventory all subdomains in your DNS zone. List www, staging, dev, mail, webmail, cdn, and any legacy CNAMEs. If staging.example.com has an expired certificate or only serves HTTP, enabling includeSubDomains will make it unreachable in modern browsers.
  3. Check for mixed content and hardcoded http:// origin links. Confirm your CMS (WordPress or Drupal) serves assets over HTTPS cleanly so pages do not break once browsers refuse HTTP fallback.

Step-by-step: Safe HSTS rollout in Cloudflare

1. Open Edge Certificates in the Cloudflare dashboard

Per Cloudflare’s HSTS documentation, go to your zone in the Cloudflare dashboard, navigate to SSL/TLS > Edge Certificates, locate HTTP Strict Transport Security (HSTS), and click Enable HSTS (reading and acknowledging the warning prompt).

2. Start with a short max-age and conservative flags

On day one, choose the shortest max-age that lets you verify behavior safely:

  • Max Age Header (max-age): Start with 5 minutes or 1 hour during your initial check. If something breaks, browsers forget the policy quickly instead of locking out visitors for a year.
  • Apply HSTS to subdomains (includeSubDomains): Leave Off initially unless you have already verified HTTPS on every single subdomain.
  • Preload: Leave Off during testing.
  • No-Sniff Header (X-Content-Type-Options: nosniff): Safe to enable on most modern sites, though verify it does not break any poorly typed legacy assets.

3. Verify the header with curl

Test an HTTPS response from your terminal:

curl -I https://example.com

Confirm strict-transport-security: max-age=300 (or your chosen duration) appears in the response headers. Note that Cloudflare only sends the HSTS header over HTTPS connections—never over plain HTTP—and only for proxied (orange-clouded) DNS records. If a subdomain is DNS-only (gray-clouded), your origin server must send its own HSTS header if needed. For broader DNS and edge checks, see our guide on debugging DNS propagation delays with dig and nslookup and purging a stale page on Cloudflare.

4. Ramp up duration after 48 hours of clean monitoring

Once you have confirmed zero certificate warnings, zero broken webhooks, and clean subdomain access:

  1. Increase max-age to 1 month, then 6 months or 12 months (31536000 seconds).
  2. Enable includeSubDomains only after confirming every active subdomain serves valid HTTPS.
  3. Enable Preload only if you intend to submit the domain to browser preload lists and commit to maintaining HTTPS across the entire domain and all subdomains indefinitely.

Common mistakes

  • Enabling Preload and includeSubDomains on the first click. If you later spin up an unencrypted local/staging subdomain under the same apex domain, browsers with the preload list built in will block access completely.
  • Leaving max-age at 0 permanently. Setting max-age=0 tells browsers to clear HSTS, which is useful as an emergency rollback—not as a production protection setting.
  • Assuming HSTS covers gray-clouded (DNS-only) records. Cloudflare’s Edge Certificates settings only apply to traffic proxied through Cloudflare.
  • Forgetting origin certificate renewals. Because HSTS forbids users from clicking “Proceed anyway” on certificate errors, an expired origin cert under Full (strict) becomes a hard outage. Combine HSTS with reliable certificate renewal monitoring and HTTPS hygiene basics.

Why this matters

HSTS closes the “first HTTP hop” gap that simple 301 HTTPS redirects leave open, protecting visitors on airport, cafe, and hotel Wi-Fi. Rolling it out in measured stages gives you that security without turning a forgotten staging subdomain into an unrecoverable support ticket.

My Take

Enable HSTS on every production domain you control, but treat max-age like a dimmer switch rather than a light switch. Five minutes on day one, a week of checking subdomains, and then moving to six or twelve months gives you all the protection with almost none of the risk. Skip Preload unless your organization owns every subdomain under that domain name for good.

Conclusion

Confirm Full (strict) SSL/TLS and valid certificates across your apex domain and subdomains first, enable HSTS in Cloudflare with a short initial max-age, verify headers with curl -I, and ramp up to 6–12 months only after testing.

Sources