Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

What Is HSTS? How Browsers Enforce HTTPS

See how the HSTS header upgrades HTTP links to HTTPS, what preloading changes, and how to roll out the policy safely.

Table of Contents

HTTP Strict Transport Security (HSTS) is a browser policy that requires HTTPS for a website. Once a browser remembers the policy, it upgrades an HTTP URL for that host to HTTPS before sending the request. This protects the connection from being downgraded to unencrypted HTTP. If HTTPS fails because of a certificate error, the browser blocks access.

What is HSTS? How does it work? Picture 1

How HSTS works

A website sends the Strict-Transport-Security response header over HTTPS. The browser ignores the header if it arrives over HTTP. For a site the browser has never visited, the first HTTP request can still reach the network before a redirect. A browser's HSTS preload list can close that gap.

What is HSTS? How does it work? Picture 2
How HTTP Strict Transport Security works
Strict-Transport-Security: max-age=31536000; includeSubDomains
  • max-age is how long the browser remembers the policy, in seconds. The example sets it to one year. A fresh HTTPS response with the header resets that timer.
  • includeSubDomains extends the policy to subdomains. Leave it out until every affected web hostname is ready to serve HTTPS.

HTTPS provides encryption and authenticates the server. HSTS tells the browser when HTTPS is mandatory. The guide to URL schemes explains where HTTP and HTTPS appear in a web address.

How to enable and test HSTS

  1. Set up HTTPS with a valid certificate and redirect HTTP traffic to the matching HTTPS URLs.
  2. Send Strict-Transport-Security on HTTPS responses from your server or CDN. Start with a short max-age so mistakes expire quickly, then increase it after testing.
  3. Open the browser's Network panel and reload the HTTPS page. Select the document request and check that the response headers contain the intended value. Repeat the check for each hostname where you expect the header.

Check older subdomains before expanding the policy. If a site becomes unreachable after deployment, start by diagnosing the TLS certificate and connection.

When to consider HSTS preloading

Preloading lets browsers with the updated list enforce HTTPS even on the first visit. To qualify, the base domain needs a valid certificate, an HTTP-to-HTTPS redirect, and an HTTPS response with a max-age of at least one year plus includeSubDomains and preload. Confirm that affected subdomains support HTTPS and use the HSTS preload checker for the full requirements and submission. Adding the directive alone does not put the domain on the list.

If you need to withdraw a remembered policy for a host, serve Strict-Transport-Security: max-age=0 over valid HTTPS. A parent domain's policy can still apply to its subdomains. A preloaded domain needs a separate preload removal request, and users receive the change through browser updates.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.