Certificate pinning in mobile apps: when not to, and how
Short answer: Certificate pinning makes your mobile app accept only specific certificates or keys for your API, instead of any certificate from a trusted authority. It sounds like extra security, and sometimes an auditor or a bank partner asks for it, but it is also one of the easiest ways to take your own app offline: when the server's certificate changes and the app has not been updated, every installed copy stops connecting. OWASP's current guidance is that there is almost no situation where you should pin. If you must, pin public keys, include backup pins, plan rotation, and know how you would recover.
What pinning does
Normally, when your app connects to your API over HTTPS, the phone checks that the server's certificate was issued by a certificate authority the operating system trusts. Android's documentation on network security configuration describes the risk pinning addresses: an app normally trusts all pre-installed authorities, and if any of them issued a fraudulent certificate, the app could be exposed to an on-path attacker.
Pinning narrows that trust. Android describes it as providing a set of certificates by the hash of their public key, so that a certificate chain is valid only if it contains at least one of the pinned keys.
Why it often causes outages
Certificates change. Many are now renewed automatically every few months, hosting or CDN providers switch authorities, and a provider's renewal may produce a new key. If your app pins a key that is no longer in use, it refuses to connect. Unlike a website, you cannot fix a mobile app instantly: users must install an update, and many do not for weeks.
OWASP's Pinning Cheat Sheet is blunt about this. It says there is almost no situation where you should consider pinning, because the risk of outages almost always outweighs the security benefit given advances in security. It lists cases where you should not pin:
- If you do not control both the client and server side of the connection.
- If you cannot update the pin set securely.
- If updating the pins is disruptive, such as requiring an app release, you probably should not pin.
- If the certificate's key pair cannot be predicted before it is put into service.
- If it is not a native mobile application.
That last point matters for web teams: pinning in browsers is not the answer.
What to do instead
For most business apps, these give strong protection without the outage risk:
- HTTPS everywhere with modern TLS settings on your servers.
- No exceptions to normal certificate validation in app code, such as code that accepts any certificate during development and accidentally ships.
- Certificate Transparency monitoring for your domains, so you learn if someone obtains a certificate for them. Android's network security configuration also lists certificate transparency as an option restricting apps to provably logged certificates.
- Short-lived tokens and strong authentication so intercepted traffic is less useful.
- Platform protections such as Android's default refusal to trust user-installed certificates for apps targeting recent versions, and iOS App Transport Security.
If you are required to pin
Some industries or partners require it. Then reduce the risk:
Pin public keys, not whole certificates. OWASP notes that pinning a certificate means the app needs updating whenever the site rotates its certificate, and if you do not control when the certificate is put into service, pinning will lead to an outage. Public key pinning lets you renew a certificate with the same key.
Choose what to pin carefully. OWASP says pinning a root authority is generally not recommended, because it also trusts all its intermediates; pinning a leaf certificate is recommended only with backups, such as an intermediate or a set of alternate keys.
Always include backup pins. Android's documentation says you should always include a backup key so that if you are forced to switch keys or authorities, connectivity is unaffected; otherwise you must push out an app update to restore it. Generate the backup key in advance and store it securely offline.
Consider an expiration. Android supports an expiration date on pin sets, after which pinning is not performed, which helps apps that have not been updated. The documentation notes the trade-off: an expiry may let attackers bypass your pins once it passes.
Coordinate with whoever manages certificates. If a hosting provider or CDN renews certificates automatically, find out whether keys change and when. Put certificate renewals on the same calendar as app releases.
Have a recovery plan
Before shipping a pinned app, answer:
- If pins fail, what do users see? A clear "please update" message is better than a silent failure.
- Can you force an update, for example through a minimum version check that runs over an unpinned endpoint?
- Who can produce and release a fixed version quickly, including over a weekend?
A worked example
Picture a hypothetical Adelaide credit-union app whose developers had pinned the API's leaf certificate. When the hosting provider renewed the certificate with a new key, every installed copy stopped working until users updated, and the support line was overwhelmed for days.
After reviewing OWASP's guidance with their partner bank, they agreed pinning was still required. The next release pinned the public keys of their own certificates plus a pre-generated backup key, with renewals planned to reuse keys and the backup ready for emergencies. A minimum version check runs on an endpoint without pinning, and certificate changes are now reviewed before they happen. The following renewal passed without a single support call.
FAQ
Does pinning stop people inspecting my app's traffic?
It makes casual inspection harder but is not a barrier for a determined attacker on their own device.
Can I pin in a web app?
No. OWASP advises against pinning outside native mobile apps; browsers dropped the old pinning header.
What about apps using third-party APIs?
Do not pin certificates you do not control, such as a payment or maps provider's.
If you've been asked to add certificate pinning to your app and want to avoid an outage, tell us how your certificates are managed.