HTTP Headers

HSTS: Protect Your Site from SSL Stripping Attacks

Learn what HTTP Strict Transport Security is, why it is essential against protocol downgrade attacks, and how to implement it in Nginx, Apache and Cloudflare.

2026-08-03·Reading time: 7 min

HTTP Strict Transport Security (HSTS) is an HTTP response header that instructs the browser to always connect via HTTPS, even if the user types 'http://' or accesses from a link without a protocol. Once the browser receives this header, it remembers the policy for the duration specified in max-age and rejects any unencrypted connection to the domain without attempting it.

The Problem HSTS Solves: SSL Stripping

Even if your site redirects from HTTP to HTTPS, without HSTS an attacker on the same network (public Wi-Fi, compromised corporate network) can intercept the initial HTTP request before the server can redirect the user. The attacker acts as a man-in-the-middle, serving the site in plain text while communicating with the server over HTTPS. This attack is called SSL Stripping and is completely invisible to the user. With HSTS active, the browser directly rejects any HTTP connection attempt, eliminating this attack vector.

Implementation in Nginx

nginx
# In the server block of your HTTPS site
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

# The 'always' parameter ensures the header is sent
# even in error responses (4xx, 5xx)

# Reload configuration without dropping active connections
sudo nginx -s reload

Implementation in Apache

apache
# In the *:443 VirtualHost of your site
<VirtualHost *:443>
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</VirtualHost>

# Enable mod_headers if not already active
sudo a2enmod headers
sudo systemctl restart apache2

Implementation in Cloudflare

If using Cloudflare as a proxy (orange cloud), go to the dashboard: SSL/TLS → Edge Certificates → HTTP Strict Transport Security (HSTS). Enable HSTS, set max-age to 12 months, and check 'Include subdomains' and 'Preload' only if all your subdomains serve HTTPS correctly. Cloudflare automatically injects the header into all responses.

HSTS Parameters Explained

  • max-age=31536000: the browser remembers the policy for 1 year (31,536,000 seconds). The minimum recommended for preloading is exactly 1 year.
  • includeSubDomains: applies HSTS to all subdomains. Only enable this if subdomains like mail., api. or blog. also serve HTTPS.
  • preload: signals that the domain wants to be included in the HSTS Preload List, which is built directly into Chrome, Firefox, Safari and Edge.

HSTS Preloading: Protection from the Very First Visit

The HSTS Preload List is hardcoded into browsers. Included domains have HSTS active by default even before the first visit, eliminating the only instant when an SSL Stripping attack could work. To request inclusion, visit hstspreload.org. Important: once included in the list, reverting can take months — only request it when all subdomains work correctly over HTTPS.

Most Common Mistakes

  • Enabling includeSubDomains without HTTPS on all subdomains: those subdomains will become inaccessible since the browser will refuse the HTTP connection.
  • max-age below 10,886,400 seconds (126 days): Google Search Console warns about very short values.
  • Sending the HSTS header in the HTTP VirtualHost (port 80): browsers ignore HSTS on insecure connections.
  • Forgetting the 'always' parameter in Nginx: the header won't be sent in error responses (4xx, 5xx).

DomainScored automatically checks the HSTS header in the HTTP Headers module: whether it's active, the max-age value, and whether it includes subdomains and preload. The analysis includes exact fix instructions for your server.

Check whether your domain has these issues with DomainScored.

Analyze my domain
We use necessary cookies to keep you signed in and protect you against CSRF attacks. If you accept, we will also load Google advertising, which sets its own cookies. If you decline, the site works exactly the same.