Skip to the page

The browser's security model · mid

HTTPS, HSTS and the other security headers

HTTPS protects data in transit, HSTS forces browsers to use HTTPS for your domain, and a short list of response headers (CSP, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, frame-ancestors, COOP/COEP/CORP) removes whole classes of browser attacks.

The notes

What you must know

  • HTTPS gives confidentiality, integrity and server authentication. Many APIs (service workers, geolocation, Secure cookies, Trusted Types) need a secure context.
  • Strict-Transport-Security: max-age=31536000; includeSubDomains tells the browser to use only HTTPS for this host. It is ignored over HTTP and only works after the first HTTPS visit; the preload list (hstspreload.org) fixes the first visit.
  • X-Content-Type-Options: nosniff stops MIME sniffing (a text file being run as a script).
  • Referrer-Policy: strict-origin-when-cross-origin (the browser default) sends only the origin to other sites, so tokens in URLs do not leak via Referer.
  • Permissions-Policy turns off powerful features you don't use (camera=(), geolocation=()), also for iframes.
  • Cross-Origin-Opener-Policy: same-origin cuts the link to cross-origin popups/openers (protects against some XS-Leaks); with COEP: require-corp the page becomes crossOriginIsolated (needed for SharedArrayBuffer). CORP marks who may embed your resources.
  • CSP (with frame-ancestors) is the most important header for XSS and clickjacking; it gets its own lessons.

The red pen

Common traps: mistake → fix

  • Mistake: "HTTPS means the site is safe"

    Fix: it only protects the connection; XSS, CSRF and bad code still work over HTTPS.

  • Mistake: "Send HSTS over HTTP too"

    Fix: browsers ignore it on HTTP; redirect HTTP to HTTPS and send HSTS on the HTTPS response.

  • Mistake: "X-XSS-Protection protects us"

    Fix: that old header is removed from modern browsers; use CSP.

Easy to hard

Questions interviewers ask, easy to hard

  1. What does HSTS do and what is the first-visit problem?
  2. Which security headers would you set on a new production app, and why each?
  3. What is COOP and when would you need COEP?
  4. How do you roll out new headers without breaking third-party integrations (payment popups, embeds)?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview