HSTS, short for HTTP Strict Transport Security, is a response header that tells a browser to reach a site over HTTPS only and to upgrade any later attempt over plain HTTP automatically. It closes the gap between a site that offers an encrypted connection and a site that cannot be visited without one.
The problem it solves
Most sites redirect visitors from HTTP to HTTPS. That redirect is itself sent over the unencrypted connection, so the first request is open to tampering by someone on the same network, for example on public Wi-Fi. With HSTS, the browser remembers that the site is HTTPS only and does not send that unencrypted request again.
How the header works
The header is called Strict-Transport-Security, and its main setting is max-age: the number of seconds the browser should remember the rule. A common value is 31536000, which is one year. Two optional settings can be added. The first, includeSubDomains, applies the rule to every subdomain of the site as well. The second, preload, signals that the site wants to be on a list that is built into browsers, so the rule applies even on the very first visit. The MDN reference for Strict-Transport-Security notes that preloading requires a max-age of at least one year together with includeSubDomains.
Browsers only accept the header when it arrives over HTTPS. Sent over plain HTTP it is ignored, so that nobody on the network can plant or alter it.
What changes for visitors
Two things change once a browser has seen the header. Addresses typed or linked with http are changed to https before any request leaves the browser. And if the certificate of the site is invalid, for example because it has expired, the browser no longer offers a way to continue past the warning.
That second effect is intended, but it raises the stakes for certificate renewal. With HSTS in place, an expired certificate means returning visitors cannot open the app at all.
Limits and cautions
HSTS only takes effect after the first visit over HTTPS, unless the site is preloaded. It is also hard to take back. The browser keeps the rule for the whole max-age period, and the way to cancel it is to send the header again with max-age set to 0, over HTTPS. Before adding includeSubDomains, make sure every subdomain works over HTTPS, including the ones that are easy to forget, such as an old staging address.
HSTS in a client app
HSTS is one of the standard security headers and is usually switched on with a single line in the hosting configuration. For an agency it comes with one duty: watch the expiry date of the certificate. A check that finds the header shows that the browser was told to insist on HTTPS on that day. It says nothing about the rest of the app.