I was looking at HTTP Strict Transport Security (HSTS) implementation in firefox. Firefox stores this data for sites in a file called SiteSecurityServiceState.txt

I see entries in it like -

support.mozilla.org:HPKP 3 17242 1483383397412,1,0,r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E=WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18= web.facebook.com:HSTS 18 17227 1504027319798,1,0

HSTS is what I was looking for. It is configured in your webserver to send corresponding header in response header. Browser stores it and makes sure all subsequent requests always go to https and certificate in correct - does not allow to add exception (atleast in firefox).

So whats this HPKP and how does it work? Is it some other security configuration?

2 Answers 2


HSTS and HPKP are different concepts.

An HTTP Strict Transport Security (HSTS) header instructs clients to use HTTPS for all future connections to a website, thereby preventing downgrade attacks. In contrast to HPKP, it doesn't influence how certificates are validated.

An HTTP Public Key Pinning (HPKP) header instructs clients to pin a specific public key to a domain. So, if a HPKP-supporting browser encounters a HPKP header, it will remember the specified public key hashes and associate them with that domain. In the future (until the specified max-age timeout expires), the browser will only accept a certificate for that domain if any key in the certificate's trust chain matches one of the associated hashes.

HPKP mitigates the risk of an attacker issuing rogue certificates after having compromised a certificate authority (occasionally happens). Your browser would normally be unable to detect a fraudulent certificate if it has been correctly signed by a trusted CA. (Although there are mechanisms to detect certificate revocations, e.g. OCSP/CRLs.) But if you have pinned a particular certificate to a website beforehand, the attacker won't be able to replace it without triggering a browser waning.

Note that since HPKP is trust-on-first-use, it will (similar to HSTS) only be effective after your first visit to a website. An exception to that are preload lists maintained by browser vendors for high-profile websites (Google, Facebook, Twitter, etc.). This means that even if DigiCert (Facebook's CA) would be compromised today, an attacker would be unable to intercept your connection to Facebook because the original certificates' public keys are preloaded in your browser.

  • May I ask why you mention hashes in plural? When we connect to a given site and it present us it's crrtificate is it not containing one public key attached to it? Or do you refer to fingerprints on the cert itself plus any intermediate it might send as well? Could you please clarify?
    – cyzczy
    Mar 17, 2017 at 17:28
  • @Arminius thanks for the details. Have a q though. Certs as you know they expire. So how come certs for high profile sites are preloaded in the browsers? If that's the case then for each cert expiry browsers have to give out a new release and older versions would never work. But that's not the case. Mar 18, 2017 at 5:55
  • @Aniket The expiry dates are stored too. If the certificate's expired, the HPKP won't work.
    – wizzwizz4
    Mar 21, 2017 at 18:38
  • @Arminius Great answer but could you please elaborate more on the line "This means that even if DigiCert (Facebook's CA) would be compromised today, an attacker would be unable to intercept your connection to Facebook because the original certificates' public keys are preloaded in your browser" May 1, 2017 at 19:30
  • 2
    Comment on HPKP in general: don't use it. It's a good way to nuke your site off the Internet for months/years even if you don't screw anything up (but your CA or CDN or hosting provider screws up). It's not a well thought out protocol extension. See blog.qualys.com/ssllabs/2016/09/06/…
    – rmalayter
    May 2, 2017 at 1:36

It's http public key pinning. It is intended to provide some (but not total) protection against compromised CAs.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.