Every API your app calls should use SSL encryption, so the data can't be read in plain text between the moment it leaves the server and the moment it reaches the client. That protection rests on the client trusting the right server, and that trust can be subverted on the device itself. SSL pinning narrows the trust to certificates you choose, and the price is a certificate expiry date you have to manage in the app as well as on the server.

Key terms

  • Certificate Authority (CA): an issuer whose certificates come pre-installed on the client and whose signature makes a server's certificate valid for https.
  • Root CA certificate: a CA certificate installed on the device, which the client then trusts to sign the certificates servers present.
  • SSL pinning: a client-side technique that embeds a list of trusted certificates in the app during development and accepts only requests signed with one of them.

Trust goes to whoever a CA vouches for

You can tell a secure endpoint by its URL, which starts with https:// instead of http://. With https, the client trusts a server only if the server presents a valid certificate signed by a trusted Certificate Authority that is pre-installed on the client. The check is about who signed the certificate: any server that presents a valid certificate signed by a CA the client trusts passes it.

That is why https endpoints alone can still leave your data open to interception. An attacker who installs a malicious root CA certificate on the user's device makes the client trust every certificate the attacker signs. From then on, the attacker can present certificates the app accepts while sitting between the app and your server. Relying on certificate validation alone leaves the app open to this man-in-the-middle attack, even though every request goes over https.

Pinning the certificates you expect

SSL pinning is a client-side defense against that attack. During development you embed, or pin, a list of trusted certificates in the app. At runtime the app accepts only requests signed with one of those certificates and rejects self-signed certificates. A certificate signed by the attacker's root CA is not on the pinned list, so installing that root CA on the device no longer gets the attacker's certificates accepted.

Pinning moves part of the trust decision from the device's CA list into your app build, and that move is the source of both its protection and its cost.

Expiry turns into a release

Certificates expire every 1 to 2 years. With pinning, a new certificate has to be updated in two places: in the app and on the server. As soon as the server starts presenting the new certificate, every installed copy of the app that still embeds the old one stops working. Users who haven't installed an update lose access to your API at that moment, however recently they last opened the app.

Plan each renewal around that moment. The pin is a list of trusted certificates, so the app update can embed the new certificate next to the old one. That update has to ship and reach your users before the server starts presenting the new certificate, so the server switch comes last. A renewal planned only on the server side is the change that breaks the pinned app in the field.

Deciding whether to pin

React Native's security guidance is a catalogue of options that each add protection, and it is not a checklist every app must complete. Pinning blocks the rogue root CA attack and adds release work on every certificate cycle. Weigh it the way you weigh the other options: invest in proportion to how sensitive the data is, how many users you have, and how much damage an attacker could do with access to one of their accounts. An app that shows public content has less to defend than one that holds account details, and the pinning decision can follow that difference.

✓ Completed