Skip to content
Tamandua
← All posts

Certificate pinning and MitM: why mobile apps still get intercepted

Pinning closes one path to reading your app's traffic, not all of them. How interception works on modern Android and iOS, how to pin without breaking production, and why pinning needs tamper and hook detection beside it.

Tamandua Team · · 6 min read

Your API is served over TLS, so the traffic between your app and your backend is encrypted. That protects it from someone on the same coffee-shop Wi-Fi. It does not stop the person holding the phone from reading and changing every request, and for many apps that person is the attacker: they want to understand your API, replay requests, change prices or automate abuse.

Certificate pinning is the standard answer, and it is worth doing. This post explains what it actually protects, how to deploy it without causing an outage, and why apps with pinning still get intercepted.

How interception works

An intercepting proxy sits between the app and the server and presents its own certificate. The app only accepts that certificate if it chains to a certificate authority the app trusts. So the attacker's whole job is getting the app to trust their CA, or to skip the check.

  • Android. Since Android 7, apps that target API level 24 or higher no longer trust CAs that the user installed, only the system store, unless the app's network security configuration opts in. That raised the bar considerably. On a rooted device, though, the attacker can add their CA to the system store, and a debug-friendly configuration that accidentally ships in a release build reopens the door.
  • iOS. A user can install and fully trust a profile with a custom CA through the device settings, without a jailbreak. Apps that rely only on default trust evaluation accept certificates from that CA.

In both cases, default TLS validation answers the question "is this certificate trusted by this device?". On a device controlled by the attacker, the answer can be made "yes".

What pinning changes

Pinning asks a narrower question: "is this the key I expect for my server?". The app ships with the hash of the public key (or keys) it expects, and rejects any certificate chain that does not contain one of them, even if the device trusts the CA that signed it.

On Android, the declarative way is a pin set in the network security configuration:

<network-security-config>
  <domain-config>
    <domain includeSubdomains="true">api.example.com</domain>
    <pin-set expiration="2027-06-30">
      <pin digest="SHA-256">PRIMARY_SPKI_HASH_BASE64=</pin>
      <pin digest="SHA-256">BACKUP_SPKI_HASH_BASE64=</pin>
    </pin-set>
  </domain-config>
</network-security-config>

Networking libraries offer the same thing in code, for example OkHttp's CertificatePinner. On iOS, apps can declare pinned keys with NSPinnedDomains in Info.plist, or evaluate the server trust themselves in a URLSession delegate.

Pinning without breaking production

The most common pinning incident is not an attack. It is a certificate rotation that nobody coordinated with the mobile team, after which every installed copy of the app refuses to talk to the backend. A few rules avoid that:

  1. Pin public keys, not certificates. Pinning the SPKI hash lets you renew a certificate with the same key pair without shipping an app update.
  2. Always ship a backup pin for a key you control but have not deployed yet, so you can rotate without waiting for every user to update.
  3. Choose the level deliberately. Pinning your own leaf key is the tightest. Pinning an intermediate gives more flexibility but trusts more certificates.
  4. Use an expiration date where the platform supports it, so a very old app version fails open to normal validation instead of failing closed forever.
  5. Write the rotation runbook before you need it, and make certificate changes on the backend a step that involves the mobile team.

Why pinned apps still get intercepted

Pinning is enforced by code inside the app, on a device the attacker controls. That leaves several ways around it, described here conceptually:

  • Runtime hooking. Instrumentation frameworks such as Frida can replace the functions that perform the pin check so they always report success. Public tooling automates this for the most popular libraries.
  • Repackaging. The attacker unpacks the app, removes or edits the pinning configuration, then re-signs and reinstalls it. No root is required.
  • Gaps in coverage. Pinning often covers the main API client but not a WebView, a third-party SDK or a secondary domain. Cross-platform frameworks can also use their own TLS stacks, so pinning configured at the platform level may not apply to them.
  • Pinning switched off to fix an incident. After a rotation outage, teams sometimes disable pinning "temporarily" and never turn it back on.

What to put next to pinning

Since the attacks on pinning go through tampering with the app, the controls that help are the ones that detect tampering:

  • Hook and instrumentation detection, so a pin check that has been replaced at runtime is more likely to be noticed.
  • Repackaging and signature checks, so a build with its configuration edited out does not look like your build.
  • Hardening that makes the pinning code and configuration harder to find and change.
  • Reporting pin failures. A pin mismatch in the wild is either a misconfiguration or someone trying to intercept your traffic. Either way you want to know.
  • Server-side assumptions that survive interception. Treat every request as potentially crafted by hand: validate authorization and business rules on the server, and do not rely on the client to enforce prices or limits.

The OWASP MASVS covers pinning under network communication and tampering resistance under resilience. They work best as a pair.

Next step: a pinning readiness check

  • Do you pin at least one backup key that is not on the current certificate chain?
  • Does your pin set have an expiration date, and is it later than your slowest-updating users' app version?
  • Have you rehearsed a key rotation in staging, including the release that ships the new pins?
  • Does your app report when a pinning failure happens, so you can tell an attack from a broken rollout?

How we think about this at Tamandua

The pairing above (network trust controls next to hook, repackaging and integrity signals, a signed policy that starts in observe-only mode, and reporting that keeps detected, degraded and bypassed outcomes visible) are the direction Tamandua App Guard is heading, not a description of what it ships today.

Current App Guard evidence is a detect-only Android lab observation on one tested device: root and re-signing were detected and logged on-device. No hosted completion, console telemetry, public enrollment, purchase, blocking, or verified effect is offered. An assisted Android pilot is under consideration, not available. iOS is source/preview only, with no enrollment or availability offer. A request records interest; it does not grant access or guarantee delivery. Register interest.

Updated 2026-10-10: this status reflects the approved availability boundaries; the educational discussion above is not a product offer.

Your app's third-party SDKs are attack surface too

Analytics, ads, crash reporting and payment SDKs run with your app's permissions and ship under your name. How to inventory them, what to check before adding one, and why app hardening doesn't change who you trust.

· 6 min read

Account takeover on mobile: the device-side signals that matter

Most account takeover is decided on the server, but the device often knows something first. Which client-side signals are worth collecting, how to bind a session to a device, and how to use them without locking out real users.

· 7 min read

Ship apps that fight back

App Guard protects Android and iOS apps: zero-code hardening for APKs, a native iOS SDK, real-time telemetry and a verifiable receipt for every build.