Website Spec
← Security
Required

HSTS (Strict-Transport-Security)

HSTS tells browsers to use HTTPS for your domain only, for a long time. Add max-age, includeSubDomains, and preload — but understand it is an irreversible commitment.

What it is

HTTP Strict Transport Security, defined in RFC 6797, is a response header that tells the browser: from now on, never speak HTTP to this host — only HTTPS. The browser remembers the instruction for the duration of max-age and refuses plain HTTP even if the user types it, clicks a stale link, or has DNS hijacked.

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

Why it matters

A 301 redirect from HTTP to HTTPS only protects the second request. The first request — and any cookies sent with it — already left the device in plain text. HSTS closes that gap. It also defends against active downgrade attacks where a network attacker strips the redirect and proxies the connection.

Without HSTS, every typed URL, bookmark, and external link to http://example.com is a moment when an attacker on the network can intercept the session.

How to implement

Send the header on every HTTPS response. Browsers ignore it on plain HTTP.

Directives:

Recommended production header:

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

After running this header reliably for at least a few weeks, submit the domain at hstspreload.org. Preloaded domains are hard-coded into Chrome, Firefox, Safari, and Edge, so even the first visit on a fresh device uses HTTPS.

Common mistakes

Verification

HSTS is a commitment, not a switch. Plan the rollback path before you ship.

Sources