Dev.to Security 🔐 Cybersecurity 👁 2 📖 5 min read

The whole .app TLD is on the HSTS preload list, so our http:// redirect only ever serves curl, and our www host sends a different HSTS header from the apex

Our site sends strict-transport-security: max-age=63072000; includeSubDomains; preload on every response. The header lives in next.config.mjs, with preload on the end because that is what the snippets say, and I had neve

Our site sends strict-transport-security: max-age=63072000; includeSubDomains; preload on every response. The header lives in next.config.mjs, with preload on the end because that is what the snippets say, and I had never checked whether it was doing anything. This week I did.

The site is pub-trivia.app, and the TLD is the interesting part. Google owns .app, and the whole TLD is on the HSTS preload list. Every .app domain is treated as HTTPS-only by the major browsers before it has sent a single request. The preload API agrees:

curl -s "https://hstspreload.org/api/v2/status?domain=pub-trivia.app"
{
  "name": "pub-trivia.app",
  "status": "preloaded",
  "bulk": false,
  "preloadedDomain": "app"
}

preloadedDomain: "app" is the line to read. We are not on the list because we asked to be. We are on it because the parent is. So the preload token in our header is a request to join a list we are already covered by, and the thing we have been guarding is the one case that cannot happen: a browser asking for http://pub-trivia.app.

What a browser does, and what everything else does

Type http://pub-trivia.app/pricing into Chrome with the Network tab open. You will see a 307 Internal Redirect with a Non-Authoritative-Reason: HSTS header on it. That response was made up by the browser, and nothing was sent. The address is rewritten to https:// before any packet leaves the machine. Try it on the pricing page, and then try the same address in curl, which has no preload list:

curl -si http://pub-trivia.app/pricing
HTTP/1.0 308 Permanent Redirect
Location: https://pub-trivia.app/pricing
Refresh: 0;url=https://pub-trivia.app/pricing
server: Vercel

That is the response a browser never sees. The http:// listener on our domain exists for command line tools, link checkers, crawlers following an old http link, and any client without a preload list. It answers with a 308, not our application, and notice what it does not send: there is no strict-transport-security header on it. That is correct, since browsers ignore the header over plain HTTP, and it means the first hop for these clients carries no HSTS at all.

Four shapes, three answers

I requested the same page in four shapes and recorded the status line and the HSTS header of the first response. The last column is the median of twelve full requests with -L, including the redirects, from one laptop, so treat the milliseconds as a ranking and not a promise.

request                              first response   HSTS on it                                       median
https://pub-trivia.app/pricing       200              max-age=63072000; includeSubDomains; preload      308 ms
http://pub-trivia.app/pricing        308 to https     none                                              349 ms
https://www.pub-trivia.app/pricing   307 to apex      max-age=63072000                                  407 ms
http://www.pub-trivia.app/pricing    308 to https www none (then 307 to the apex)                       422 ms

Three things stand out.

The www host sends a different HSTS header. The 307 from www carries max-age=63072000 and nothing else: no includeSubDomains, no preload. That header did not come from our config, because our rule is attached to our own responses and this one is a redirect generated by the platform's domain layer. The value is the same two years, so the practical effect is the same. But the header on www and the header on the apex are authored by two different systems, and if I ever changed ours, the other would not follow.

The www redirect is a 307. The http redirect is a 308, which is permanent, and the www redirect is a 307, which is temporary. Both end at the apex. Search engines treat the two similarly in practice, but a 307 tells a client not to remember the move, and so every non-browser client repeats the extra hop forever. The response also carries cache-control: public, max-age=0, must-revalidate, which is an instruction not to reuse it.

The extra hops cost 40 to 115 ms here. Adding the http hop costs 41 ms over the direct request, the www hop 99 ms, and both together 114 ms. Those are small numbers for a client that is not a person, and every one of those clients is a crawler or a script. The people who matter reach the site through the browser, which skips every redirect in the table except the www one.

What would be worth changing

Not much, and that is the useful finding:

  1. The preload token. It is harmless, but it implies a list we are not on. If I rewrote the header today, I would leave it off and add a comment that the TLD does the work. Leaving it also means I cannot be accused of an unfulfilled preload submission, because there is no per-domain entry to maintain.
  2. includeSubDomains. This is the part with a real consequence. It tells browsers that every subdomain of pub-trivia.app must be HTTPS as well. Since the TLD is preloaded, that is already true for browsers whether or not we say it, but our header is how a non-preloaded copy of the rule would reach a client that does not ship the list.
  3. The 307 on www. If the platform lets me pick the status code for the redirect, 308 is the right one for a move that has been in place since launch.

What I cannot show you

The Chrome behaviour above is documented and I have seen it, but it is not something curl can demonstrate, so treat that paragraph as a thing to check in your own browser rather than something I have measured here. I also have not tested Safari or Firefox, which ship their own copies of the list (derived from Chromium's), and which I would expect to behave the same way.

The timings are one laptop, one network, twelve runs per shape. They rank the four shapes and show that none is slow. They are not a claim about anyone else's connection.

Try it on your own domain

Three commands cover the whole check:

curl -s "https://hstspreload.org/api/v2/status?domain=YOURDOMAIN"
curl -si http://YOURDOMAIN/ | head -8
curl -si https://www.YOURDOMAIN/ | head -8

If the first says preloadedDomain is your TLD, your own preload token is decoration. If the second shows a 301 where a 308 would do, or the third shows an HSTS header that differs from your apex, you have found the same small inconsistencies I did. The site they came from is live: start at the homepage, look at the FAQ, or try the free tools, which need no account.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.