Advertisement
Intermediate ASP.NET Core, HTTPS, Certificates & Transport Security

What is certificate pinning, and why is it generally discouraged for typical web API scenarios despite its security benefits?

Short answer

Certificate pinning hardcodes a client's trust to one specific certificate (or public key) rather than trusting any certificate issued by a recognized CA, defending against a compromised or rogue CA issuing a fraudulent certificate for your domain -- however, it's generally…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Certificate pinning hardcodes a client's trust to one specific certificate (or public key) rather than trusting any certificate issued by a recognized CA, defending against a compromised or rogue CA issuing a fraudulent certificate for your domain -- however, it's generally discouraged for typical scenarios because it creates a serious operational risk: if the pinned certificate needs to be rotated/renewed (planned or due to compromise) and the pinning configuration isn't updated in lockstep across all clients, those clients become completely unable to connect, a self-inflicted outage that's happened to major companies historically.
// Example of certificate pinning logic (generally NOT recommended for typical scenarios)
var handler = new HttpClientHandler {
    ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => {
        var expectedThumbprint = "AABBCCDD...";
        return cert?.GetCertHashString() == expectedThumbprint;
    }
};
Real-world example
A mobile banking app that implemented certificate pinning for its API calls experienced a complete outage for all users after a routine certificate renewal, since the pinned certificate hash in the already-deployed app version no longer matched, illustrating why pinning requires extremely careful, coordinated rotation planning.
Likely follow-ups
  • What are safer alternatives to full certificate pinning that still improve on default CA trust, like public key pinning with backup pins?
  • In what specific scenarios (like a fixed-purpose IoT device) might pinning's trade-offs actually be worthwhile?
Related topics