Web Development

HSTS Explained: Benefits, Risks and Safe Deployment

Learn how HSTS forces HTTPS, prevents downgrade attacks, how max-age, includeSubDomains and preload work, and why careless deployment can break access to a site.

SeoNest Team2 min read
Open article contents

HSTS Explained: Security Benefit and Deployment Risk

HSTS is one of the simplest HTTP security mechanisms to configure—and one of the easiest to deploy too aggressively.

HTTP Strict Transport Security, or HSTS, tells a browser that a domain must be accessed only over HTTPS. Once the browser has learned that policy, an attempt to open http://example.com is upgraded to HTTPS before an insecure HTTP request is sent. HSTS also prevents users from bypassing certificate errors for that host. (rfc-editor.org)

The security benefit is significant: HSTS reduces the opportunity for HTTPS downgrade and SSL-stripping attacks. The deployment risk is equally important: a long max-age, includeSubDomains, or HSTS preloading can make misconfigured or HTTP-only hosts inaccessible until the underlying HTTPS problem is fixed.

Direct Answer

HSTS is an HTTP response header that tells supporting browsers to use HTTPS for a domain for a specified period.

A typical policy looks like this:

Strict-Transport-Security: max-age=31536000; includeSubDomains

Here, max-age=31536000 means the browser remembers the HSTS policy for approximately one year. includeSubDomains extends that policy to subdomains. Browsers only accept the HSTS header over a secure connection; an HSTS header received over plain HTTP is ignored. (rfc-editor.org)

HSTS strengthens HTTPS deployment. It does not replace HTTPS, TLS certificates, redirects, or correct server configuration.

Key Facts

FeatureWhat It DoesMain Risk
max-ageStores the HSTS policy for a number of secondsMistakes can persist until the policy expires
includeSubDomainsExtends HSTS to subdomainsHTTP-only subdomains can become inaccessible
preloadSignals intent to participate in browser preload programsCreates a longer-term domain-wide commitment
max-age=0Removes a dynamically learned HSTS policyBrowser must first reach the site securely to receive it

RFC 6797 defines max-age and includeSubDomains. The preload mechanism is an additional browser ecosystem feature rather than part of the HSTS specification itself. (rfc-editor.org)

Why HSTS Matters

Consider a website that redirects HTTP visitors to HTTPS:

http://example.com
        ↓
301 redirect
        ↓
https://example.com

That redirect helps normal users reach HTTPS, but the initial HTTP request is still unencrypted. An attacker controlling the network could potentially interfere before the HTTPS connection is established. MDN describes this as the first-connection window in which SSL stripping remains possible. (developer.mozilla.org)

After a browser learns an HSTS policy, the sequence changes:

User requests http://example.com
        ↓
Browser sees stored HSTS policy
        ↓
Browser changes request to HTTPS
        ↓
HTTPS connection

The insecure request is avoided.

This distinction matters: an HTTP-to-HTTPS redirect happens after an HTTP request reaches the server, while HSTS can cause the browser to upgrade the request locally before sending it.

INTERNAL LINK: How HTTPS and TLS Work

How HSTS Works

When an HTTPS response contains:

Strict-Transport-Security: max-age=31536000

the browser records that host as an HSTS host. The max-age value acts as a time-to-live measured from when the browser receives the header. Future qualifying HTTP requests are upgraded to HTTPS. Each later HSTS response can refresh the expiration time. (rfc-editor.org)

There is another important behavior: TLS certificate errors become non-bypassable for an HSTS host. A user normally presented with a certificate warning may sometimes have an option to continue. HSTS intentionally removes that escape route because allowing the user through would undermine the security policy. (developer.mozilla.org)

That is useful during an attack—but painful during an operational mistake.

The Deployment Risk

The biggest HSTS mistake is treating the strongest configuration as the default starting point.

Imagine this domain structure:

example.com
www.example.com
api.example.com
legacy.example.com
internal.example.com

Suppose legacy.example.com still works only over HTTP. Enabling this immediately on the parent domain would be dangerous:

Strict-Transport-Security: max-age=31536000; includeSubDomains

A browser that receives the policy can begin requiring HTTPS for descendants of example.com. If legacy.example.com cannot serve valid HTTPS, users may no longer be able to access it.

This is why includeSubDomains should be enabled only after the relevant subdomain inventory has been checked and HTTPS support has been verified. MDN specifically warns that the directive can disable access to subdomains that do not yet support HTTPS. (developer.mozilla.org)

Safer Deployment

A safer rollout is progressive rather than immediate.

Start by confirming that the main domain works correctly over HTTPS. Then use a short HSTS lifetime, for example:

Strict-Transport-Security: max-age=300

This gives a five-minute policy window.

After confirming certificate renewal, redirects, CDN behavior, application routes, error responses and other infrastructure, increase the duration gradually:

Strict-Transport-Security: max-age=86400

Then, after further validation:

Strict-Transport-Security: max-age=31536000

Only add includeSubDomains when HTTPS is reliably supported throughout the intended subdomain tree.

This gradual increase is a SeoNest deployment recommendation rather than a requirement of RFC 6797. The current HSTS preload service also advises operators to ramp up max-age before submitting a domain for preloading. (hstspreload.org)

HSTS Preloading

Normal HSTS has a limitation: a browser must usually receive the HSTS header before it knows the policy. A new browser profile therefore still has an initial connection window.

HSTS preloading addresses this by shipping a list of HSTS domains with browsers. Chromium documents that Chrome maintains such a preload list and that other browsers use lists based on it. (chromium.org)

The current submission requirements at hstspreload.org include a valid certificate, HTTP-to-HTTPS redirection on the same host when HTTP is served, HTTPS support across subdomains, includeSubDomains, preload, and a max-age of at least 31536000 seconds. (hstspreload.org)

A typical preload-ready header is:

Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

But preloading should not be enabled casually. The preload service explicitly warns projects not to enable preload by default and notes that removal can be slow. Its current guidance recommends HSTS itself while taking a more cautious position on HSTS preloading. (hstspreload.org)

Nginx Example

For Nginx:

add_header Strict-Transport-Security "max-age=31536000" always;

The always parameter makes Nginx add the header regardless of response status. Nginx also has specific inheritance behavior for add_header, so nested server or location configuration should be reviewed rather than assuming the header is inherited everywhere. (nginx.org)

Do not send HSTS from an HTTP-only endpoint expecting the browser to trust it. Browsers intentionally ignore HSTS headers delivered over insecure HTTP. (developer.mozilla.org)

Verify the Deployment

Check the HTTPS response headers directly:

curl -I https://example.com

curl -I retrieves the HTTP response headers, allowing you to confirm that Strict-Transport-Security is actually present. (curl.se)

Look for:

Strict-Transport-Security: max-age=31536000

Also test redirects, error responses, important subdomains and certificate validity. If you plan to use includeSubDomains, testing only the apex domain is not enough.

Common Misconceptions

HSTS redirects HTTP to HTTPS on the server. Not exactly. Once the policy is known, the browser can upgrade the request before making the insecure HTTP connection.

HSTS fixes an expired certificate. No. It makes certificate failures stricter. A broken certificate can therefore make an HSTS-protected site completely inaccessible until the certificate problem is fixed.

Removing the header immediately disables HSTS. No. A previously stored policy remains active until its max-age expires. Sending max-age=0 removes a dynamic HSTS policy when the browser successfully receives that response over HTTPS. (rfc-editor.org)

Every HTTPS site should immediately use preload. HSTS and HSTS preloading are separate decisions. Preloading creates a stronger operational commitment and should follow a deliberate review of the entire domain namespace.

SeoNest Recommendation

Enable HSTS after HTTPS is already stable—not as a way to make an unstable HTTPS deployment secure.

Start with the main hostname and a short max-age. Validate certificates, redirects, CDN behavior, application errors and renewal automation. Increase max-age gradually. Add includeSubDomains only after verifying the relevant subdomains. Treat preloading as a separate infrastructure decision because its consequences extend beyond a normal response header.

The goal is not to configure the strongest-looking header. It is to create an HTTPS policy your infrastructure can reliably honor.

FAQ

Does HSTS improve SEO?

HSTS is primarily a transport-security mechanism. Google has not documented HSTS itself as a direct ranking factor in the sources used for this article. Its value should therefore be evaluated mainly in terms of HTTPS security and deployment reliability, not assumed ranking improvements.

Does HSTS affect the first visit?

Ordinary dynamically learned HSTS cannot fully protect a browser that has never learned the site's policy. Preloading can remove that initial gap for included domains. (developer.mozilla.org)

Can HSTS be disabled?

For a dynamically stored policy, the server can send:

Strict-Transport-Security: max-age=0

over HTTPS. The browser then removes that host's stored HSTS policy as defined by RFC 6797. (rfc-editor.org)

Should APIs use HSTS?

If an API hostname is accessed by user agents that implement HSTS, it can benefit from the same transport policy. Whether includeSubDomains should be applied at a parent domain still depends on the HTTPS readiness of the wider domain tree.

Final Takeaway

HSTS closes an important weakness in ordinary HTTP-to-HTTPS redirection by telling browsers to require HTTPS in future connections. Its strength comes from persistence: browsers remember the policy and refuse insecure fallback.

That persistence is also the deployment risk.

Use HSTS deliberately. Stabilize HTTPS first, start with a manageable max-age, expand coverage only after testing, and approach includeSubDomains and preloading as infrastructure commitments rather than harmless header options.

Sources

  1. RFC Editor — RFC 6797: HTTP Strict Transport Security (HSTS), November 2012. Defines HSTS processing, max-age, includeSubDomains, expiration and removal behavior. (rfc-editor.org)
  2. MDN Web Docs — Strict-Transport-Security header. Practical browser behavior, syntax, certificate handling, subdomains and preload context. (developer.mozilla.org)
  3. MDN Web Docs — Transport Layer Security. HTTPS upgrade behavior, SSL stripping and the first-connection limitation of dynamically learned HSTS. (developer.mozilla.org)
  4. Chromium — HTTP Strict Transport Security. Chromium's description of HSTS behavior and browser preload lists. (chromium.org)
  5. HSTS Preload List Submission — hstspreload.org. Current preload requirements, operational warnings and submission guidance. (hstspreload.org)
  6. NGINX — ngx_http_headers_module. Official documentation for add_header, always and header inheritance. (nginx.org)
  7. curl — Tutorial. Official documentation for using -I / --head to inspect HTTP headers. (curl.se)

SEONEST

Need a stronger technical foundation?

We build production-ready websites where SEO, speed and clean engineering are part of the architecture from the start.

Discuss your project