← Back to blog

Certificate Pinning: How It Works, When to Use It, and mTLS

November 18, 2026
Certificate Pinning: How It Works, When to Use It, and mTLS

Certificate pinning makes a client trust one specific certificate or public key for a server, instead of any certificate that a trusted certificate authority (CA) has signed. It narrows who can impersonate your server. It also ties your app's uptime to your certificate lifecycle: if the certificate or key changes and the pin does not, clients fail. Pinning is worth it only when you control renewals and can see what your server presents at any moment. Mutual TLS (mTLS) is a different tool that proves the client's identity to the server.

Pingfloat
Check Your Certificate Before Pinning
Verify the SSL certificate your server presents to help plan certificate changes and avoid surprises during pinning.
Visit

TL;DR

  • Pinning stores an expected certificate or public key in the client and rejects anything else, even a validly signed certificate.
  • Pin the public key (SPKI), ship a backup pin, and plan every renewal before you ship the pin.
  • Browser-based HPKP is deprecated. Pinning now matters mainly for mobile apps, thick clients and server-to-server calls.
  • mTLS is not pinning: pinning lets the client verify the server, while mTLS also makes the server verify the client.
  • Check the certificate your server really presents with the SSL Checker before and after every rotation.

Table of Contents

What certificate pinning is

Normally a client accepts a server certificate if it chains to a CA in the device or browser trust store. That store holds many CAs, and a mistake or compromise at any one of them can produce a certificate for your domain that a client will accept.

Pinning closes that gap. OWASP defines pinning as associating a host with its expected X.509 certificate or public key. If more than one identity is acceptable, the client accepts a match to any member of a set of pins, called a pinset.

Android's documentation describes the motivation in the same terms: an app normally trusts all pre-installed CAs, so if one of them issued a fraudulent certificate, the app would be exposed to an on-path attacker. Pinning limits the certificates the app accepts.

In short, pinning replaces "anyone the platform trusts" with "only the identities I listed".

What certificate pinning is

How a pin check works

The check happens during the TLS handshake, the exchange where client and server agree on encryption and the server presents its certificate:

  1. The client connects and receives the server's certificate chain.
  2. It runs the normal validation: chain, hostname, expiry.
  3. It compares the certificate or its public key with the stored pin.
  4. On a mismatch, the connection fails. OWASP recommends failing the connection and logging the mismatch.

The pin check is an extra gate on top of normal validation. It never replaces it.

Certificate or public key: are they the same?

They are not. A certificate is a signed document that contains a public key, a hostname, validity dates and an issuer. The public key is one field extracted from it. OWASP separates pinning the whole certificate from pinning the public key and encourages pinning the Subject Public Key Info (SPKI), which is the public key structure plus its algorithm.

The practical difference matters at renewal:

Pin typeWhat it matchesWhat happens when you renew
Whole certificateThe exact certificate fileBreaks on every renewal, because the new certificate is a new file
Public key (SPKI)The key inside the certificateSurvives renewal only if the new certificate reuses the same key pair
Backup pinA key you have generated but not deployed yetLets you switch to the new key without breaking clients

Reusing the same key to keep pins valid is possible, but OWASP calls that bad key management except in an emergency. The cleaner design is to pin a current key plus a backup key.

Where pinning still makes sense

Browsers used to support HTTP Public Key Pinning (HPKP), a header that let a site tell browsers which keys to trust. OWASP notes HPKP is deprecated and no longer recommended or supported by modern browsers. Cloudflare says it does not support HPKP for its universal, advanced or custom hostname certificates, because edge certificate rotation could take pinned domains offline.

The same OWASP guidance says pinning can still benefit mobile apps, thick clients and server-to-server communication. In those cases you control both ends and can ship an update. Public-key pinning can protect against an attacker who obtained a valid certificate through a validation weakness, CA compromise or administrative access on the client.

Mobile certificate pinning

Mobile apps are the most common case. You publish the app, you know exactly which backend it talks to, and the pin travels inside the app. Android's network security configuration lets you declare pins in XML. It also supports an expiration attribute: if it is not set, the pins do not expire. The documentation explains that an expiration helps avoid connectivity problems for users who do not get updates, such as when they disable app updates.

That detail is the heart of the operational problem. A pin lives in a shipped binary. A certificate lives on your server. They change on different schedules, and users do not update on your schedule.

What pinning does not do

OWASP's mobile testing guide says pinning reduces the set of trusted CAs and can shrink the attack surface. It also says an attacker who controls the device can disable the app's pinning logic, and that pinning does not by itself stop backend abuse or server-side vulnerabilities.

So pinning is one layer. It protects the network path between a client you shipped and a server you run. It does not secure the device, the API logic or your authentication. Pair it with sound TLS configuration (see our guides to TLS versions and TLS cipher suites) and the response headers in our security headers checklist.

The operational risk: renewals and rotation

Microsoft's Azure guidance states that static pinning of publicly trusted TLS certificates creates operational risk, because changes to CAs, keys, chains and trust stores can make pinned clients fail. Its conclusion is that static public Web PKI pinning often brings more operational risk than security benefit when the certificates change outside the application's control.

The lesson is not to avoid pinning. It is to pin only what you control. Cloudflare's suggested route to controlled pinning is to upload a custom certificate, control renewal and key material, and test renewal in staging. Changing the key can still break clients pinned to the previous key, so the key is the thing to manage.

How the pin gets to the client

OWASP lists three ways: preload the pin at development time, learn it on first use (trust on first use, or TOFU), or update it over an unpinned channel. It prefers out-of-band preloading because it reduces the chance that an attacker taints the pin.

A worked rotation example

Suppose your mobile app pins the SPKI hash of your API's current key and a backup key you generated and keep offline.

  1. Ship app version 5.2 with both pins and, on Android, a pin expiration date that suits your update cadence.
  2. Wait until most active users have updated. Your analytics tell you how many.
  3. Generate the new certificate using the backup key. The backup pin already in the field now matches.
  4. Deploy the certificate and verify what the server presents.
  5. Ship app version 5.3 with a new backup pin, so the next rotation has a safety net.

Skip step 2 or step 4 and some clients will fail. Step 4 is where most teams get surprised: a load balancer, CDN edge or secondary region still serves the old certificate, or an incomplete chain.

Keep an eye on what your server presents

A pin is only as safe as your knowledge of the certificate behind it. For every host a client pins, you want to know:

  • which certificate and chain the server sends right now
  • when that certificate expires
  • whether every endpoint behind the hostname serves the same one
  • whether the endpoint is reachable at all

Our SSL Checker is a free tool that checks the SSL certificate of a hostname, and our Website Uptime Monitor watches whether the site responds. If a rotation goes wrong, a pinned client fails closed, so you want to find out before your users do. Our practical guide to SSL certificate monitoring covers the routine, and the walkthrough on checking an SSL chain with one OpenSSL command helps when you want to verify a chain from a terminal.

When a pinned client reports a failure, the cause is usually in the handshake. The five command line checks for SSL handshake failures give you a quick order of attack.

Mutual TLS: what it is and how it differs

People often search for pinning and mTLS together because both involve certificates, but they answer different questions.

In ordinary TLS, the client authenticates the server. OWASP describes mTLS as TLS in which the server also authenticates the client, using a client certificate and proof of possession of its private key.

The handshake adds a step. After the server has authenticated itself, it sends a certificate request, and the client returns its certificate. SSL.com's guide notes that client certificates need the Client Authentication extended key usage, a field in the certificate that says what it may be used for. The same guide lists employees, contractors, customers and IoT devices as parties mTLS can authenticate.

Ordinary TLS and mutual TLS handshake comparison

With TLS 1.3, OWASP says the client's proof of key possession is bound to the handshake transcript through a CertificateVerify message, which stops an intermediary from relaying that authentication to a separate TLS connection.

Pinning vs mTLS at a glance

Certificate pinningMutual TLS
Question answeredIs this the server I expect?Who is the client?
Who checksThe clientThe server (in addition to the usual client check of the server)
What is storedExpected server certificate or keyClient certificate and private key, plus the CA the server trusts
Typical useMobile apps, thick clients, service-to-serviceAPIs, internal services, employee and device access
Main failure modeServer key changes and the pin does notClient certificate expires or is not issued

They can run together. A mobile app can pin the server's key and also present a client certificate, so each side has a narrow idea of who the other must be. Both create the same discipline problem: certificates expire, and expiry on either side causes outages.

Choosing your approach

Use this order of questions:

  1. Do you ship the client? If you do not, as with a public website visited by arbitrary browsers, do not pin. HPKP is deprecated.
  2. Do you control the server certificate and key lifecycle? If a CDN or provider rotates keys for you, static pins are risky.
  3. Can you update clients quickly? If not, use an expiration where the platform supports it and keep a backup pin.
  4. Do you also need to identify clients? That is a job for mTLS or another authentication method, not pinning.
  5. Can you observe what each endpoint serves? If not, fix that first.

Perspective

Most pinning incidents we hear about in the developer community are not attacks. They are renewals. Someone rotated a certificate, a pin did not move with it, and an app stopped connecting.

That is why we think of pinning as a monitoring problem as much as a cryptography problem. Our tools are built for developers and IT professionals who need a quick, honest view of a site: what certificate it serves, whether it is up, what the headers and handshake look like. Free, with no installation or account for core functionality.

If you pin, check the certificate before the change, after the change and on a schedule. If you use mTLS, do the same for the client certificates you issue. A pin you cannot verify is a guess.

 

Andreas

Check your certificate before you pin

Pingfloat is a free suite of web tools for developers and IT professionals. The SSL Checker lets you inspect a host's certificate, and the Website Uptime Monitor tracks availability, with scheduled monitoring available after sign-up. You can see everything else, from traceroute to JWT and header utilities, on pingfloat.com.

Pingfloat

FAQ

What is certificate pinning used for?

It restricts a client to the specific certificate or public key you expect for your server, so a certificate from a different CA cannot be used to impersonate it. It is most useful for mobile apps, thick clients and server-to-server traffic that you control end to end.

Is SSL pinning the same as certificate pinning?

Yes, in everyday use. "SSL pinning" is the older name, and modern connections use TLS, the successor to SSL. The technique is the same: compare what the server presents with a stored pin and reject a mismatch.

Should I pin the certificate or the public key?

Pin the public key (SPKI), as OWASP encourages. A whole-certificate pin breaks at every renewal, while a key pin survives if you keep a planned backup key. Include a backup pin from the start.

Is mutual TLS better than pinning?

They solve different problems, so neither replaces the other. Pinning helps the client trust the right server. mTLS lets the server verify the client with a certificate. Many systems benefit from both.

Does pinning stop an attacker who controls the device?

No. OWASP's mobile guidance says an attacker who controls the device can disable the app's pinning logic. Treat pinning as protection for the network path, and secure the backend separately.

Sources