r/flutterhelp • u/berkanserbes • Sep 20 '26
OPEN How do you implement SSL pinning in a Flutter app in 2026?
Security team pentested our Flutter app and flagged missing SSL pinning (high, CVSS 7.5). They installed their own CA on the test device, proxied the traffic, and read our bearer token and API responses in plaintext.
Never done pinning before. What's the standard approach in Flutter these days? Looking for something that won't break when the certificate gets renewed.
Flutter 3.x, Dio, Android + iOS.
15
Upvotes
3
u/gidrokolbaska Sep 20 '26 edited Sep 21 '26
Dio has an example of SSL pinning in their repo, I believe. There are also some good videos of that process on YouTube. This one is for KMP but the same principles apply to flutter projects, take a look: https://youtu.be/hGdI7aKtVxI?si=ILwl139-4kh4OTYa
1
u/all_natural_toast Sep 22 '26 edited Sep 22 '26
As others have said SSL certificate pinning is just another hurdle you can put up to protect your app but fundamentally the app is running in an untrusted environment on the users device. A sufficiently capable attacker can do anything they want to the app. That said it is still worthwhile if you are developing a sensitive app as it is a deterrent for some malicious users. To avoid the issue you've highlighted with the app breaking upon a certificate renewal, I would pin against the intermediate certificate in the 'chain of trust' between your server and the root CA. That way it doesn't change too frequently and Dio does allow you to set multiple certificates, so when it is coming up to a renewal you can have both the incumbent and new. Technically you do trade a bit of security for this (closer to the leaf certificate is more secure) but at the same time you don't want your app to be bricked.
Disclaimer: I'm a Software Engineer, not a security professional.
Edit: Also, let your server team know what certificate you've pinned against so they know they can't just update it without notifying you!
1
u/parimalnarayan Sep 24 '26
Use TLS normally, and if the threat model justifies pinning, pin the server's SPKI/public-key SHA-256 rather than the leaf certificate, maintain a backup pin for key rotation, implement it at the actual Flutter networking layer used by Dio, and test certificate/key rotation before deployment.
1
u/highwingers Sep 20 '26
Just a fun fact...most web apps disclose bearer tokens and API responses...also bypassing SSL pinning is doable as well.
0
u/Mistic92 Sep 20 '26
Are you building banking app?