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:
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:
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:
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:
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:
| Control | Protects against | Bypassable on attacker-controlled device? |
|---|---|---|
| Certificate or public key pinning | Interception on untrusted networks, rogue CAs | Yes |
| Root or jailbreak detection | Casual tampering and instrumentation | Yes, with effort |
| Play Integrity or App Attest, verified server-side | Modified apps, emulators, scripted clients | Harder; enforced by the server |
| Server-side authorisation and rate limiting | API abuse regardless of client | Not 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
Is SSL pinning still recommended for mobile apps?
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.