Back to Blog
Penetration Testing10 min read2026-11-30

SSL Pinning Bypass Testing and Defence for Android and iOS Apps

Certificate pinning stops interception on networks you do not control, but anyone with a device they control can usually bypass it. How testers assess pinning under OWASP MASTG, and how to build pinning that survives rotation and sits inside a layered defence.

A

Asfaleia Team

Security Consulting Team

Sections

SSL pinning (more accurately certificate or public key pinning) makes a mobile app trust only specific keys for its own servers, instead of any certificate issued by a trusted certificate authority, which blocks interception through rogue or user-installed CAs. It is required at OWASP MASVS-NETWORK-2 for higher-assurance apps, but it is not a security boundary: on a device they control, an attacker can usually remove or bypass pinning with runtime instrumentation or by repackaging the app. Build it with platform features, pin public keys with backup pins and a rotation plan, and rely on server-side controls, not the pin, to protect your API.

Penetration testers bypass pinning on almost every mobile engagement, because they need to see the app's traffic to test the API behind it. That is normal and expected under the OWASP Mobile Application Security Testing Guide (MASTG). The useful questions are different: is pinning implemented correctly, does it fail safely, and what happens to your backend once someone does get past it?

What SSL pinning actually does

During a normal TLS handshake, the app accepts the server's certificate if it chains to any certificate authority in the device's trust store and the hostname matches. That trust store holds many public CAs, and on a device under the user's control it can also hold CAs the user installed. An intercepting proxy works by presenting its own certificate signed by such a CA.

Pinning adds a second check. The app carries a list of expected public keys (or certificates) for its own domains, and the connection is accepted only if the server's chain contains one of them. A proxy certificate, even a validly signed one, does not match, so the connection fails.

Certificate pinning compared with public key pinning

There are two things you can pin:

The certificate. Simple, but the pin breaks every time the certificate is renewed, even if nothing else changed.
The public key (SPKI). You pin a hash of the certificate's SubjectPublicKeyInfo. The pin survives certificate renewal as long as the key pair is reused, and pinning an intermediate CA's key lets you reissue server certificates freely from that CA.

Both Android's Network Security Configuration and Apple's NSPinnedDomains use base64-encoded SHA-256 hashes of the SPKI, and OWASP's MASWE-0028 recommends pinning the public key rather than the whole certificate.

Why apps use pinning

Pinning is most common in banking, payments, healthcare, government and other high-value apps. It protects users against:

a compromised or mis-issuing public certificate authority;
corporate, hotel or hostile Wi-Fi networks that intercept TLS with their own root CA;
malware or social engineering that persuades a user to install a malicious CA profile.

It also raises the effort needed to inspect and reverse engineer the app's API, which is why fraud teams like it. That last benefit is real but limited, and it is where most misunderstandings start.

How penetration testers assess pinning

The MASTG covers pinning in its network testing chapters, with tests such as MASTG-TEST-0022 (Android) and MASTG-TEST-0068 (iOS) on custom certificate stores and pinning, newer Android tests for missing or expired pins in the Network Security Configuration, and dedicated "Bypassing Certificate Pinning" techniques for both platforms (MASTG-TECH-0012 and MASTG-TECH-0064). In outline, an assessment looks like this.

Static review

The tester decompiles the app and reads how pinning is configured: the Network Security Configuration file and manifest on Android, Info.plist and App Transport Security settings on iOS, and any pinning library such as OkHttp's CertificatePinner or TrustKit. They check which domains are pinned and which are not, whether backup pins exist, whether pins have already expired, whether debug overrides or user CA trust leak into release builds, and whether any custom trust code accepts every certificate.

Dynamic testing with an intercepting proxy

With a proxy CA installed on a test device, the tester confirms that pinned connections fail closed and that no sensitive endpoint, SDK or WebView quietly falls back to an unpinned path. Gaps here are common: third-party analytics or support SDKs, secondary API domains and WebViews are often outside the pin set.

Runtime instrumentation

On a rooted or jailbroken test device, tools such as Frida and objection hook the functions that perform certificate validation and force them to succeed. The MASTG notes that for most apps this works quickly when the app uses standard platform or library APIs, and that custom implementations need manual analysis. Testers use it to reach the API, and it also shows how much effort a real attacker would need.

Patching and repackaging

Where instrumentation is blocked, a tester can modify the app package itself: change the Network Security Configuration to trust user CAs, remove pinning code, then re-sign and reinstall. This tests whether the app or backend notices it is running as a modified build.

We do not publish bypass scripts here. The techniques are well documented in the MASTG; what matters for defenders is that they work, and what your app and API do about it.

Why pinning is not a security boundary

Pinning protects a legitimate user on an untrusted network. It does not protect your app from a person who controls the device the app runs on. That person can hook any check, edit any configuration file or rebuild the app. OWASP's MASWE-0028 says this directly: attackers who can reverse engineer the app may remove the pins, and runtime hooking can bypass pinning checks on a device they control, so pinning must be implemented alongside other measures.

The practical consequences:

Never treat "the traffic is pinned" as protection for your API. Any request your app can make, an attacker can make with a proxy or a script.
Do not hide secrets in traffic. API keys, signing keys or business logic that only stays safe while nobody reads the traffic are already exposed.
Do test the API as if pinning did not exist. That is the reason testers bypass it.

Making pinning resilient

The biggest operational risk with pinning is not bypass; it is locking out your own users. Apple recommends using pinning with caution, and OkHttp's documentation warns that pinning limits your server team's ability to update TLS certificates. Do it deliberately.

Android: Network Security Configuration

Prefer the declarative Network Security Configuration over custom code. Android's documentation says to always include a backup key, and lets you set an expiration date after which pinning stops, which avoids bricking old app versions but, as Google notes, can also give attackers a way round the pins once it passes.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="false">
        <domain includeSubdomains="true">api.example.com</domain>
        <pin-set expiration="2027-12-31">
            <!-- current key -->
            <pin digest="SHA-256">CURRENT_SPKI_SHA256_BASE64=</pin>
            <!-- backup key, held offline -->
            <pin digest="SHA-256">BACKUP_SPKI_SHA256_BASE64=</pin>
        </pin-set>
    </domain-config>
</network-security-config>

Keep debug CAs inside the debug-overrides element only, which Android applies solely when the app is debuggable, and check that release builds do not trust user-installed CAs. Apps targeting Android 7.0 (API level 24) and later do not trust user CAs by default. Android 16 added opt-in Certificate Transparency checking in the same file, and Google's documentation states it is enabled by default from Android 17 (API level 37).

Android: OkHttp CertificatePinner

If you use OkHttp, CertificatePinner takes sha256 SPKI hashes per hostname. The same rules apply: at least two pins, and an agreed process with whoever manages your TLS certificates.

val pinner = CertificatePinner.Builder()
    .add("api.example.com", "sha256/CURRENT_SPKI_SHA256_BASE64=")
    .add("api.example.com", "sha256/BACKUP_SPKI_SHA256_BASE64=")
    .build()

iOS: NSPinnedDomains and TrustKit

Since iOS 14, Apple supports declarative pinning in Info.plist under App Transport Security, using NSPinnedDomains with either NSPinnedCAIdentities or NSPinnedLeafIdentities. Apple recommends pinning CA keys rather than server keys where possible, pinning more than one key, and testing failure cases before release.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSPinnedDomains</key>
    <dict>
        <key>api.example.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSPinnedCAIdentities</key>
            <array>
                <dict>
                    <key>SPKI-SHA256-BASE64</key>
                    <string>INTERMEDIATE_CA_SPKI_SHA256_BASE64=</string>
                </dict>
                <dict>
                    <key>SPKI-SHA256-BASE64</key>
                    <string>BACKUP_CA_SPKI_SHA256_BASE64=</string>
                </dict>
            </array>
        </dict>
    </dict>
</dict>

Developer reports suggest coverage differs between networking APIs, so verify that every component you rely on, including WebViews, honours the configuration on your minimum supported iOS version. TrustKit, an open-source library, is an alternative that also supports pin failure reporting, which is useful for spotting interception and misconfiguration in production.

Pin the SPKI, not the leaf certificate

Pinning a leaf certificate ties every renewal to an app release. Pinning the SPKI of a key you control, or of an intermediate CA you have committed to, gives you room to renew certificates without shipping a new app. The trade-off is scope: an intermediate CA pin trusts anything that CA issues for your domain, so choose a CA you trust and keep a backup from a different CA.

Plan pin rotation before you ship

Write down, before release:

which keys are pinned, who holds the backup private key and where;
the oldest app version still in use, and therefore how long old pins must keep working;
how a forced update or remote kill switch would restore connectivity if every pin fails;
the monitoring that will tell you pin failures are rising.

OWASP MASWE-0028 lists missing backup pins and insecure dynamic pin updates among common implementation mistakes. If pins are delivered dynamically, they must arrive over a channel that is itself authenticated.

Layering pinning with integrity checks and server-side defences

Because pinning can be removed on a hostile device, combine it with controls that make tampering visible and limit what a bypass achieves:

Root and jailbreak detection and anti-instrumentation checks raise the cost of hooking, though they can also be bypassed and should feed risk decisions rather than act as a gate on their own.
Play Integrity API on Android and App Attest on iOS let your server check that requests come from a genuine, unmodified app on a genuine device. Verify the verdicts on your server, never in the app. Our Play Integrity API bypass guide covers how testers assess these.
Server-side authorisation on every endpoint, checked against the authenticated user, closes the object-level access flaws that testers find once traffic is visible. See our OWASP API Security Top 10 guide.
Short-lived, bound tokens, rate limiting and anomaly detection reduce what a scripted client can do with a stolen session.
No long-term secrets in the app. Assume anything in the package or its traffic is readable.
ControlProtects againstBypassable on attacker-controlled device?
Certificate or public key pinningInterception on untrusted networks, rogue CAsYes
Root or jailbreak detectionCasual tampering and instrumentationYes, with effort
Play Integrity or App Attest, verified server-sideModified apps, emulators, scripted clientsHarder; enforced by the server
Server-side authorisation and rate limitingAPI abuse regardless of clientNot by the client

Mapping to OWASP MASVS and MASTG

In MASVS 2.1.0, MASVS-NETWORK-1 states "The app secures all network traffic according to the current best practices", and MASVS-NETWORK-2 states "The app performs identity pinning for all remote endpoints under the developer's control". The related weakness, MASWE-0028 Insecure Identity Pinning, is mapped to the L2 profile, meaning pinning is expected in higher-assurance apps rather than every app. A report against these controls should state which endpoints are pinned, how the pins are implemented, what bypass required, and which API findings were reachable once traffic was visible. Our mobile application security testing guide explains how this fits into a full MAST programme.

Frequently asked questions

For high-value apps such as banking, payments and government services, yes, and MASVS-NETWORK-2 expects it at the L2 profile. For lower-risk apps, the operational risk of locking out users may outweigh the benefit, and both Apple and OkHttp advise caution. If you pin, use platform configuration, pin public keys and always ship a backup pin.

Can SSL pinning be bypassed?

Yes, on a device the attacker controls. Runtime instrumentation tools and app repackaging can disable pinning in most apps, and the OWASP MASTG documents these techniques for testers. Pinning still protects ordinary users on untrusted networks, which is its real purpose.

Why do penetration testers bypass pinning during an assessment?

To test the API behind the app. Most serious mobile findings, such as broken object-level authorisation or excessive data exposure, live on the server, and testers need to see and modify traffic to find them. The test also checks that pinning is correctly implemented and that the backend does not rely on it.

What is the difference between pinning the certificate and pinning the public key?

A certificate pin breaks whenever the certificate is renewed. A public key (SPKI) pin survives renewal if the same key pair is reused, and an intermediate CA key pin allows new server certificates from that CA. OWASP recommends pinning public keys, with at least one backup.

What happens if all pinned keys change?

Every installed copy of the app that enforces those pins will fail to connect until users install an update with new pins. Avoid this with backup pins from a separate key or CA, a documented rotation plan, a forced-update mechanism and, on Android, a considered use of the pin-set expiration date.

Asfaleia Tech is an NTRA Tier 1 accredited cybersecurity company that works with organisations in Egypt, Saudi Arabia, the wider Middle East and worldwide. Our mobile app penetration testing follows OWASP MASVS and MASTG, including pinning and integrity checks, and pairs with API penetration testing of the backend and source code review of the client. Book a free 30-minute consultation to scope a test.

Tags

#SSL Pinning#Certificate Pinning#Mobile App Security#OWASP MASVS#Android Security#iOS Security

Downloadable-style takeaway

Use this as a working assessment checklist.

Pull the headings into your next security review, assign owners, and mark each section as ready, partial, or missing.

A

Written by

Asfaleia Team

Security Consulting Team

Written by the Asfaleia Tech Security Team, combining field experience across offensive testing, detection engineering, incident readiness, and compliance evidence.

Ready to Strengthen Your Security?

Let's discuss how Asfaleia-Tech can help protect your organization.