What Is HSTS?

May 24, 2024

HTTP Strict Transport Security (HSTS) is a security policy mechanism that helps to protect websites against man-in-the-middle attacks such as protocol downgrade attacks and cookie hijacking. By enforcing secure connections, HSTS instructs browsers to only interact with a website using a secure HTTPS connection, rather than HTTP.

what is hsts

What Is HSTS?

HTTP Strict Transport Security (HSTS) is a web security policy that allows websites to declare themselves accessible only via secure HTTPS connections. When a website implements HSTS, it informs browsers that they should exclusively use HTTPS to communicate with the site, eliminating the possibility of using the less secure HTTP protocol. This is achieved by the server sending an HSTS header in its HTTP responses, specifying a period during which the browser should enforce this policy.

HSTS helps to prevent various attacks, including protocol downgrade attacks, where an attacker forces a browser to use HTTP instead of HTTPS, and cookie hijacking, where cookies are intercepted over unsecured connections.

By mandating HTTPS, HSTS ensures that all communications between the user's browser and the website are encrypted and secure, enhancing the overall security posture of the web application.

A Short History of HSTS

The concept of HTTP Strict Transport Security (HSTS) emerged from the growing need to enhance web security. It was first proposed in 2009 by Jeff Hodges, Collin Jackson, and Adam Barth. Their work focused on mitigating the risks associated with man-in-the-middle attacks and protocol downgrade attacks that exploited the vulnerabilities of HTTP. The initial draft was submitted to the Internet Engineering Task Force (IETF) in 2010, and after several revisions and community feedback, it became a standard in 2012 with the publication of RFC 6797. Since then, HSTS has been widely adopted by major web browsers and websites, becoming a crucial tool in the effort to secure web communications.

Why Is HSTS Important?

HSTS is important because it significantly enhances the security of web communications. By enforcing the use of HTTPS, HSTS ensures that all data exchanged between a user's browser and a website is encrypted, protecting it from eavesdropping and tampering. This is crucial for safeguarding sensitive information, such as login credentials, personal details, and financial transactions, from malicious actors.

HSTS also prevents protocol downgrade attacks, where attackers trick the browser into using the less secure HTTP, and cookie hijacking, where session cookies are intercepted over an unsecured connection.

How Does HSTS Work?

HTTP Strict Transport Security (HSTS) is a mechanism that ensures a web browser always uses a secure HTTPS connection when communicating with a website. It works by allowing websites to declare themselves accessible only via HTTPS, thus preventing various attacks associated with the less secure HTTP protocol.

When a user first visits a website that supports HSTS, the server responds with a special HTTP header called Strict-Transport-Security. This header specifies a max-age value, which indicates the period (in seconds) for which the browser should enforce HTTPS-only connections for the site. The header might also include an includeSubDomains directive, indicating that all subdomains should also be accessed using HTTPS.

Once the browser receives this header, it records and starts enforcing the HSTS policy. If the user attempts to visit the site or its subdomains using HTTP during the specified max-age period, the browser automatically converts the request to HTTPS, ensuring a secure connection. Even if the user manually types "http://" in the browser’s address bar, the browser will change it to "https://" before making the request.

If the HSTS policy includes subdomains, this protection also extends to them, further securing the site’s entire domain structure. This mechanism effectively eliminates opportunities for attackers to intercept or tamper with the connection by exploiting HTTP vulnerabilities.

HSTS Requirements

HTTP Strict Transport Security has several requirements that must be met for it to function correctly and effectively secure web communications. Here are the key requirements:

  • HTTPS implementation. The website must support HTTPS and have a valid SSL/TLS certificate. HSTS cannot be implemented on a site that only supports HTTP, as the entire purpose of HSTS is to enforce secure HTTPS connections.
  • HSTS header. The server must send the HSTS header (Strict-Transport-Security) in its HTTPS responses. This header includes the max-age directive, which specifies how long the browser should remember to enforce HTTPS for the site. An example of an HSTS header is:
Strict-Transport-Security: max-age=31536000; includeSubDomains
  • Max-age directive. The max-age directive is mandatory and defines the duration in seconds for which the browser should enforce HTTPS for the site. For instance, max-age=31536000 sets the policy for one year.
  • IncludeSubDomains directive. This optional directive extends the HSTS policy to all subdomains of the site. If included, all subdomains must also support HTTPS.
  • Preloading (optional but recommended). Preloading involves submitting the site to the HSTS preload list, a list maintained by browser vendors. Once a site is preloaded, browsers will enforce HTTPS for it and its subdomains from the first visit, even before receiving the HSTS header. To qualify for preloading, the site must serve an HSTS header with max-age of at least one year (31536000), include the includeSubDomains directive, and include the preload directive in the header.
  • No mixed content. The site must avoid mixed content, which occurs when HTTPS pages load resources (such as images, scripts, or stylesheets) over HTTP. Mixed content undermines the security of HTTPS and can cause browsers to block such resources or show security warnings.
  • Redirects. Any HTTP requests to the site should be redirected to HTTPS before HSTS is applied. This ensures that users who initially visit the site via HTTP are directed to the secure version.

HSTS Limitations

HTTP Strict Transport Security (HSTS) is a powerful security mechanism that comes with some limitations, including:

  • Initial insecure connection. The very first connection to a website is not protected by HSTS, leaving it vulnerable to man-in-the-middle attacks. Until the browser receives the HSTS header, the connection might occur over HTTP.
  • Misconfiguration risks. Incorrectly configuring HSTS, such as setting a very long max-age for a site that is not ready for full HTTPS enforcement, can lead to issues. Other examples of misconfiguration include HTTPS not being fully implemented or mixed content issues. If this occurs, users experience broken functionality or accessibility problems.
  • Subdomain coverage. If the includeSubDomains directive is not used, subdomains are not protected by the HSTS policy. This can leave them vulnerable to attacks, undermining the security benefits of HSTS.
  • Site accessibility. If a site’s SSL/TLS certificate expires or is misconfigured, users will be unable to access the site until the issue is resolved, as HSTS mandates HTTPS connections only.
  • Cache issues. Once a browser receives an HSTS header, it will enforce HTTPS for the site until the max-age period expires. If a site no longer wishes to use HTTPS or changes its configuration, users might still be forced to use HTTPS due to cached HSTS policies.
  • Unsupported browsers. Not all browsers support HSTS. Users with older or less common browsers that do not recognize the HSTS header will not benefit from its security protections.
  • Preloading drawbacks. While preloading enhances security, it is a commitment. Once a site is included in the HSTS preload list, it cannot be easily removed, and any issues with HTTPS on the site result in significant access problems for users.
  • Impact on performance. Forcing HTTPS introduces slight performance overhead due to the encryption and decryption processes. While generally minimal, it can be noticeable for high-traffic websites or users with slower connections.

HSTS Browser Compatibility

The following table compares HSTS compatibility with most commonly used browsers today.

BrowserSupported Versions
Google Chrome4 and later
Mozilla Firefox4 and later
Microsoft Edge12 and later
Apple Safari7 and later
Opera12 and later
Internet ExplorerNo support

HSTS Deployment Best Practices

Effectively deploying HTTP Strict Transport Security (HSTS) requires following best practices to ensure robust security and minimize potential issues. Here are some best practices for deploying HSTS:

  • Ensure full HTTPS support. Before enabling HSTS, make sure your entire site supports HTTPS, including all subdomains and resources. Mixed content can cause issues when HSTS is enforced.
  • Configure SSL/TLS correctly. Use strong SSL/TLS configurations to avoid vulnerabilities. Ensure your SSL/TLS certificates are valid, up-to-date, and correctly installed.
  • Set appropriate max-age. Start with a short max-age value (e.g., one day) to test the implementation and ensure everything works correctly. Gradually increase the max-age to a longer duration (e.g., one year) once you’re confident in the setup.
  • Include subdomains. Use the includeSubDomains directive to ensure that all subdomains are covered by the HSTS policy, providing comprehensive protection across your entire domain.
  • Use preloading. Submit your site to the HSTS preload list to ensure that browsers enforce HSTS from the first visit. This requires setting a max-age of at least one year, including the includeSubDomains directive, and adding the preload directive to your HSTS header.
  • Redirect HTTP to HTTPS. Set up server-side redirects from HTTP to HTTPS. This ensures users who initially access your site via HTTP are redirected to the secure version.
  • Monitor and test. Regularly monitor your site for SSL/TLS issues, mixed content, and other potential problems. Use tools like SSL Labs’ SSL Test to check your configuration and ensure it meets best practices.
  • Update security policies. Keep your security policies and configurations, including HSTS, regularly updated with the latest recommendations and practices.
  • Inform users and stakeholders. Communicate the changes to your users and stakeholders, explaining the benefits and potential impacts of HSTS implementation. This helps manage expectations and ensures that any issues are promptly reported and addressed.
  • Prepare for emergencies. Have a plan in place for handling emergencies, such as certificate expiration or configuration errors. You should be able to remove your site from the HSTS preload list if necessary, although this process can take time due to browser update cycles.

Anastazija
Spasojevic
Anastazija is an experienced content writer with knowledge and passion for cloud computing, information technology, and online security. At phoenixNAP, she focuses on answering burning questions about ensuring data robustness and security for all participants in the digital landscape.