Bypassing HTTP Strict Transport Security (HSTS)

And other problems with HTTP and HTTPS

Hanno Böck

Once there was HTTP without encryption

In 1995, Netscape introduced SSL - today known as TLS - and HTTPS


  • Encryption
  • Integrity
  • Authentication


  • Expensive
  • Optional security
  • Mixing secure and insecure contexts

Mixing secure and insecure contexts

Mixing secure and insecure contexts isn't just a problem with HTTP; it's also a problem with e-mail protocols

Talk STARTTLS at Bornhack

Today, we want to talk about mixing insecure HTTP with secure HTTPS


Cookies are bound to the hostname (e.g., or the whole domain (e.g.,


Set Cookie over HTTPS

Read Cookie over HTTP

Cookie Secure Flag

RFC 2109, 1997

Optional. The Secure attribute (with no value) directs the user agent to use only (unspecified) secure means to contact the origin server whenever it sends back this cookie.

The user agent (possibly under the user's control) may determine what level of security it considers appropriate for "secure" cookies. [...]

RFC 6265, 2011

The Secure attribute limits the scope of the cookie to "secure" channels (where "secure" is defined by the user agent). When a cookie has the Secure attribute, the user agent will include the cookie in an HTTP request only if the request is transmitted over a secure channel (typically HTTP over Transport Layer Security (TLS) [RFC2818]).

RFC 6265, 2011, continued

Although seemingly useful for protecting cookies from active network attackers, the Secure attribute protects only the cookie's confidentiality. An active network attacker can overwrite Secure cookies from an insecure channel, disrupting their integrity [...]

A fix for that problem was only provided very recently

__Host- / __Secure- prefix

Still just a draft, but use them!


Just because we have a Secure flag for cookies does not mean people will use it

Session-Cookies and SSL, 2008

Found and reported problems in various PHP web apps and described a practical attack on eBay

Firesheep (2010)

Plugin that made Cookie stealing attacks easy

Other Cookie Security features (not TLS related)

  • HttpOnly
  • SameSite=Lax/Strict/None

This is how your Cookies should look like

Set-Cookie: __Host-SESSID=c60fu856m8u25vrv; path=/; Secure; HttpOnly; SameSite=Lax

Cookies are not the only problem of mixing secure HTTPS and insecure HTTP


Let's say you want to have a very secure website, so you redirect all HTTP calls to HTTPS

HTTP/1.1 301 Moved Permanently

The redirect is still HTTP and is not protected!

SSL Stripping

Moxie Marlinspike, 2009

A network attacker can prevent the redirect and serve a fake webpage over HTTP

Speaking of Redirects...

I see something like this quite often:

  • redirects to
  • redirects to

https -> http -> https

Don't do that!

How can we fix SSL Stripping?

HTTP Strict Transport Security (HSTS)

RFC 6797, 2012

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


HSTS Expires!

How do you set the time on your computers?

Network Time Protocol (NTP)

NTP is insecure by default and had no TLS support until 2020

Delorean attack on HSTS

                               _.-="_-         _                                 
                          _.-="   _-          | ||"""""""---._______     __..    
              ___.===""""-.______-,,,,,,,,,,,,`-''----" """""       """""  __'   
       __.--""     __        ,'                   o \           __        [__|   
  __-""=======.--""  ""--.=================================.--""  ""--.=======:  
 ]       [w] : /        \ : |========================|    : /        \ :  [w] :  
 V___________:|          |: |========================|    :|          |:   _-"   
  V__________: \        / :_|=======================/_____: \        / :__-"     
  -----------'  ""____""  `-------------------------------'  ""____"" 

Jose Selvi, 2014

Luckily, we have Network Time Security (NTS) now

RFC 8915, 2020

Optional, usually not enabled by default, enable it!

HSTS is Trust-on-First-Use

First connection problem


HSTS preload list

  • ~140.000 entries
  • 15 Megabyte uncompressed
  • 1 Megabyte compressed


Hanno in late 2023:

How exactly does the includeSubDomains flag in HSTS work?

I tried a few things

This does not look right!

Assume the following

  • sets an HSTS policy with includeSubDomains
  • sets an HSTS policy without includeSubDomains
  • Which policy applies to
  • Can you open
  • RFC says No
  • Chrome blocks it
  • Firefox before version 122 opens it

In Firefox before 122, any subdomain with an HSTS policy without includeSubDomain disables HSTS for all sub-sub-domains.

This even works with preloading!

Mozilla developers immediately agreed that this is a vulnerability and needs to be fixed


Fixed in Firefox 122

wget also affected

(fixed in 1.24.5, low impact)

Why is this a problem?

Imagine the following:

  • uses HSTS, includeSubDomains, *AND* preloading
  • sets a Cookie for without the "Secure" flag. (HSTS already makes sure it's secure!)
  • uses HSTS without includeSubDomains


  • Attacker sends user to without includeSubDomains policy
  • Attacker sends user to - Cookie is transmitted in plain text has all the conditions for this attack to work

Have I reported this to Netflix?


Expires: 2025-01-01T06:00:00.000Z

Bugbounty as the only security contact is a problem

  • Bugbounty triagers are trained to reject as much as possible (sad, but true)
  • Technically, this is not a vulnerability on, "just" a non-ideal configuration

Please note: This program or engagement does not allow disclosure.

In preparation for this talk, I wanted to create a demo

I tried the demo in Firefox 121 (vulnerable), it worked as expected.

I tried the demo in Firefox 122 (fixed), it still worked 🤔

That was unexpected

As an attacker, how can you make sure a user opens another webpage?


Firefox does not let subresources set HSTS policies...

This was an attempt to fix another bug that is also undermining HSTS...

... and it did not even fix it.

Even before that, Firefox used partitioning for HSTS on subresources (similar to Cookies)

HSTS is a good feature, and you should use it, but its implementation is not necessarily robust, particularly in Firefox

Demo time!

Recommendations for Web Developers

Use HSTS and always set includeSubDomains

Use HSTS preloading for important domains

Even with HSTS, use other tools to prevent plaintext leakage


Always redirect from http:// to https://

If your main webpage is on the www subdomain

  • First redirect from to
  • Then from to

This makes sure you protect all subdomains.

Avoid insecure redirects

No https:// -> http:// -> https://


Should always have the "Secure" flag, HSTS is no excuse for not having it

Use __Host- prefix if possible, __Secure- prefix otherwise

Recommendation for Users

Enable HTTPS only mode in your browser

Thanks for listening!

Any questions?


Need help with HTTPS, HSTS, TLS?
Contact me: