Security

    Certificate pinning in mobile apps: when it helps

    A 2026 view of a mobile app rejecting an interceptor's valid-looking certificate because it does not match the pinned public key, with a backup pin ready for rotation

    Certificate pinning is one of those security measures that is genuinely useful and genuinely able to take your app offline if you get it wrong. The idea is simple: your app refuses to trust any server certificate except the specific one you pinned, which blocks an attacker who presents an otherwise valid certificate. The catch is operational, since a certificate rotation without an updated pin can brick every installed copy of your app until users update. Here is what pinning protects against, when it is worth the commitment, and how to do it without locking yourself out.

    Short answer

    Certificate pinning makes your app trust only a specific server certificate or public key, rather than any certificate a trusted authority issued, which defends against interception by a rogue or compromised certificate authority and by intercepting proxies. Per OWASP's guidance, it is valuable for high-sensitivity apps where you control the backend, but it carries real operational risk: if you rotate certificates without shipping an updated pin, the app cannot connect until users update. So pin the public key rather than the leaf certificate, include backup pins, and only adopt pinning with a rotation plan. It is strong defense-in-depth for the right app, not a default for every app.

    What you should know

    • Pinning restricts trust: the app accepts only your pinned certificate or key.
    • It blocks rogue-CA interception: even a valid attacker certificate is rejected.
    • It is an operational commitment: a bad rotation can break the app.
    • Pin the public key, not the leaf: and include backup pins.
    • It is for sensitive apps: not a universal default.

    What is certificate pinning?

    It is restricting which certificate your app will accept for a given server. Normally an app trusts any certificate signed by a certificate authority in the device's trust store, so a connection succeeds as long as the certificate chains to a trusted CA. Pinning narrows that: the app stores a known value, ideally the hash of your server's public key, and rejects the connection if the server's certificate does not match, even if it is otherwise valid. That closes a gap, because an attacker who can get a certificate issued by a trusted CA, through a compromised or coerced CA, or a user-installed CA on the device, could otherwise intercept traffic with a valid-looking certificate. Pinning means only your specific key is accepted, so such a certificate is refused.

    When does pinning help, and when does it hurt?

    It helps against interception and hurts when operations go wrong. The table weighs it.

    SituationPinning effect
    Sensitive app, you control the backendHelps; blocks rogue-CA and proxy interception
    Intercepting proxy or compromised CAHelps; the attacker certificate is rejected
    Certificate rotated without an updated pinHurts; the app cannot connect until users update
    No backup pin and the key changesHurts; risk of bricking installed apps
    Rooted or jailbroken deviceLimited; pinning can be bypassed on a compromised device

    The benefit is real for apps handling sensitive data on a backend you operate, where pinning meaningfully raises the bar against interception. The risk is equally real: pinning ties your app to a specific key, so a rotation that does not account for the pin takes the app offline, which is why it demands a rotation plan and backup pins.

    How do you pin without bricking your app?

    Pin carefully, and never without a recovery path. Pin the public key, using a Subject Public Key Info hash, rather than the leaf certificate, so renewing the certificate with the same key does not break the pin. Always include at least one backup pin for a key you control but have not deployed yet, so you can rotate to it without an app update. On Android, you can configure pins in the network security config or use a library's certificate pinner; on iOS, you implement server trust evaluation in your URLSession delegate. Plan rotations ahead, deploy a new pin in an app update before the old certificate expires, and monitor so a pin mismatch does not silently cut off users. The discipline is that pinning is a commitment you maintain, not a setting you enable once.

    What to watch out for

    The first trap is adopting pinning without a rotation plan, which is how teams brick their own apps when a certificate changes. The second is pinning the leaf certificate instead of the public key, so an ordinary renewal breaks the pin. The third is treating pinning as absolute, when it raises the bar but can be bypassed on a rooted or jailbroken device, so it is defense-in-depth, not a guarantee. A pre-submission scan such as PTKD.com (https://ptkd.com) reads the compiled APK, AAB, or IPA against OWASP MASVS and reports on your network and transport configuration, helping you confirm your pinning and HTTPS posture before you ship. The pinning logic itself you implement and maintain in the app.

    What to take away

    • Certificate pinning makes your app trust only a specific server key, blocking interception via a rogue or compromised certificate authority.
    • It is valuable for sensitive apps on a backend you control, but it is an operational commitment that can break the app if a rotation is mishandled.
    • Pin the public key rather than the leaf certificate, include backup pins, and adopt pinning only with a rotation plan.
    • It is defense-in-depth, not absolute, and a pre-submission scan such as PTKD.com helps you verify your transport and pinning posture.
    • #certificate-pinning
    • #tls
    • #mitm
    • #network-security
    • #owasp-masvs
    • #app-security
    • #mobile

    Frequently asked questions

    What is certificate pinning?
    It is restricting which certificate your app accepts for a server. Normally an app trusts any certificate signed by a CA in the device's trust store, but pinning narrows that to a known value, ideally the hash of your server's public key, and rejects the connection if the certificate does not match. That blocks an attacker who obtains a valid-looking certificate from a compromised or user-installed CA, since only your specific key is accepted rather than any trusted-CA certificate.
    When should I use certificate pinning?
    For sensitive apps on a backend you control, where the protection against rogue-CA and proxy interception is worth the operational cost. Banking, health, and similar apps benefit most. It is not a universal default, because pinning ties your app to a specific key and demands a rotation plan. If you cannot commit to managing pins and rotations carefully, the risk of bricking your app can outweigh the benefit for a lower-sensitivity app.
    Can certificate pinning break my app?
    Yes, if mishandled. Because the app trusts only the pinned key, rotating your certificate without shipping an updated pin means the app cannot connect until users update, which can effectively brick installed copies. Pinning the leaf certificate instead of the public key makes even an ordinary renewal break the pin. So always pin the public key, include backup pins for a key you can rotate to without an app update, and plan rotations ahead of certificate expiry.
    Does pinning make my app fully secure?
    No, it is defense-in-depth, not a guarantee. Pinning meaningfully raises the bar against network interception, but it can be bypassed on a rooted or jailbroken device where an attacker controls the runtime, and it does not protect against weaknesses elsewhere in the app. So treat it as one strong layer for protecting traffic on a backend you control, combined with HTTPS everywhere and the rest of your security, rather than as a single measure that secures the app.
    How do I implement pinning safely?
    Pin the public key using a Subject Public Key Info hash, not the leaf certificate, and always include at least one backup pin. On Android, configure pins in the network security config or use a library's certificate pinner; on iOS, implement server trust evaluation in your URLSession delegate. Deploy a new pin in an app update before the old certificate expires, and monitor for mismatches. A pre-submission scan such as PTKD.com helps you verify your transport and pinning posture before shipping.

    Keep reading

    Scan your app in minutes

    Upload an APK, AAB, or IPA. PTKD returns an OWASP-aligned report with copy-paste fixes.

    Try PTKD free