Learn / Security / Lesson 01

HTTPS and HSTS

Why having HTTPS is not enough, how one header stops a whole class of attacks, and why that header is hard to take back.

Last updated: 2026-09-19

What it is

HTTPS encrypts the connection between a browser and a server. HSTS (HTTP Strict Transport Security) is a response header that tells the browser: for the next N seconds, never talk to this site over plain HTTP, not even once.

http
Strict-Transport-Security: max-age=31536000

After a browser has seen that header, typing schema-ph.dev, clicking an old http:// link, or following a bookmark all go straight to HTTPS inside the browser. The insecure request is never sent.

Why it is a rule

A site can have a perfect certificate and still be attacked, because the first request often is not HTTPS. A person types a bare domain, the browser tries http://, and the server answers with a redirect to https://. That first plain-text hop is the gap.

HSTS was standardised in 2012 (RFC 6797) as the answer to sslstrip: once the browser knows the rule, there is no plain-text hop left to hijack.

The Philippines has a lot of shared and public Wi-Fi, and many networks run TLS-intercepting proxies. The first-visit gap is not theoretical here.

How to do it

  1. Serve every page over HTTPS and redirect HTTP to HTTPS.
  2. Send Strict-Transport-Security on every HTTPS response in production.
  3. Start with a short max-age (a day) while you check nothing breaks, then raise it to a year (31536000).
  4. Add includeSubDomains only once every subdomain serves HTTPS.
  5. Add preload and submit to the browser preload list only when you are sure it is permanent.
js
if (process.env.NODE_ENV === 'production') {
  app.use((req, res, next) => {
    res.setHeader('Strict-Transport-Security', 'max-age=31536000')
    next()
  })
}

Do not send it in development. On localhost it pins your dev server to HTTPS inside your own browser until you clear the entry by hand.

How we do it here

Every production response from schema-ph.dev carries HSTS with a one-year max-age. Our subdomains are not included yet, and the site is not on the preload list; both wait until every subdomain is confirmed HTTPS-only.

Benefits

Disadvantages

Checklist

Sources

Read this lesson as Markdown