What is HSTS and How to Use HTTP Strict Transport Security? 

What is HSTS and How to Use HTTP Strict Transport Security? 


Online security threats are always a concern. One key technology that plays a crucial role to reduce  this issue is HTTP Strict Transport Security (HSTS).  

The security of web communications would be significantly compromised without HSTS. It is a web security policy mechanism that helps protect websites against man-in-the-middle attacks such as protocol downgrade attacks and cookie hijacking. 

Let us look into the details of what HSTS is, how it works, and how you can implement it on your website to enhance its security and protect your users’ data. 

What is HSTS?  

HSTS, or HTTP Strict Transport Security, is a web security policy mechanism that helps to protect websites against man-in-the-middle attacks such as protocol downgrade attacks and cookie hijacking. It allows web servers to declare that web browsers (or other complying user agents) should only interact with it using secure HTTPS connections, and never via the insecure HTTP protocol. 

The need for HSTS arose from the increasing prevalence of man-in-the-middle attacks, where attackers could intercept and alter communication between a user’s browser and a website, often by downgrading the connection from HTTPS to HTTP.  

The HSTS protocol was developed to mitigate this risk by ensuring that once a browser has connected to a website over HTTPS, it will continue to use HTTPS for all future connections to that site. 

HSTS was first proposed in 2009 by Jeff Hodges from PayPal, Collin Jackson, and Adam Barth. It was standardized by the Internet Engineering Task Force (IETF) in RFC 6797 in November 2012. Since then, it has been widely adopted by web browsers and websites as a critical security feature.  

The protocol continues to evolve, with ongoing discussions about enhancements such as preloading HSTS information into browsers to protect users on their first visit to a site. 

How HSTS Works 

HTTP Strict Transport Security works by instructing web browsers to only communicate with a website using secure HTTPS connections, rather than insecure HTTP.  

Here is a step-by-step explanation of how HSTS works: 

  1. A user’s web browser makes an initial request to a website using HTTPS. 
  2. The website’s server responds with an HTTPS response that includes the HSTS header. This header contains the max-age attribute, which specifies the duration (in seconds) that the browser should remember to only access the site via HTTPS. It can also include the includeSubDomains attribute, which indicates that the HSTS policy should apply to all subdomains of the websites as well. 3
  3. The browser receives the HSTS header and stores the website’s HSTS policy. From this point forward, the browser will automatically convert all HTTP requests to HTTPS for the site, ensuring that all communication is encrypted and secure. 
  4. If the user or any link on the website attempts to access the site using HTTP, the browser will automatically redirect the request to HTTPS before it leaves the browser. This prevents any possibility of a man-in-the-middle attack intercepting and reading the unencrypted HTTP traffic. 
  5. The HSTS policy remains in effect for the duration specified by the max-age attribute. Once this time expires, the browser will no longer automatically enforce HTTPS for the site unless it receives a new HSTS header. 

Typically, each time the browser accesses the website, it will receive the HSTS header again, which resets the max-age timer, effectively renewing the policy. 

Significance of HSTS  

After understanding what HSTS is and how to use it, let us delve deeper to see why it is important. 

Here are some key points about the significance of HSTS: 

Enhanced Security:

HSTS ensures that all communication between the user’s browser and the web server is encrypted, reducing the risk of eavesdropping, man-in-the-middle attacks, and other forms of cyber threats. 

Prevention of SSL Stripping:

SSL certificate is important for securing your website’s information and lets visitors know your site is safe. SSL stripping is a technique used by attackers to downgrade a secure HTTPS connection to an insecure HTTP connection. HSTS helps prevent this by telling the browser to only use HTTPS for a specified period. 

Reduction of HTTPS Overhead:

When a website uses HSTS, it tells the browser to use a secure HTTPS connection right from the start. This means that when you visit the website, your browser automatically uses HTTPS without having to be redirected from an HTTP connection. This reduces the extra steps and time it takes to switch from an insecure to a secure connection, making the website load faster and more securely. 

Improvement in SEO:

Google and other search engines prefer websites that are safe. Using HTTPS makes your website secure, and HSTS ensures your website always uses HTTPS. This can help your website appear higher in search results, making it easier for people to find. 

Google conducts an HSTS check as part of its security measures, particularly for its Chrome browser. Chrome maintains an HSTS preload list, which is a list of domains that are hardcoded into the browser to be accessed only via HTTPS. This list includes domains that have requested to be preloaded and have met certain criteria, including having a valid HSTS policy. 

Building Trust:

HTTPS encrypts data between users and websites, making it difficult for hackers to intercept sensitive information. It also verifies the website’s identity, preventing malicious impersonation. Data integrity is ensured, guaranteeing that transmitted data remains unchanged. Visual indicators like padlock icons or “Secure” labels help build trust with users, as they assure them that their data is being transmitted securely. 


For certain industries, there may be regulatory requirements to ensure data is transmitted securely. Implementing HSTS can help meet these compliance requirements. 

For instance, the Reserve Bank of India (RBI) has issued guidelines for the security of online banking and payment systems, which include recommendations for the use of secure communication protocols like HTTPS. By adopting HTTPS and HSTS, banks and financial institutions can comply with these guidelines and enhance the security of their online services. 

How to Enable HSTS?  

To enable HTTP Strict Transport Security for your website you will need to follow these steps: 

1. Obtain an SSL Certificate:

Before enabling HSTS, make sure that your website is accessible via HTTPS by obtaining and installing an SSL certificate. 

2. Access Your Website’s Files:

Connect to your web server using a FTP client or through the file manager in your hosting control panel. 

3. Edit the .htaccess File:

Locate the .htaccess file in your website’s root directory. If you do not have one, you can create it. 

4. Add HSTS Header:

Add the following line to your .htaccess file: 

Header always set Strict-Transport-Security “max-age=31536000; includeSubDomains; preload” 

This line instructs browsers to only connect to your website via HTTPS for the next year, including all subdomains. 

5. Save Changes:

Save the .htaccess file and upload it back to your server if you edited it locally. 

6. Test Your Website:

After implementing HSTS, test your website to ensure that it is only accessible via HTTPS and that there are no mixed content issues. 

7. Optional – Submit to HSTS Preload List:

If you want to add your domain to the HSTS preload list, which is built into browsers to enforce HTTPS connections before the first visit, you can submit your domain at hstspreload.org. Make sure you understand the requirements and implications before doing so. 

Keep in mind that enabling HSTS is a significant security commitment. Once enabled, you must ensure that your website is always accessible via HTTPS, or users will be unable to access it. 

To conclude, HTTP’s strict transport security helps prevent several types of cyber-attacks, including man-in-the-middle attacks, protocol downgrade attacks, and cookie hijacking. Therefore, website owners need to implement HSTS as part of their security measures to protect both their users and their digital assets. 



Web hosting specialist with a knack for creativity and a passion for baking, serving up tech solutions with a side of sweetness.