Skip to content

Interview question · Network Security & Protocols

What is SSL stripping, how does HSTS prevent it, and what are the risks and limits of HSTS and preloading?

Users type a domain, not https://. That one habit gave attackers a plain-HTTP first request to hijack. HSTS closes it, and preloading closes it before the first visit, with a commitment you cannot easily undo.

mediumEssentialNewPreparation tags: Google, Amazon, MetaUpdated Nov 2026

TL;DR: When a user types example.com, the browser often starts with plain HTTP and is redirected to HTTPS. A man in the middle can intercept that first HTTP request and keep the victim on HTTP, talking HTTPS to the real site on their behalf (SSL stripping). HTTP Strict Transport Security is a response header (Strict-Transport-Security: max-age=...; includeSubDomains) that tells the browser to use only HTTPS for the domain for the given time and to make certificate errors non-bypassable. The first visit remains exposed, which the HSTS preload list fixes by shipping the domain in browsers. The risks are operational: includeSubDomains and preload apply to every subdomain, including internal ones that never had HTTPS, and removal from the preload list takes months.

How to approach it

Describe the attack as a sequence (first request over HTTP, attacker relays), then HSTS's two effects (upgrade and no click-through), then the trust-on-first-use gap and preloading, then deployment risks. Interviewers like this question because it tests both protocol understanding and operational judgement.

A strong answer

FIG · SSL STRIPPING · THE FIRST HTTP REQUEST
The attack lives in one plain-HTTP request; HSTS removes that request

No HSTS

User types bank.com

browser tries http://

Attacker on path

answers over HTTP

Never forwards the redirect to HTTPS

Real site

attacker talks HTTPS to it

Outcome, unsafe: Victim stays on HTTP

Passwords and cookies visible to the attacker

HSTS or preload

User types bank.com

browser knows the policy

Upgrades to https:// internally

Attacker on path

only sees TLS

Cannot present a valid certificate

Real site

direct TLS

Outcome, safe: No plaintext request exists

Certificate errors cannot be clicked through

The attack. The victim on a hostile network types bank.example. The browser sends GET http://bank.example/. The attacker intercepts, fetches the HTTPS site themselves, and returns pages to the victim over HTTP with links and form actions rewritten to HTTP. The victim sees a working site with no padlock and submits credentials in clear text. TLS was never broken; it was never used on the victim's side. Variants downgrade only part of a page or strip Secure flags from cookies.

What HSTS does. After the browser receives the header over a valid HTTPS connection:

  1. For max-age seconds, every request to that host (and its subdomains with includeSubDomains) is upgraded to HTTPS inside the browser before it is sent. No plain HTTP request leaves.
  2. Certificate errors for the host become fatal: the user cannot click through. This removes the second most common way MITM succeeds.

The header is ignored over plain HTTP, so an attacker cannot set or clear it by injecting into HTTP responses.

The first-visit gap and preloading. Before the browser has seen the header (new device, cleared data, expired max-age), the first request can still be stripped. The HSTS preload list, maintained for Chromium and used by other major browsers, hard-codes domains as HTTPS-only. Requirements include serving the header with a long max-age (at least one year), includeSubDomains and the preload token, and redirecting HTTP to HTTPS on the same host. Some top-level domains are preloaded as a whole (for example .dev and .app), so every site under them is HTTPS-only by default.

Deployment risks.

  • includeSubDomains breaks any subdomain that does not serve valid HTTPS: intranet hosts, legacy devices, printers with web interfaces under the corporate domain.
  • Preloading is slow to undo: removal requests take effect only as browser releases ship, so a mistake persists for months.
  • A long max-age with a broken certificate means users cannot reach the site at all, rather than clicking through. That is the intended security property and an availability risk.

Roll out gradually: start with a short max-age without includeSubDomains, inventory subdomains, fix their HTTPS, extend max-age, then add includeSubDomains, then preload.

Related controls. Set Secure on cookies so they never travel over HTTP; use __Host- cookie prefixes to bind cookies to the host over HTTPS; avoid mixed content. For mobile apps, the equivalents are network security configuration (Android) and App Transport Security (iOS), which block cleartext by default.

What interviewers probe next

  • "Can an attacker remove HSTS by sending max-age=0?" Only over a valid HTTPS connection to the real site, which they cannot establish without a trusted certificate.
  • "Does HSTS protect APIs called by mobile apps?" No, it is a browser mechanism; apps should enforce HTTPS themselves, which the platforms do by default.
  • "What if the site's certificate expires with HSTS on?" Browsers refuse to connect and users cannot override, so certificate automation and monitoring become availability-critical.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

Your site redirects HTTP to HTTPS, and a tester on the same café network still captures a user's session cookie.

  1. Start here

    How did the tester capture the cookie?

How it's scored

Weak: "HSTS forces HTTPS."

Hire: Explains SSL stripping on the first request, HSTS's upgrade and non-bypassable errors, and preloading for the first visit.

Strong Hire: Walks the attack precisely, explains why the header is honoured only over HTTPS, gives preload requirements and TLD preloading, details includeSubDomains and removal risks with a staged rollout, and connects to cookie flags and mobile equivalents.

Common mistakes

  • Believing an HTTP-to-HTTPS redirect is enough.
  • Enabling includeSubDomains and preload without inventorying subdomains.
  • Forgetting the first-visit gap.
  • Treating HSTS as relevant to non-browser clients.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 10, and we keep track of how far you get in every topic.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in doubles your free answers, from 5 to 10 per topic, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

No comments yet. Share a correction or a different way to answer it.