What Is Certificate Pinning?
Certificate pinning associates a host or service with an expected X.509 certificate, issuer or public key. During a TLS connection, the client first performs normal certificate validation and then applies the additional pinning rule. If the presented credential does not match the accepted pinset, the client rejects the connection.
A pinset can contain more than one acceptable credential so the service can rotate certificates without immediately breaking every deployed client. Pinning is mainly a client-side trust-hardening technique; it is not a replacement for TLS, hostname verification or certificate-chain validation.
Is Certificate Pinning an Authentication Method?
Pinning participates in server authentication by narrowing which credentials a client will accept for a host. It does not authenticate the end user, and it is not a substitute for MFA, OAuth, mTLS client authentication or application authorization.
The normal web PKI asks whether the certificate chains to a trusted authority and matches the requested hostname. Pinning adds a more restrictive question: does this validated connection also present a certificate or public key that this specific client was preconfigured to trust?
Certificate Pinning vs Standard TLS and mTLS
| Control | What it authenticates | Typical use |
|---|---|---|
| Standard TLS server validation | Server identity through hostname + trusted certificate chain | Normal HTTPS and API clients |
| Certificate/public-key pinning | Further restricts which server credential a controlled client accepts | Exceptional native-client threat models |
| Mutual TLS (mTLS) | Server and client/workload identities | Service-to-service, device and enterprise client authentication |
Pinning is therefore not a replacement for user authentication, OAuth or API authorization. For service-to-service security, mTLS or workload identity frequently solves a different—and more relevant—problem by authenticating both sides of the connection.
Certificate Pinning vs Public-Key Pinning
| Pin type | Advantage | Operational risk |
|---|---|---|
| Leaf certificate | Simple exact match | Breaks on certificate renewal unless pins are updated |
| Intermediate CA | Allows leaf renewal under one issuer | Trusts more certificates than a leaf pin |
| Public key / SPKI | Can survive certificate reissuance with same key | Still breaks when the key rotates |
| Pinset with backup | Supports planned rotation/failover | Requires secure lifecycle and testing |
OWASP’s pinning guidance encourages careful selection of what is pinned and emphasizes backup/rotation planning. Public-key/SPKI pinning can reduce churn when a certificate is reissued using the same key, but long-lived keys have their own security lifecycle considerations.
Certificate Pinning vs HPKP: Do Not Confuse the Two
Application-level pinning in a native client is different from HTTP Public Key Pinning (HPKP), the browser mechanism defined by RFC 7469. HPKP is now considered obsolete by modern browser documentation and should not be treated as a current website-deployment recommendation.
If your requirement is ordinary website transport security, use correctly configured HTTPS, HSTS where appropriate, certificate lifecycle automation and modern TLS. Do not add browser HPKP headers as a substitute for sound certificate management.
When Should You Use Certificate Pinning?
OWASP’s current Pinning Cheat Sheet asks teams to start with “Should I pin?” and answers that, in almost all situations, the answer is no. The incremental protection against CA or trust-store compromise must be weighed against the very real risk of making a client unable to connect after certificate/key rotation, CDN changes, interception-proxy requirements or emergency recovery.
Consider pinning only when you control both the client release process and the server endpoint, can securely distribute backup pins before rotation, can recover from an unexpected key change and have a threat model that standard PKI does not adequately address. Native mobile or tightly controlled enterprise clients are the usual environments where the decision may be defensible.
A Safe Certificate Pinning Implementation Model
Implementation differs by platform, but the architecture should follow this sequence:
- Establish a normal TLS connection and validate the certificate chain and hostname.
- Extract the certificate or public-key material using a platform-supported TLS callback/API.
- Hash or compare the intended stable representation (often SPKI for public-key pinning).
- Compare against a preloaded pinset containing the active and backup pins.
- Fail closed if the pin does not match; do not offer users a “continue anyway” button.
- Log a privacy-safe pin failure signal and surface diagnostics without exposing sensitive connection data.
Normal TLS validation
↓
Hostname + certificate-chain validation
↓
Extract certificate / SPKI
↓
Compare with active + backup pinset
↓
Match → continue Mismatch → fail closedCertificate Rotation, Key Rotation and Backup Pins
The hardest part of pinning is not the first connection—it is changing trust without causing an outage. A safe plan deploys a backup pin in clients before the server starts using the new certificate/key. Only after the new credential is broadly accepted should the old pin be removed in a later client release.
- Maintain at least one tested backup path appropriate to your risk model.
- Track certificate and key expiration well ahead of the release cycle.
- Test disaster recovery for an unexpected key compromise.
- Coordinate CDN, reverse proxy and certificate-management changes with mobile/client releases.
- Do not silently disable pinning on failure; that converts a security control into a bypass.
Certificate Pinning in Mobile and API Clients
Native mobile applications are the most common environment where pinning may be considered because the developer controls the TLS client code and release artifact. Even there, OWASP says the decision should be exceptional rather than automatic.
For service-to-service APIs, mTLS or workload identity can often provide stronger, more manageable mutual authentication than hardcoded server pins. See Ammune’s mTLS API security guide and non-human identity API security.
Common Certificate Pinning Mistakes
- Pinning a leaf certificate with no backup or rotation plan.
- Turning off normal certificate-chain or hostname validation because a pin is present.
- Allowing users to bypass pin failures manually.
- Pinning third-party services you do not control and cannot coordinate with.
- Shipping pins that expire before users are likely to update the app.
- Failing to test disaster recovery when a private key must be revoked immediately.
Alternatives to Certificate Pinning
Before adding pins, ask whether a more operationally resilient control solves the same threat. For service-to-service communication, mutual TLS, private trust anchors, service-mesh identities or workload identity systems can authenticate both ends without embedding a public-server key into every client release. For public clients, Certificate Transparency monitoring and disciplined certificate automation can reduce PKI risk without creating a hard availability dependency.
Native mobile applications that need unusually strong server identity assurance may still justify pinning, but the architecture should compare the expected security gain with update latency, offline users, disaster recovery and third-party endpoint dependencies.
- Use mTLS when mutual machine identity is the real requirement.
- Use private PKI or workload identity for controlled internal environments.
- Monitor certificate issuance and expiration continuously.
- Reduce third-party TLS dependencies rather than pinning services you cannot coordinate with.
Certificate Pinning Decision Matrix: Browser, Mobile and Service-to-Service
| Client model | Default recommendation | Reason |
|---|---|---|
| Public website in a normal browser | Do not deploy application pinning | Browsers manage the public PKI; HPKP is obsolete and website operators do not control the browser trust lifecycle |
| Native mobile app where you control client and service | Consider only for a documented high-risk threat model | Pinning can narrow trust, but secure backup pins and forced-update/rotation procedures are essential |
| Enterprise service-to-service API | Usually prefer mTLS, private trust policy or workload identity | These mechanisms authenticate peers without hard-coding a brittle public-server pin into every client |
| Environment with sanctioned TLS inspection | Pinning may conflict with operations | Interception changes the certificate chain and can intentionally trigger pin failures |
If pinning is still justified, document who owns the pinset, how a backup key is introduced, how emergency rotation works and how clients recover if the primary credential is replaced unexpectedly. See the related mTLS API security guide for mutual client/server authentication.
What Runtime API Security Adds Beyond TLS and Pinning
TLS and any justified pinning policy protect the transport channel; they do not authorize API actions. Ammune can add runtime API visibility above the encrypted channel, while certificate validation, pin lifecycle, mTLS and application authentication remain separate security responsibilities.
Certificate Pinning Decision Checklist
- Start with correctly configured TLS and hostname validation.
- Write down the threat that pinning uniquely mitigates.
- Confirm you control both client release and server credential lifecycle.
- Choose certificate vs SPKI pinning deliberately.
- Ship backup pins before rotating server credentials.
- Test expiry, failover and emergency key-compromise procedures.
- Fail closed on pin mismatch without a user bypass.
- Reevaluate whether mTLS, private PKI or workload identity solves the requirement more safely.
Frequently Asked Questions
What is certificate pinning?
It is an additional client-side trust check that restricts a host to an expected certificate, issuer or public key after normal TLS validation.
Does OWASP recommend certificate pinning for every app?
No. Current OWASP guidance says pinning is usually not recommended because operational and outage risks often outweigh the benefit.
What is the difference between certificate and public-key pinning?
Certificate pinning matches certificate material; public-key pinning typically matches a stable public-key representation such as SPKI and can survive certificate reissuance when the same key is retained.
Does pinning replace certificate validation?
No. Normal chain and hostname validation should still be performed.
Where is certificate pinning most appropriate?
A tightly controlled native client/server environment with a specific threat model and a mature pin rotation and recovery process.
Is certificate pinning the same as mTLS?
No. Pinning restricts which server certificate or key a client accepts. mTLS also authenticates the client to the server using a client certificate or workload credential.
Primary References
Secure the Channel, Then Secure the API
Use TLS and pinning only where the threat model justifies it. Ammune complements transport trust with runtime visibility into API behavior and threats.
