← Glossary

What Is HSTS (HTTP Strict Transport Security)?

HSTS is a browser policy, declared by a site through the Strict-Transport-Security header, that makes the browser use HTTPS for that host for a stated period and refuse to proceed past TLS errors.

Updated:

HSTS, or HTTP Strict Transport Security, is a mechanism by which a website tells browsers to contact it over HTTPS and nothing else. The site sends a Strict-Transport-Security response header on a secure connection, and the browser records the host as one that must be reached securely for the number of seconds given in the header. From then on, any attempt to load an http:// address for that host is rewritten to https:// before a request leaves the browser, and a TLS failure for that host becomes a hard stop with no option to click through. The mechanism is specified in RFC 6797 and is widely supported by modern browsers.

The policy is remembered by the browser, not enforced by the network. That distinction matters because it means HSTS protects a user even on a hostile Wi-Fi network where an attacker controls what plain HTTP responses look like: the browser never sends the plain request in the first place. It also means the protection exists only where the browser already knows a policy for the host, which is why preloading exists as a separate step.

How Browsers Remember HSTS

A server sends Strict-Transport-Security with a max-age value over valid HTTPS. The browser stores the host’s policy until the current time plus that many seconds; receiving another valid header refreshes the expiry. Merely continuing to visit the site does not extend a policy if its responses stop carrying the header.

Two safeguards keep the mechanism from being abused. RFC 6797 requires browsers to ignore the header when it arrives over plain HTTP, since an attacker on the path could otherwise inject or expire a policy at will. For the same reason, the header has no effect when the certificate presented was not trusted, because a successful attacker could then set a policy on behalf of a victim site. Only authentic secure responses change the browser's state.

Once a host is known, two behaviours apply. First, the browser upgrades insecure requests: typing the hostname without a scheme, following an old http:// bookmark or being redirected to http:// all result in an HTTPS request. Second, warnings become errors. If the certificate is expired, mismatched or untrusted, the browser terminates the connection and shows a page that cannot be bypassed. For a known HSTS host, RFC 6797 requires termination on certificate errors without letting the user proceed through the warning.

max-age, Subdomains and Preloading

Three directives shape the policy.

DirectiveMeaningNotes
max-age=secondsHow long the browser treats the host as HSTS-protectedRequired. max-age=0 removes that host’s dynamic policy; inherited and preload policies are separate. Values of one year (31536000) or two years (63072000) are common.
includeSubDomainsExtends the policy to every subdomain of the hostOptional. Applies to hosts the browser has not visited, so HTTP services on affected subdomains need working HTTPS.
preloadSignals consent to inclusion in browser preload listsNot part of RFC 6797; a convention used by the hstspreload.org submission process.

A short max-age makes early deployment easier to reverse, but expires sooner for infrequent visitors. Long policies provide lasting protection and require reliable HTTPS. Lowering the value or setting it to zero only affects a browser once it receives the new header over a valid secure connection.

HSTS preload addresses the gap before a browser has ever seen the header. Chromium maintains a list of hosts compiled into the browser, and Firefox, Safari and Edge derive their own lists from it. A domain qualifies for submission when it serves a valid certificate, redirects HTTP to HTTPS on the same host, supports HTTPS on affected subdomain web services, and sends an HSTS header on the base domain with max-age of at least one year, includeSubDomains and the preload directive. The preload site warns that inclusion cannot easily be undone: removal propagates through browser releases over a period of months, and other vendors are not bound to follow. A preloaded domain with one subdomain that cannot do HTTPS has a problem that no server configuration can fix quickly.

HSTS vs Redirects and Certificate Validation

An HTTP-to-HTTPS redirect commonly accompanies HSTS but does a different job. The redirect only happens after the browser has sent a plain HTTP request and received a response. An attacker who can intercept that request can answer it with anything: a copy of the site, a redirect to a look-alike host, or a page that keeps the session on HTTP. The MDN documentation describes this as the first-visit problem, and RFC 6797 calls it a bootstrap man-in-the-middle. Once a valid policy is known and remains effective, HSTS removes that plain request. A matching preload entry can supply the policy before a first visit.

Certificate validation is a different layer. TLS verifies that the server holds a key certified for the hostname; HSTS changes how the browser reacts when that verification fails. Without HSTS a user can usually read a warning and proceed. With HSTS the connection is refused. HSTS does not repair a bad certificate or make a misconfigured server accept HTTPS. It can upgrade requests to known HSTS resource hosts, but does not generally repair mixed content from unrelated hosts. If the HTTPS endpoint is broken, HSTS makes the site unreachable for anyone who already holds the policy, which is precisely what it is designed to do.

Deploying HSTS in Practice

A common rollout starts by serving the whole site, including affected subdomain web services, over HTTPS with valid certificates and working redirects. The header is then added with a short max-age, such as a few minutes, while logs are checked for subdomains or legacy services that broke. The value is raised in stages toward a year or more, includeSubDomains is added once every subdomain is confirmed, and preload is submitted last. Browsers expose the stored policies for inspection; Chromium documents an internal page at about://net-internals/#hsts that lists both dynamic entries learned from headers and static entries from the preload list.

A reverse proxy or CDN can insert the header on HTTPS responses. HSTS governs the browser’s connection to that host, not the CDN-to-origin transport, which needs its own protection. Internal web services under an included subdomain also need usable HTTPS. Non-web services such as mail are not converted to HTTPS by this browser policy.

Limitations and Considerations

HSTS is keyed by hostname rather than an IP literal. An unlisted host’s first HTTP request has no HSTS protection unless a known ancestor includes subdomains. Browser HTTPS-first features may provide separate protection. Dynamic policies can expire or be cleared according to browser behaviour; preload entries follow a separate lifecycle. Non-browser clients vary: some implement HSTS or offer it as an option, while others ignore the header.

The strictness that makes HSTS valuable also makes mistakes expensive. A certificate that expires on an HSTS host locks visitors out until it is renewed. A long max-age on a hostname that later needs plain HTTP, or an includeSubDomains directive applied before an internal subdomain was ready, produces outages that the server cannot undo on the client side. Removing a child host’s dynamic policy does not override an ancestor’s includeSubDomains rule or automatically remove a preload entry. HSTS raises the floor for transport security; it is not a general fix for HTTPS misconfiguration.

Frequently asked questions

Is an HTTP redirect equivalent to HSTS?

No. A redirect takes effect only after the browser has already sent a plain HTTP request, which an attacker on the network can intercept. HSTS stops the browser from sending that request at all once it knows the host. Sites use both: the redirect for first visits and HSTS for everything after.

Does HSTS fix an invalid certificate?

No. HSTS makes a certificate error a hard stop rather than repairing the certificate. The HTTPS endpoint still needs valid credentials and configuration. It may upgrade requests to known HSTS hosts, but does not generally fix mixed content loaded from unrelated insecure hosts.

What changes when subdomains are included?

The policy also covers descendant hostnames, including internal ones and ones not previously visited. Web services on those names need working HTTPS or a browser with the policy may be unable to reach them. It does not convert unrelated protocols, such as email transport, into HTTPS.

Does HSTS protect the very first visit to a site?

HSTS can cover a first visit through a matching preload entry or a previously learned ancestor policy with includeSubDomains. Otherwise an initial HTTP request has no HSTS protection. Starting directly with HTTPS or using a browser’s HTTPS-first mode offers separate protections, rather than establishing that HSTS was already active.

How can a site remove an HSTS policy?

A valid HTTPS response containing max-age=0 removes the host’s dynamic entry. Clients must receive it; it does not override a parent’s includeSubDomains policy or immediately remove a preload entry. Preload removal has a separate process and depends on browser updates, so rollback needs planning.