How Does HTTP Strict Transport Security Protect a Website?

Web operations engineer checking a secure browser connection beside network equipment

HTTP Strict Transport Security Explainer

HTTP Strict Transport Security, usually shortened to HSTS, is a browser policy that tells a user agent to contact a website only through HTTPS for a stated period. A site sends the Strict-Transport-Security response header over a secure connection, and the browser stores the rule for that hostname. Later, if a user types an address beginning with http:// or follows an old insecure link, the browser rewrites the request to HTTPS before making the network connection. That local upgrade helps prevent an attacker from intercepting the initial HTTP request and keeping the visitor on an insecure version of the site.

The header’s max-age directive sets how many seconds the policy should remain in the browser’s HSTS store. Each valid HTTPS response can refresh that duration. If a request uses the ordinary HTTP port, the browser changes it to the corresponding HTTPS port; other explicitly named ports are preserved while the scheme is upgraded. The rule is learned by hostname, not by an IP address in the general case, and browsers ignore an HSTS header received over plain HTTP because an attacker could alter that response.

HSTS also changes certificate-error behavior. For a normal HTTPS site, a browser may sometimes offer an advanced option that lets the user continue after a warning. For a known HSTS host, the connection must terminate when the certificate is untrusted, expired, or does not match the name; the user is not allowed to click through. This protects the policy from being defeated by a convincing warning page. The optional includeSubDomains directive extends the rule to subordinate hostnames, which can close gaps but requires every affected service to support HTTPS correctly.

A first visit remains the important limitation. Before the browser has received a valid HSTS header, an initial HTTP request can still be exposed to redirection attacks. Browser preload lists reduce that gap by shipping a set of HTTPS-only domains in advance, but preloading is an ecosystem practice outside the core RFC and carries operational commitments. A domain should not request preload treatment until HTTPS works consistently across the required hostname scope, redirects are correct, certificates renew reliably, and owners understand that removal can take time.

Deployment benefits from a gradual rollout. Administrators can begin with a short max-age, monitor certificate and subdomain failures, and lengthen the period after verifying that all traffic paths are ready. Turning on includeSubDomains too early can lock users out of forgotten services, development hosts, or third-party systems that still depend on HTTP. HSTS cannot repair a broken certificate, stop an application vulnerability, eliminate mixed-content problems by itself, or encrypt traffic that never reaches a compliant browser. It is one enforcement layer, not a complete web-security program.

The practical value of HSTS is that the browser remembers the site’s secure-transport decision and applies it before an attacker can influence an ordinary HTTP redirect. Strong deployments pair the header with automatic certificate renewal, HTTPS redirects, modern TLS configuration, monitoring, and an inventory of every affected hostname. They test expiration and recovery plans as carefully as initial activation. Teams should also distinguish HSTS from server-side redirects: a redirect happens only after an HTTP request reaches the server, while a stored HSTS policy upgrades the destination before that request is sent. Used carefully, the policy removes a common opportunity for downgrade attacks and makes certificate failures unavoidably visible. Operational ownership is crucial because a long max-age can outlive staffing changes, migrations, or a forgotten vendor contract. Documentation should record which team owns certificates, DNS, redirects, and emergency changes for each hostname. Monitoring from outside the network can catch renewal failures before users do, while staged configuration changes reduce the chance that a policy intended to improve security creates a prolonged outage.

Explore more "Explainers"

Discover additional explainers across politics, science, business, technology, and other fields. Each explainer breaks down a complex idea into clear, everyday language—helping you better understand how major concepts, systems, and debates shape the world around us.