Skip to content
API and Integration

Certificate Pinning for Mobile Apps with Azure Backends

14 min read

Pinning makes a mobile app refuse any server that cannot prove it holds a key you chose in advance. We pin the API for apps that handle sensitive data, and the rule that keeps it safe is to pin a key you control, never a certificate a provider issues and renews for you. Reuse that key across renewals as certificate lifetimes shorten, pin a backup key in every release, and put the same certificate on every failover path.

Should a mobile app pin its API?

Pinning protects against interception through a mis-issued certificate or one installed on the device, and it can also take your app offline the day a certificate changes in a way you did not plan for. Both of those are real, so the answer depends on what the app protects.

The standards start from different ends. The OWASP Mobile Application Security Verification Standard (MASVS) control MASVS-NETWORK-2 says the app performs identity pinning for all remote endpoints under the developer’s control. Apple’s identity pinning guidance says pinning certificates is not required, and that you should deploy pinning configurations with caution and only if absolutely necessary.

In our view they describe different apps. A staff app that reaches business systems, a health app, or anything that moves personal or financial data usually has a reason to pin its own API. A content app that only reads public information rarely does. Where we pin, one rule runs through everything below.

Pin a key you control. Never pin a certificate that a provider issues and renews for you, such as a Front Door or App Service managed certificate, Cloudflare’s universal certificates, or an azurewebsites.net host name. Each can change its key or certificate authority at a renewal you are not told about.

What does a pin actually match?

A pin is not a copy of a certificate. It is a SHA-256 hash of a certificate’s public key, known as its Subject Public Key Info (SPKI). A certificate can be renewed many times over the same key, and the pin keeps matching, so a pin only breaks when the key changes.

When your app connects, the server presents a chain of certificates. Each level is signed by the one above it, up to a root certificate the phone already trusts. You can pin a key at any level of that chain, and the level you choose decides how often your pins are at risk.

Which level of the chain should you pin?

Pin your own leaf key where you hold it, use roots only as a fallback, and never pin an intermediate.

Which certificate key to pin: your own leaf key if you hold it, never an intermediate, and roots only as a fallback
Three levels of a certificate chain compared on whether to pin them. Your leaf key, the strongest choice and highlighted: you generate the key and keep it in Key Vault, it is reused at every renewal so the pin keeps matching, and it is present in every chain a phone builds. Pin it, if the key is yours, with a backup key pinned too. Intermediate, which changes often: it is held by the certificate authority, Let's Encrypt switches intermediates annually, and a certificate may be signed by any active intermediate. Do not pin it, because it is too likely to change between app releases. Root, the fallback: it is held by the certificate authority, changes over years with new generations cross-signed, and phones may end their chains at different roots. Pin roots only as a fallback, and then pin every root a supported phone could end at. A pin is a hash of a public key, so it survives any renewal that keeps the same key.
  • Your leaf certificate. If you generate the key and reuse it at renewal, the pin survives every renewal. If the certificate is managed by a provider, the provider holds the key and can replace it.
  • Intermediates. These belong to the certificate authority and change without notice. Let’s Encrypt says it intends to switch which intermediates are in use annually, and a certificate may be signed by any of its active intermediates, of which its certificates page currently lists four.
  • Roots. These change over years rather than months, but authorities do move to new root generations and cross-sign them from older roots, so a root pin set needs maintaining.

Apple’s guidance recommends pinning certificate authority public keys rather than server keys, and for an app whose certificates come from a provider that is the safer choice. On Azure, though, you can hold your own key in Key Vault and reuse it at every renewal, and a leaf key pin then avoids the question of which roots each phone trusts, because the leaf is in every chain.

Why can two phones build different chains?

A phone does not simply accept the chain a server sends. It builds its own chain of trust to a root in its trust store. Android’s network security configuration documentation says one of the public keys in the chain of trust must be in the set of pins, and Apple says a pinned certificate authority key must appear in the chain as an intermediate or a root.

When we tested native pinning in December 2026 against our own website, which sits behind Cloudflare, the server sent Let’s Encrypt’s default chain: our certificate, the YE1 intermediate, ISRG Root YE, and cross-signs through ISRG Root X2 to ISRG Root X1. The same chain came back on every test.

Let’s Encrypt lists Root YE among roots that are not yet widely trusted. A phone that does trust Root YE can finish its chain there and never reach X1, so an app pinned only to X1 could refuse the site on that phone, while an older phone that trusts only X1 would build the longer chain. Which roots each phone trusts depends on its operating system version, so in our test build we pinned every root the chain could end at. Pinning our own leaf key would have avoided the question entirely.

Can you pin the certificate your Azure edge serves?

The certificate your app sees belongs to whatever terminates TLS: Front Door, App Service, Application Gateway, an ingress controller in Azure Kubernetes Service (AKS), or Cloudflare in front of any of them. The same API can be pinnable or not depending on which certificate that edge serves.

Where TLS ends Whose certificate Pin it? Why
Front Door, managed certificate Microsoft’s, issued through DigiCert No Microsoft’s Front Door documentation says to avoid pinning a managed certificate or any part of its hierarchy, and that Azure can change any aspect of it, including the root issuer. Microsoft has also been moving managed TLS certificates to authorities under new DigiCert roots (Global Root G2 and G3).
Front Door, your certificate from Key Vault Yours Yes You control the key. Reference the secret’s latest version so renewals reach Front Door.
App Service on azurewebsites.net, or an App Service managed certificate Microsoft’s No Microsoft renews these, and you never hold the key.
App Service or Application Gateway with your certificate from Key Vault Yours Yes You control the key and its renewal policy.
AKS ingress with cert-manager Yours Yes Set rotationPolicy: Never if you pin the leaf key, because the default changed in cert-manager 1.18 (see below).
Cloudflare universal or advanced certificate Cloudflare’s, from an authority Cloudflare chooses No Cloudflare does not support pinning these certificates. It uses several certificate authorities (Let’s Encrypt, Google Trust Services and SSL.com, with Sectigo for backup certificates) and says their root lists should not be used for pinning.
Cloudflare with a custom certificate you upload Yours Yes Cloudflare calls this the only advisable approach where pinning is needed, and warns that pinning still carries outage risk if a renewal deploys a new key.

Our own test site uses Cloudflare’s universal certificate. That was fine for proving pinning works over a few days, and it is exactly what we would not pin in a released app: if Cloudflare renews from a different authority, every installed copy pinned to the old roots stops connecting until users install an update.

How do shorter certificate lifetimes affect pinning?

Public TLS certificates are getting much shorter lives, which means more renewals, and every renewal is a chance for a pin to break. Under the CA/Browser Forum’s ballot SC-081, the maximum lifetime falls from 398 days to 47 days between March 2026 and March 2029:

From Maximum lifetime of a public TLS certificate
15 March 2026 200 days
15 March 2027 100 days
15 March 2029 47 days

Let’s Encrypt is going further. Its move from 90 to 45 days takes its default profile to 64-day certificates on 10 February 2027 and 45-day certificates on 16 February 2028, and it already offers a 45-day profile and a six-day profile to those who opt in.

We keep the certificate and the key apart: renew the certificate as often as the rules require, reuse the same key across those renewals, and pin the key. Each Azure route supports this:

  • Key Vault. A certificate policy’s key properties include a ReuseKeyOnRenewal setting. Set it, and after the first renewal check that the public key hash has not changed. Key Vault can renew automatically through its partner authorities, DigiCert and GlobalSign, at a percentage of the lifetime or a number of days before expiry. Other authorities are allowed but do not support automatic renewal, so with them you run the renewal yourself, reuse the key, and import each renewal as a new version.
  • Front Door with your certificate. Select the latest version of the secret and Front Door picks up each renewal. Microsoft says it takes up to 72 hours for a new version to be deployed automatically, so renew well before expiry.
  • cert-manager. cert-manager 1.18 changed the default private key rotation policy from Never to Always, which generates a new key at every issuance. Set rotationPolicy: Never explicitly on any certificate whose leaf key you pin, and keep a renewal window with renewBefore.

What periods do we suggest?

These are our suggestions rather than standards. The renewal point follows Let’s Encrypt’s advice for clients that do not use ACME Renewal Information (ARI, RFC 9773), which is to renew at about two thirds of the certificate’s life. Where your renewal client supports ARI, let it choose.

Item Suggestion Why
Certificate renewal At two thirds of its life: about day 133 of 200, day 67 of 100, day 31 of 47 Leaves a third of the life to notice and fix a failed renewal, and covers Front Door’s rollout of a new version
Primary leaf key Reuse across renewals, and replace it about once a year, or at once if it may be compromised Keeps pins stable between app releases while still retiring keys on a schedule
Backup leaf key Generate it now, pin it in every release, and keep it in a separate Key Vault that no server reads Lets you move to a new key without waiting for an app release
Root pins, where you rely on them Review at every release, and add a new root generation as soon as the authority announces it Phones on newer operating systems may end their chains at the new root
Android pin expiry Set an expiry comfortably beyond your release cadence, such as 12 to 18 months, and move it forward with each release After the date, Android stops enforcing the pins. Google warns this lets attackers bypass them on old installs, and the trade is deliberate: an old install loses pinning rather than its connection. iOS has no equivalent

How do you move to a new key without breaking installed apps?

A pin lives in the app’s native configuration, the iOS Info.plist or Android’s network security configuration, which is part of the app binary. An over-the-air JavaScript update cannot change it: Expo’s EAS Update, for example, updates the non-native parts of an app, and native changes need a new build. A new pin therefore reaches users only through a store release, and only once they install it.

Rotation depends on the backup key already being in every installed copy. Android’s documentation makes the same point: always include a backup key, so that if you have to switch keys or change authorities, the app keeps connecting.

Rotating a pinned key: every release pins key A and backup B, the server moves to B, then a release pins B and C
A swimlane showing how to rotate a pinned key, across three lanes: app releases, the server key and keys held offline. Stage 1, before: every app release pins key A and backup key B, key A serves traffic, and key B is pinned but never deployed. Stage 2, switch, highlighted: the server moves to key B, which installed apps already trust, so no app release is needed. Stage 3, next release: a release pins key B and a new backup key C, key B serves traffic and key A is retired, and key C is kept where no server reads it.
  1. Every release pins the primary key A and the backup key B, and, if you use them, the roots as a fallback.
  2. To replace A, on schedule or because it may be compromised, move the server to B. Every installed copy already trusts B, so no app release is needed.
  3. Generate a new backup, C, and ship a release that pins B and C. Retire A.
  4. Keep a minimum supported version in the app, so you can ask users of very old releases to update when their pins have fallen too far behind.

How should pinning fit with failover?

Global edge networks can fail as a whole. On 29 October 2025, Azure Front Door had a global outage that ThousandEyes traced to a configuration change that stopped nodes across Front Door’s fleet loading properly. On 18 November 2025, Cloudflare had a global outage that it explained as a database permissions change that doubled the size of a Bot Management feature file, past a limit in the software that reads it. In both cases, sites that depended on a single edge were unreachable for hours.

Microsoft’s guidance on global routing redundancy puts Azure Traffic Manager in front, directing traffic to Front Door or to an alternative service, and recommends Traffic Manager’s weighted routing method for mission-critical architectures. Its Front Door best practices name Application Gateway or a partner content delivery network as alternatives, advise using Front Door or Traffic Manager but not both unless high availability needs both, and say Traffic Manager should then always sit in front. Microsoft also notes that if Traffic Manager is unavailable, users might not reach your application, so it becomes a dependency of its own.

Failover for a pinned mobile app: Traffic Manager routes to Front Door or Application Gateway, each with the same key
Four layers of a failover design for a pinned mobile app. The mobile app on iOS and Android pins key A and backup key B in its native configuration. DNS routing through Azure Traffic Manager uses health probes to send traffic to a healthy path. The edge paths, highlighted, carry the same certificate: Front Door with your Key Vault certificate on key A, and Application Gateway with the same certificate on key A and its own web application firewall. The origin is your API, reached through either path. With a managed certificate on either path the keys would differ, and a pinned app would refuse the path it is switched to.

Pinning and failover meet at the certificate. If Front Door serves its managed certificate and Application Gateway serves another, the keys differ, and a pinned app refuses whichever path it is switched to, so a failover meant to keep the app available makes the outage worse. With your own certificate on every path, by the same Key Vault reference on Front Door and Application Gateway, or uploaded as a custom certificate to Cloudflare, any path satisfies the pins.

What about DNS during a switch?

  • Do not let the switch depend on the provider that is down. Keep control of the API host name’s records somewhere you can change them during that provider’s outage, and make sure the people on call can reach it.
  • Keep the time to live short. We suggest five minutes or less for the API host name’s records. Resolvers and phones cache answers, so a switch spreads over minutes rather than happening at once.
  • Bypassing Cloudflare sends clients to your origin. Turning off Cloudflare’s proxy for the record points clients straight at the origin, which then needs a publicly trusted certificate for the API host name carrying your pinned key. Cloudflare says its Origin CA certificates only encrypt traffic between Cloudflare and your origin, and that visitors may see untrusted certificate errors if proxying is turned off, so they will not do.
  • Plan for what the alternative path lacks. It may have no caching, and it needs its own web application firewall, such as Application Gateway’s, and its own rate limits.

What should the runbook cover?

When What to do
Before Install the same certificate, by the same Key Vault reference, on every path. Configure Traffic Manager’s health probes. Set short TTLs. Write down the manual override, and rehearse it with a released build against a test host name that resolves to the alternative path. We suggest rehearsing every quarter.
During Confirm the outage on the provider’s status page and with your own probes. Move traffic to the alternative path or disable the failed endpoint. Check with a pinned build on a real phone that the API answers.
After Move traffic back once the provider is stable. Check that renewals still reach every path: a version Front Door has not picked up shows when you compare its certificate with the latest version in Key Vault.

What should you check before you ship pinning?

  • Pin only the API host names you control, and only on a certificate whose key you hold.
  • Prefer your own leaf key, reused at renewal, with a backup key pinned in every release and held where no server reads it.
  • If you pin roots instead, pin every root a supported phone’s chain could end at, and never an intermediate.
  • Automate renewal at two thirds of the certificate’s life, or by ARI.
  • Check that key reuse is switched on: ReuseKeyOnRenewal in Key Vault, rotationPolicy: Never in cert-manager.
  • Set an Android pin expiry and move it forward with each release.
  • Keep a minimum supported app version that you can raise.
  • Put the same certificate on every failover path, keep DNS changeable during an edge outage, and rehearse the switch.
  • Test that pinning fails the way you expect, using OWASP’s MASTG-TEST-0022 on Android as a guide.

How do we approach this?

We build and support mobile apps with Azure backends, and pinning is one of the decisions we make with you early, because it shapes how certificates, releases and failover work for the life of the app. Our mobile app development service covers the build, including React Native apps built with Expo, and our guide to mobile API best practices covers the wider set of decisions for a mobile backend. If you already have an app in production and want a second opinion on its pinning or failover, our mobile and API security review covers both.

Frequently asked questions

Should every mobile app use certificate pinning?
No. We pin the API for apps that handle personal, health or financial data, and for staff apps that reach business systems. An app that only reads public content rarely needs it. Apple advises deploying pinning with caution, so pin only where you can also run the key rotation and failover that pinning demands.
Can we pin an Azure Front Door managed certificate?
No. Microsoft's Front Door documentation says to avoid pinning a managed certificate or any part of its hierarchy, because Azure can change any aspect of it, including the root issuer. Use your own certificate from Key Vault on Front Door, and pin its key.
Should we pin the leaf certificate or a root certificate?
Pin the public key of your own leaf certificate if you hold the key and reuse it at renewal, with a backup key pinned too. Pinning roots is a fallback when you cannot hold the key, and then you must pin every root a supported phone's chain could end at. Never pin an intermediate.
What happens to a pinned app when the certificate renews?
Nothing, if the renewal keeps the same key, because a pin matches the public key rather than the certificate. Pins break when the key changes, which is why key reuse settings matter in Key Vault and in cert-manager, where the default since version 1.18 is a new key at every issuance.
Can we pin a certificate served by Cloudflare?
Not Cloudflare's own certificates. Cloudflare does not support pinning its universal or advanced certificates and chooses which certificate authority issues them. If pinning is essential, Cloudflare says to upload a custom certificate, and you then pin that certificate's key.

Ready to transform your software?

Let's talk about your project. Contact us for a free consultation and see how we can deliver a business-critical solution at startup speed.