Deutsch
Security wikiWeb security

What is HSTS (HTTP Strict Transport Security)?

Also known as: HSTS, Strict-Transport-Security, HSTS preload, RFC 6797

HSTS is a response header that tells browsers to use only HTTPS for your domain. What it protects, the first-visit gap, preloading and how to check your app.

By Tim GeithnerPublished 2 min read

Short answer

HTTP Strict Transport Security (HSTS) is a response header that tells browsers to reach your domain only over HTTPS for a set time. After the first secure visit, the browser upgrades every http link itself and refuses to let users click through certificate errors. Set it with a long max-age on your custom domain, add includeSubDomains once every subdomain serves HTTPS, and only preload when you are sure.

Ask an AI about this page:ChatGPTClaude

On this page

HTTP Strict Transport Security (HSTS) is a response header, defined in RFC 6797 (opens in a new tab), that tells browsers to contact a domain only over HTTPS for a set number of seconds. Once a browser has seen it, it rewrites every http:// request to that domain into https:// before sending it, and, as MDN puts it, it doesn’t let users click through certificate errors.

A typical HSTS header
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
  • max-age is how long, in seconds, the browser remembers the rule. Every response with the header resets the timer.
  • includeSubDomains applies the rule to all subdomains as well.
  • preload signals that you want the domain in the browsers’ built-in preload list (see below).

HSTS in an AI-built app

When you publish a Lovable app or deploy a Vite build, you usually get HTTPS automatically, and a visitor who types your domain without https:// is redirected to it. That redirect is the gap HSTS closes. The first request still goes out unencrypted, so someone on the same café Wi-Fi can answer it with a fake page before the redirect ever happens. With HSTS in place, the browser never makes that plain request again.

Two details matter in practice:

  • The header only counts over HTTPS. RFC 6797 says browsers must ignore it on responses received over plain http, so sending it on the redirect does nothing.
  • The very first visit is still exposed. HSTS works from the first secure response onwards. The RFC calls this the bootstrap problem; the preload list exists to close it, by shipping known HSTS domains inside the browser.

How to check your app

Open your live site over HTTPS, open the browser’s developer tools, go to the Network tab and click the first document request. Look for strict-transport-security in the response headers. No header means no HSTS. A very short max-age (minutes or days) gives little protection. If you use a custom domain, check it as well as any platform subdomain.

How to fix or prevent it

Set the header on every HTTPS response from your custom domain, starting with a moderate max-age while you check that everything works over HTTPS, then raise it to a year or two. Add includeSubDomains once you know every subdomain serves HTTPS; a forgotten subdomain without a certificate becomes unreachable. Submit to the preload list only after reading the requirements at hstspreload.org, because inclusion cannot easily be undone. How to set headers on your hosting is in Security headers for Vite and Lovable apps; HSTS goes well with a Content Security Policy, and both belong on the pre-launch security checklist.

Frequently asked questions

My site already redirects http to https. Do I still need HSTS?

Yes. The redirect itself happens over an unprotected http request, which someone on the same network can intercept. With HSTS the browser skips the http request entirely on later visits.

What max-age should I use?

MDN’s example uses two years (63072000 seconds). Preloading requires at least one year (31536000) together with includeSubDomains. Start shorter while you test, then raise it.

Should I submit my domain to the HSTS preload list?

Only if every subdomain, now and in future, will serve HTTPS. hstspreload.org warns that inclusion cannot easily be undone: removal takes months to reach users.

Sources

  1. 1.RFC 6797: HTTP Strict Transport Security (HSTS) — IETF
  2. 2.Strict-Transport-Security header — MDN Web Docs
  3. 3.HSTS Preload List Submission — hstspreload.org

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt