Browser Terms Explained: HSTS (HTTP Strict Transport Security)

Get SigmaOS Free

It's free and super easy to set up

Browser Terms Explained: HSTS (HTTP Strict Transport Security)

Get SigmaOS Free

It's free and super easy to set up

Browser Terms Explained: HSTS (HTTP Strict Transport Security)

Get SigmaOS Free

It's free and super easy to set up

Browser Terms Explained: HSTS (HTTP Strict Transport Security)

Have you ever noticed the little padlock icon in your browser's address bar when you visit a secure website? That padlock indicates that your connection to that website is encrypted, which means that any information you enter there is protected from prying eyes. But did you know that there's a way to make that connection even more secure? It's called HTTP Strict Transport Security, or HSTS for short. In this article, we'll explain what HSTS is, why it's important, and how it works.

Understanding HSTS: A Brief Overview

Before we dive into the details of HSTS, let's first establish some basic concepts. First, what is HTTP? HTTP stands for Hypertext Transfer Protocol, which is the protocol that defines how data is exchanged between web servers and web clients (i.e., your browser). When you type a URL into your browser's address bar and press Enter, your browser sends an HTTP request to the server hosting that website. The server then sends back an HTTP response containing the requested data (e.g., HTML, images, stylesheets, etc.).

What's the problem with HTTP? The problem is that HTTP requests and responses are sent in plain text, which means that anyone who intercepts them (e.g., a hacker on the same Wi-Fi network as you) can read and potentially modify the data. This is where HTTPS comes in. HTTPS stands for Hypertext Transfer Protocol Secure, and it's basically a version of HTTP that uses encryption to protect the data being exchanged between the server and the client.

Now, let's move on to HSTS. HSTS is a mechanism that allows a website to instruct a browser to always use HTTPS when communicating with that website. This means that even if the user types in an HTTP URL or clicks on a link that points to an HTTP URL, the browser will automatically convert it to HTTPS before sending the request. HSTS accomplishes this by adding a special header to the server's HTTP response, which tells the browser to remember that that website should always be accessed over HTTPS.

What is HSTS?

In technical terms, HSTS is an HTTP response header that a website sends to a browser to instruct it to only communicate with that website over HTTPS. The header contains a few key pieces of information, including:

  • The max-age directive, which specifies how long the browser should remember to use HTTPS for that website (e.g., 31536000 seconds, or one year)

  • The includeSubDomains directive, which tells the browser to apply the HSTS policy to all subdomains of that website as well

  • The preload directive, which indicates that the website has been added to a global list of sites that should always be accessed over HTTPS

Why is HSTS Important?

Now that we know what HSTS is, let's discuss why it's important. The primary benefit of HSTS is that it helps protect users from attacks that target their HTTPS connections. Here are a few examples:

The Role of HSTS in Web Security

Protecting Against Man-in-the-Middle Attacks

One of the most common HTTPS-related attacks is called a man-in-the-middle (MitM) attack. In a MitM attack, a hacker intercepts the communication between the user's browser and the website's server and can read, modify, or inject data into that communication. For example, the hacker could inject malicious JavaScript code into the website's response, which could then steal the user's login credentials or perform other nefarious actions.

HSTS helps protect against MitM attacks by ensuring that the user's browser always communicates with the website over an encrypted HTTPS connection. Even if the attacker intercepts the initial HTTP request, the browser will automatically upgrade it to HTTPS thanks to the HSTS policy.

Preventing Cookie Hijacking

Another attack that HSTS can help prevent is cookie hijacking. A cookie is a small piece of data that a website stores on the user's computer and uses to remember information about the user's session (e.g., login credentials, shopping cart contents, etc.). If an attacker can steal the user's cookie (e.g., by intercepting the HTTP request and reading the cookie value), they can impersonate the user and perform actions on the user's behalf.

With HSTS in place, the user's browser will always send the cookie over an encrypted HTTPS connection, making it much harder for an attacker to intercept.

Enhancing User Privacy

Finally, HSTS can help enhance user privacy by preventing "mixed content" warnings. Mixed content occurs when a website is loaded over HTTPS but includes resources (e.g., images or scripts) that are served over HTTP. This can happen if the website owner forgets to update all of their resources to use HTTPS or if a third-party service used by the website doesn't support HTTPS. When mixed content is detected, the browser will often display a warning to the user.

HSTS helps prevent mixed content by ensuring that all resources are loaded over HTTPS, which can help protect the user's privacy and prevent warnings from being displayed.

How HSTS Works

The HSTS Header

Let's now take a closer look at how the HSTS header works. When a browser first connects to a website that supports HSTS, the website sends an HTTP response that contains the HSTS header. This header includes the max-age directive, which tells the browser how long to remember the HSTS policy (in seconds). After the specified time period has elapsed, the browser will no longer automatically convert HTTP URLs to HTTPS for that website.

The HSTS header syntax looks like this:

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

In this example, the max-age directive tells the browser to remember the HSTS policy for one year, the includeSubDomains directive tells the browser to apply the policy to all subdomains of the website, and the preload directive indicates that the website has been added to the global HSTS preload list.

HSTS Preloading

The HSTS preload list is a global list of websites that have opted into HSTS and are always accessed over HTTPS. The list is maintained by the Chromium project (the open-source project that powers Google Chrome), and is built into all major browsers (including Chrome, Firefox, and Safari). When a website is added to the list, it's effectively "baked into" the browser, which means that even if the user has never visited the website before, their browser will automatically use HTTPS when communicating with that website. This can help protect users from attacks that target their initial request to a website.


Finally, it's worth noting that HSTS is not a replacement for HTTPS – it's a complement to it. HSTS only works if the website is already using HTTPS, so if a website doesn't support HTTPS, adding an HSTS header won't provide any additional security. Therefore, website owners should always ensure that their website uses HTTPS (and only HTTPS) before implementing HSTS.

Implementing HSTS on Your Website

Configuring HSTS in Different Web Servers

If you're a website owner interested in implementing HSTS on your website, you'll need to know how to configure it on your web server. The process will vary depending on which web server you're using (e.g., Apache, Nginx, IIS, etc.), but the basic steps are:

  1. Ensure that your website is already using HTTPS (i.e., all requests are being served over HTTPS)

  2. Add the HSTS header to your server's HTTP response for your website (e.g., via a .htaccess file on Apache)

  3. If desired, submit your website to the HSTS preload list

Testing Your HSTS Implementation

Once you've configured HSTS on your server, it's a good idea to test that it's working properly. You can do this by visiting your website using HTTP (not HTTPS) and ensuring that your browser automatically redirects you to the HTTPS version of the site. You can also use tools like the SSL Server Test to check that your website is properly serving the HSTS header.

Common HSTS Implementation Mistakes

Finally, it's worth noting some common mistakes that website owners make when implementing HSTS:

  • Forgetting to ensure that all resources (e.g., images, scripts, stylesheets) are being served over HTTPS as well

  • Setting the max-age value too low (e.g., less than a year)

  • Submitting a website to the preload list before it's fully HTTPS-compliant

Be sure to avoid these mistakes to ensure that your HSTS implementation is effective.


HTTP Strict Transport Security (HSTS) is a powerful mechanism that website owners can use to enhance the security of their HTTPS-enabled websites. By instructing browsers to always use HTTPS when communicating with their websites, website owners can protect their users from a variety of attacks. While implementing HSTS does require some additional configuration, the benefits are well worth the effort.