SSL Pinning in iOS Apps: How It Works and When to Use It
SSL pinning ties your iOS app to one server key, so a forged certificate cannot intercept its traffic. Plan the rotation before you ship it.
On this page
Short answer
SSL pinning is a technique that ties an iOS app to a specific server certificate or public key, so the app only trusts that exact identity when it opens a TLS connection. If an attacker presents any other certificate, even one signed by a trusted authority, the connection fails.
What is SSL pinning in an iOS app?
SSL pinning in an iOS app is a security check that pins the app to a known server identity, usually a certificate or a public key, so the app refuses connections to any server that presents a different one. Normal TLS trusts any certificate signed by a certificate authority on the device; pinning narrows that trust to the one you chose.
The reason teams add it is that a trusted certificate authority is not always trustworthy in practice. A compromised authority, a mis-issued certificate, or a device with a malicious root certificate installed can all produce a certificate that normal TLS would accept. Pinning blocks those cases because the attacker does not hold the pinned key.
Pinning is most common in banking, payments, health and messaging apps, where the data is sensitive and the cost of interception is high. It is a defence in depth: it sits on top of normal TLS rather than replacing it.
How does SSL pinning work?
SSL pinning works by comparing the server's certificate, or its public key, against a value stored inside the app during the TLS handshake. The app's network layer runs this check before any data is sent, so a failed check means no request leaves the device.
There are three common ways to pin, each with different trade-offs.
| Pin type | What is stored | Strength | Rotation cost |
|---|---|---|---|
| Certificate pin | The whole server certificate | High | High: breaks on renewal |
| Public key pin | The public key only | High | Low: survives renewal |
| SPKI hash pin | Hash of the public key | High | Low: survives renewal |
| Intermediate pin | The issuer's key | Medium | Low, wider trust |
Public key pinning is the usual choice because it survives certificate renewal: the key stays the same while the certificate is replaced. Certificate pinning is stricter but breaks every time the certificate is renewed, which makes it a poor fit for most teams.
How do you add SSL pinning to an iOS app?
You add SSL pinning to an iOS app by implementing a delegate or session delegate that checks the server's trust object during the TLS handshake, comparing it against the pinned key or certificate you bundled with the app.
- Choose what to pin. Pin the public key of your leaf certificate, and keep one backup pin for the next key you will use.
- Bundle the pins. Store the pin hashes in the app bundle or fetch them from a trusted configuration endpoint, never from the server being pinned.
- Implement the challenge handler. In URLSession, use the authentication challenge delegate to evaluate the server trust and compare the public key.
- Decide the failure mode. A failed pin must fail the connection and log the event; it must never fall back to unpinned TLS.
- Test with a proxy. Run the app behind a TLS-intercepting proxy and confirm that requests fail, then confirm they succeed without it.
- Plan rotation. Ship the next pin before you rotate the key, so old app versions keep working after the change.
Apple's App Transport Security does not do pinning for you. It enforces HTTPS and modern TLS, but pinning is a separate check you add in your own networking code or through a library. If the app also needs a backend behind the pinned server, a partner for custom software development can build the API layer under the same security review.
What happens when a pinned certificate changes?
When a pinned certificate or key changes without the app knowing, the app treats its own server as untrusted and refuses every connection. Users see failed requests, empty screens or a generic network error, and the app is effectively down until a fix ships.
This is the main operational risk of pinning, and it is why backup pins matter. A backup pin is a second public key that is already in the app but not yet in use on the server. When you rotate, you switch the server to the backup key, and the app accepts it without an update.
The rotation sequence is: generate the new key, add its pin to the app in a release, wait until most users have that release, then switch the server to the new key. If you skip the waiting step, users on old versions lose access.
Some teams also pin the intermediate certificate as a second option, which gives more room during rotation. That widens trust slightly, so it is a trade-off between safety and the risk of locking users out.
Example: a banking app rotates its pinned key
Example (hypothetical): a banking app with 200,000 users pins the public key of its API server. The security team plans to rotate the key because the current one is three years old and the team wants a fresh one before the next audit.
The team generates the new key and adds its hash as a backup pin in version 4.8 of the app. The app now trusts two keys: the current one and the new one. Version 4.8 ships, and after eight weeks, 170,000 of the 200,000 users have updated, which is 85% of the base.
The team then switches the server to the new key. The 170,000 users on version 4.8 connect without a problem. The 30,000 users on older versions see connection errors until they update, so the app shows a message explaining that an update is needed rather than a generic failure.
The arithmetic shows why the wait matters. If the team had rotated after only four weeks, with 100,000 users updated, the other 100,000 would have been locked out. The backup pin plus a patient rollout turns a risky change into a routine one.
When should you skip SSL pinning?
You should skip SSL pinning when your app serves public content with no sensitive data, when you cannot run a key rotation process, or when the app is a web view wrapper where pinning adds little because the browser layer already handles trust.
Pinning has a real cost. It adds code to maintain, a rotation duty that must survive staff changes, and a failure mode that can take the whole app offline. For a content app with no login, that cost buys almost nothing, because there is nothing valuable to intercept.
It is also a poor fit when the backend is a third-party API you do not control. If the provider rotates its certificate without telling you, your app breaks and you cannot fix it from your side. In that case, normal TLS plus certificate transparency checks is the safer choice.
For teams building mobile products, the question is part of a wider security review. A cybersecurity services review will show whether pinning is the right control or whether the effort belongs elsewhere, such as token storage or API design.
What are the common mistakes?
The most common SSL pinning mistakes are pinning the certificate instead of the key, shipping without a backup pin, and letting a failed pin fall back to normal TLS, which removes the protection entirely.
- Pinning the certificate. Renewal then breaks the app, and renewals happen every few months.
- No backup pin. A lost or compromised key leaves no way to rotate without breaking old app versions.
- Silent fallback. If a failed pin falls back to unpinned TLS, an attacker only needs to trigger the fallback.
- Pinning every host. Third-party hosts you do not control should not be pinned, or their changes break your app.
- No monitoring. Pin failures are a signal of attack or misconfiguration, and nobody sees them without logging.
- Forgetting the web view. Pinning URLSession does not protect a WKWebView, which needs its own handling.
How do you keep SSL pinning working over time?
You keep SSL pinning working by treating key rotation as a scheduled process with an owner, a calendar and a backup pin, not as a one-off task that somebody remembers when the certificate is about to expire.
- Document the pins. Record which keys are pinned, where the pins live in the app, and who owns rotation.
- Rotate on a schedule. Set a yearly rotation and add the backup pin in a release at least one cycle before the switch.
- Monitor pin failures. Log every failure with the host and the presented key, and alert on spikes.
- Test each release. Run the app behind an intercepting proxy in QA and confirm that requests fail as expected.
- Plan the update message. Users on old versions need a clear prompt to update, not a blank screen.
Pinning is a long-term commitment. If the team cannot staff the rotation process, normal TLS with strong server configuration is the better choice, and the app will be safer for it.
If you are building an iOS app that handles sensitive data and want the security design reviewed before launch, mobile app development with a security review is the place to start.
SSL pinning in iOS apps: what to remember
SSL pinning in iOS apps is a strong defence against interception, but only when it is built with rotation in mind. Pin the public key, keep a backup pin, never fall back to unpinned TLS, and test every release against an intercepting proxy.
The teams that get it right treat pinning as a process: a scheduled rotation, logged failures and a clear update path for users on old versions. The teams that get it wrong treat it as a one-time code change, and they find out when their own server rotation takes the app offline.
Use it where the data justifies the cost, and skip it where it does not. The right answer depends on what your app carries, not on what other apps do.
Key takeaways
- SSL pinning ties an app to one server key, not any trusted certificate
- Pin the public key, not the certificate, so renewal does not break the app
- Always ship a backup pin before rotating the server key
- A failed pin must fail the connection, never fall back to plain TLS
- Treat rotation as a scheduled process with an owner and a calendar
Frequently asked questions
What is the difference between SSL pinning and normal TLS?
Normal TLS trusts any certificate signed by a certificate authority on the device. SSL pinning narrows that trust to one specific certificate or public key that the app expects. If an attacker presents a different certificate, even a validly signed one, the pinned app refuses the connection.
Does SSL pinning work with URLSession in Swift?
Yes. You implement the authentication challenge delegate and compare the server's public key against the pinned value during the TLS handshake. The check runs before any request data is sent, so a failed pin means no data leaves the device.
Can SSL pinning be bypassed?
Yes, on a jailbroken device an attacker can patch the app or the TLS library to skip the check. Pinning raises the bar against network interception and malicious certificates, but it does not protect a device the attacker fully controls. Server-side checks still matter.
How often should a pinned key be rotated?
Once a year is a common schedule, or sooner if the key may be exposed. The rotation must be planned: add the new pin as a backup in a shipped release, wait until most users have it, then switch the server. Rotating without the wait locks out old app versions.
Should every iOS app use SSL pinning?
No. It fits apps that carry sensitive data, such as banking, payments, health and messaging. For a public content app with no login, the cost and the risk of locking users out outweigh the benefit. Normal TLS with strong server configuration is enough there.
Does App Transport Security do SSL pinning?
No. App Transport Security enforces HTTPS and modern TLS settings, but it does not pin a certificate or key. Pinning is a separate check that you add in your own networking code or through a library on top of the standard TLS behaviour.