Skip to main content

What is HSTS (HTTP Strict Transport Security)?

Glossary image
HTTP Strict Transport Security HSTS header Strict-Transport-Security

HTTP Strict Transport Security (HSTS) is a web security policy mechanism that instructs browsers to communicate with a server exclusively over HTTPS, preventing any unencrypted HTTP connections for a defined period of time. Rather than relying on users or redirects to enforce secure connections, HSTS shifts that responsibility to the browser itself, making the enforcement automatic and consistent.

How HSTS Works

When a browser receives a response from a server that includes the Strict-Transport-Security HTTP response header, it records that domain as an HSTS host. For the duration specified in the header's max-age directive, the browser will refuse to load any resources from that domain over plain HTTP, automatically upgrading any such requests to HTTPS before they even leave the device. This is a meaningful distinction from a standard HTTP-to-HTTPS redirect, because the upgrade happens locally, before a network request is made, eliminating the window of vulnerability that exists during a redirect.

A typical HSTS header looks like this: Strict-Transport-Security: max-age=31536000; includeSubDomains; preload. The max-age value sets how long, in seconds, the browser should enforce the policy. The optional includeSubDomains directive extends the policy to all subdomains, and preload signals intent to be included in browser-maintained HSTS preload lists, which hardcode the policy directly into browsers like Chrome, Firefox, and Safari so that even the very first visit to a site is protected.

Why HSTS Matters for Security

Without HSTS, a site that redirects HTTP traffic to HTTPS is still vulnerable during that initial, unencrypted request. An attacker positioned between the user and the server, a scenario known as a man-in-the-middle attack, can intercept the HTTP request before the redirect occurs and downgrade the connection. HSTS closes this gap by ensuring the browser never attempts an insecure connection in the first place. This makes it a critical complement to encryption at the transport layer.

Implementation Risks and Misconfiguration

While HSTS significantly strengthens a site's security posture, it carries real risks if misconfigured. Setting a long max-age value, which is recommended for security, means that any lapse in a valid HTTPS certificate will make the site completely inaccessible to returning visitors for the duration of the policy. There is no simple override for end users. Similarly, enabling includeSubDomains without first confirming that every subdomain supports HTTPS can break parts of a site or application unexpectedly. Submitting a domain to the HSTS preload list is effectively irreversible in the short term, so it should only be done when HTTPS is fully stable and permanent across the entire domain. A cautious approach is to start with a short max-age value, verify everything functions correctly, and then increase it incrementally.

Have a question?

Get in touch if you'd like to learn more about this topic.

Contact Us