Internet security is a growing priority, and HTTP Strict Transport Security (HSTS) has become a key standard for protecting communications between browsers and websites. Defined in RFC 6797 and published in November 2012 by the Internet Engineering Task Force (IETF), HSTS allows websites to declare themselves accessible only via secure connections, preventing exposure to man-in-the-middle attacks and other threats.

What is HTTP Strict Transport Security (HSTS)?

HSTS is a web security policy that forces browsers to connect exclusively through HTTPS, preventing the use of HTTP. The directive is set via the HTTP Strict-Transport-Security header and has the following effects:

  • Forces the use of HTTPS: Automatically converts any attempt to access a site via HTTP into an HTTPS connection before making the request.
  • Prevents “click-through insecurity”: Stops users from bypassing security warnings related to TLS/SSL certificates.
  • Protects against man-in-the-middle (MITM) attacks: Reduces vulnerability to attackers intercepting and modifying communication between users and the server.

How HSTS Works

When a browser receives the HSTS header in a valid HTTPS response, it stores the information and enforces the policy on future connections to the same site. This involves:

  1. URL Transformation: If a user attempts to access an HSTS-protected domain using HTTP, the browser automatically changes the protocol to HTTPS before sending the request.
  2. Blocking Insecure Connections: If there is an issue with the site’s security certificate, the browser blocks the connection without allowing exceptions.
  3. Policy Persistence: The policy duration is specified with the max-age parameter, which defines how long (in seconds) the browser should enforce HSTS for the site.

Implementation Example

To enable HSTS on a web server, the following response header should be included:

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

This header indicates that:

  • The policy will be enforced for one year (31,536,000 seconds).
  • All subdomains will also be protected (includeSubDomains).

To disable HSTS, the following header can be sent:

Strict-Transport-Security: max-age=0

This instructs the browser to remove the stored HSTS policy for the domain.

Advantages of HSTS

Enhanced User Security

By preventing insecure connections, HSTS protects against SSL stripping attacks, where an attacker intercepts and downgrades HTTPS traffic to HTTP without the user noticing.

Performance Improvements

Since browsers remember that a site only allows HTTPS, unnecessary redirects are avoided, reducing latency and improving page load times.

Compliance with Best Practices

HSTS implementation is a crucial step in adopting HTTPS by default, aligning with security policies recommended by organizations such as Google and Mozilla.

Considerations and Limitations

Vulnerability on First Connection

HSTS cannot protect a user’s first visit to a website if they manually enter the address using HTTP. During this initial access, an attacker could intercept and modify the connection. To mitigate this risk, browsers maintain HSTS preload lists, which include certain sites as HSTS-protected by default.

Impact on Subdomains

If a site enables includeSubDomains, but some subdomains do not support HTTPS, users will be unable to access them. This can affect internal services or legacy systems.

Difficulty in Disabling HSTS

Once a browser has recorded a domain with HSTS, removing the policy can be challenging, as users must manually delete it from their browser settings. Additionally, if a site is included in a browser’s HSTS preload list, the only way to remove it is to request removal from each browser vendor.

Conclusion

HTTP Strict Transport Security is a fundamental tool for enhancing web security. Its implementation ensures that users always connect to a site via secure connections, eliminating vulnerabilities associated with HTTP. However, its configuration must be carefully planned, especially in environments with multiple subdomains or services that still rely on HTTP.

For system administrators and developers, adopting HSTS not only strengthens user security but also optimizes performance and ensures compliance with modern web security standards.

Source: RFC 6797

Scroll to Top