Flutter security best practices are the controls that protect a shipped Flutter app and its users' data on a device you do not control: where tokens live, which secrets stay out of the binary, how traffic is protected and how your backend rejects fake clients. The OWASP Mobile Application Security project gives these a checklist structure, called MASVS. This guide follows it, uses vendor and OWASP documentation only, and says where Flutter's own docs are silent. I have shipped 20+ Flutter apps, and two of the case studies below show the patterns in real projects.
What is OWASP MASVS and how does it map to a Flutter app?
MASVS is the OWASP Mobile Application Security Verification Standard, and it lists eight control groups. The sister MASTG section holds the Android and iOS testing guides you use to check each one (OWASP MASVS). One control reads, in full, "The app securely stores sensitive data" (MASVS-STORAGE-1). Flutter changes how you implement the controls, not which ones apply.
| MASVS group | What to do in a Flutter app | Section below |
|---|---|---|
| MASVS-STORAGE: Storage | Tokens and keys in Keychain or Keystore-backed storage; manage Android backups | Storage |
| MASVS-CRYPTO: Cryptography | Use platform key stores and vetted libraries; never invent your own scheme | Storage, case studies |
| MASVS-AUTH: Authentication and Authorization | Enforce access on the server or in Security Rules, never only in widgets | Backend |
| MASVS-NETWORK: Network Communication | HTTPS only, careful pinning, no blanket certificate bypass | Network |
| MASVS-PLATFORM: Platform Interaction | Review platform channels, deep links and plugin permissions | Checklist |
| MASVS-CODE: Code Quality | Keep the SDK and dependencies current; read pub advisories | Dependencies |
| MASVS-RESILIENCE: Resilience Against Reverse Engineering and Tampering | Obfuscate release builds and keep symbol files | Obfuscation |
| MASVS-PRIVACY: Privacy | Collect and send less; sanitise data before it leaves the device | Case studies |
The OWASP Mobile Top 10 2024 final release is the risk-side view: Improper Credential Usage, Inadequate Supply Chain Security, Insecure Authentication/Authorization, Insufficient Input/Output Validation, Insecure Communication, Inadequate Privacy Controls, Insufficient Binary Protections, Security Misconfiguration, Insecure Data Storage and Insufficient Cryptography (OWASP). The mapping in the table is my own reading of how those groups land in Flutter code, not an OWASP document.
Where should a Flutter app store tokens and keys?
In flutter_secure_storage, not in SharedPreferences or plain files. The package uses the Keychain on iOS and macOS. On Android its default encrypts with RSA OAEP as the key cipher and AES-GCM as the storage cipher ("RSA-wrapped AES"), and its biometric-capable options use KeyStore-based storage. The minimum Android SDK is 23 (package page).
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
const storage = FlutterSecureStorage();
await storage.write(key: 'refresh_token', value: token);
final saved = await storage.read(key: 'refresh_token');
await storage.delete(key: 'refresh_token'); // on sign-out
Three details decide whether this actually protects users.
- iOS accessibility. Keychain items default to "When Unlocked". "After First Unlock" suits background work, and Apple's advice is "Always use the most restrictive option that makes sense for your app." Items whose attribute ends in
ThisDeviceOnlyare not migrated when restoring another device's backup (Apple). The plugin exposes anaccessibilityoption, defaulting to unlocked. - Android Auto Backup. It includes shared preferences and internal files by default, and
android:allowBackupdefaults totrue(Android). The plugin's page warns that restored backups can causejava.security.InvalidKeyException: Failed to unwrap keyand recommends disabling autobackup or excluding the SharedPreferences files it uses. For most apps with secure storage, the simplest fix is one attribute:android:allowBackup="false"inAndroidManifest.xml. - What Keystore protects. Android says keystore key material is non-exportable and can be bound to secure hardware, but if your app's process is compromised, an attacker "might be able to use the app's keys but can't extract their key material" (Android Keystore). It stops extraction, not use.
Call WidgetsFlutterBinding.ensureInitialized() in main before the first storage call, as the package requires. On iOS and macOS with Keychain Sharing or App Groups, the package warns that a missing entitlement can make values appear written but never persist. Web support is experimental and needs HTTPS or localhost.
For larger data, store an encryption key in secure storage and keep the data in an encrypted database. That is how I handled two of my own projects, covered under real examples below.
Can you hide an API key or secret inside a Flutter app?
No. Flutter's obfuscation guide says it plainly: "It is a poor security practice to store secrets in an app" (Flutter). My own reasoning follows from that: anything the app can read at runtime, someone holding the binary can eventually read, so a secret in the app is a secret you have already published.
Firebase draws a useful line. Its API keys "only identify your Firebase project and app to those services" and keys restricted to Firebase services "do not need to be treated as secrets". Access is controlled by IAM, Security Rules and App Check. The exception is a Gemini Developer API key, which "should never be included in your code or configuration files" (Firebase).
For any other secret, such as an OpenAI or Gemini key, put a server between the app and the provider. I wrote the full pattern in stop hardcoding LLM API keys in Flutter, and the provider-side details in integrating ChatGPT and Gemini in Flutter. If the leak risk is on your own laptop rather than in the shipped app, that is a different problem, covered in the AI coding agent security checklist.
Does Flutter code obfuscation protect your app?
It makes release binaries harder to read, but it is not protection. Flutter's docs say obfuscation "does not encrypt resources nor does it protect against reverse engineering. It only renames symbols with more obscure names." It works only on release builds, and web apps do not support it (they are minified instead) (Flutter).
flutter build appbundle --obfuscate --split-debug-info=build/symbols
flutter build ipa --obfuscate --split-debug-info=build/symbols
# read an obfuscated crash trace later
flutter symbolize -i crash.txt -d build/symbols/<symbols file for that build>
The documented build targets include apk, appbundle, ios, ipa, macos, windows and linux. Practical points from the same page:
- Back up the symbols. Flutter tells you to back up the SYMBOLS file for each obfuscated build; you need it to de-obfuscate a stack trace. Without it, a production crash report is unreadable. My Flutter bug-fixing guide covers crash reporting.
- Check your code. Code that depends on matching class, function or library names fails after obfuscation. Flutter's example is a test asserting
foo.runtimeType.toString()equals'Foo'. Enum names are not currently obfuscated. - Android shrinking. Flutter's Android page says code shrinking is always enabled in release builds (Flutter).
Treat obfuscation as the MASVS-RESILIENCE layer: it raises the cost of casual inspection and nothing more.
How do you secure network traffic in a Flutter app?
Use HTTPS for every request, and decide deliberately whether to pin. Platform defaults help: Android's network security configuration disables cleartext traffic by default from Android 9 (API level 28) (Android), and Apple's App Transport Security requires TLS 1.2 or later with forward secrecy and treats NSAllowsArbitraryLoads as an exception that "might trigger additional App Store review" (Apple). I could not find an official statement on whether these platform policies govern dart:io sockets, so enforce https:// in your own Dart code too. If a broad exception raises questions in App Review, see Flutter App Store rejection fixes.
On pinning, start with what OWASP says about Flutter: "Flutter uses Dart, which is not proxy-aware and uses its own certificate store," so "any certificates installed on the system are simply ignored" (MASTG-TECH-0109). That blocks a standard intercepting proxy, but MASTG documents workarounds that patch or hook the app, so it is not a security boundary either.
If you pin, know the costs. Android's own guidance for pinning says to include a backup key, because otherwise "you must push out an update to the app to restore connectivity". It also warns that setting an expiration on pins may let attackers bypass them (Android). Flutter's docs do not describe pinning, so this is a sketch built from the dart:io API. Test it against your own server certificate, including its expiry, before shipping.
import 'dart:io';
import 'package:flutter/services.dart' show rootBundle;
Future<HttpClient> pinnedClient() async {
final cert = await rootBundle.load('assets/certs/api_ca.pem');
final context = SecurityContext(withTrustedRoots: false)
..setTrustedCertificatesBytes(cert.buffer.asUint8List());
return HttpClient(context: context);
}
A SecurityContext created with withTrustedRoots: false contains no certificates until you add one (Dart). The API page does not list the accepted certificate formats, so confirm yours loads. Do not shortcut with badCertificateCallback: it is called for a certificate that cannot be authenticated, and "if the callback returns true, the secure connection is accepted" (Dart). A callback that returns true turns TLS off in practice.
If you would rather use a package, secure_pinning on pub.dev defaults to public-key (SPKI) hashes, which survive certificate renewal, and its page recommends a second pin. It comes from a pub.dev verified publisher, but it is at version 0.0.2, which that badge does not make audited, so read the code first. Its page says web is unsupported because browsers do not expose TLS certificate bytes to page JavaScript (pub.dev).
How do you stop fake clients from abusing your backend?
Do the real enforcement on the server, then add attestation. Client-side checks can be bypassed, so access rules belong in Firebase Security Rules or your own API. Firebase says to secure data with Security Rules and App Check rather than rely on key secrecy (Firebase). Sign-in itself is covered in the Firebase Auth guide.
App Check adds an attestation to requests. Providers include Play Integrity on Android and DeviceCheck or App Attest on Apple platforms, and the debug provider is for emulators and CI. When you enable enforcement, "requests from clients without a valid attestation will be rejected". Firebase is clear about limits: "Using App Check does not guarantee the elimination of all abuse", and App Check and Authentication are "complementary" (Firebase App Check). It protects Cloud Firestore, Realtime Database, Cloud Storage, callable Cloud Functions and Firebase AI Logic, among others.
flutter pub add firebase_app_check
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate(
appleProvider: AppleProvider.appAttest, // Android defaults to Play Integrity
);
Firebase's Flutter page states that the Android default is the Play Integrity provider, and notes App Attest is available only on iOS 14.0+ and macOS 14.0+ (Firebase). Use the debug provider only for emulator and CI builds.
If you run your own API, the Play Integrity API returns verdicts for app integrity (is it your unmodified binary), device integrity and account details, and Google suggests a range of server responses rather than a binary allow or deny (Android).
How do you keep Flutter dependencies and the SDK safe?
Update both, and read what pub tells you. Flutter's security page asks you to keep up with SDK releases, keep dependencies current and avoid private, customised Flutter copies that fall behind. It commits to security updates for the version on the stable branch. When I checked on October 24, 2026, that page carried a notice that Flutter 3.47.8 blocks compromised eMudhra CA keys (Flutter security).
For packages, pub surfaces security advisories at dependency resolution, so dart pub get prints a notice with a link. Advisories come from the GitHub Advisory Database. If one does not apply to your app, add its GHSA identifier to ignored_advisories in pubspec.yaml, which applies to your root package only (Dart). Never ignore one without reading it. The agent-side version of this problem, a coding agent adding packages for you, is in the agent security checklist.
What does this look like in real Flutter apps?
Two of my case studies use these patterns, and I am only repeating what they already state.
- Nest AI. A privacy-first parenting companion where I was Senior Flutter Engineer and Security Lead. Child data stays on the device in an AES-256 encrypted Hive store, with the keys held in the iOS Keychain and Android Keystore. A cloud proxy sanitises personally identifiable information before prompts reach an LLM endpoint.
- Expense Manager. An offline-first finance tracker with SQLCipher AES-256 database encryption and no cloud dependencies.
The shared idea is the one in this guide: keep the key in the platform store, keep the bulk data encrypted, and send less off the device.
The Flutter app security checklist before release
- Tokens and keys are in secure storage, and nothing sensitive is in SharedPreferences, logs or plain files.
- The Android manifest sets
allowBackupdeliberately, or excludes the secure storage files. - No third-party secrets, such as a Gemini Developer API key, are in code, assets or config; a server proxy holds them.
- Firebase keys are restricted to Firebase services and never include the Gemini API.
- Every request uses
https://, andbadCertificateCallbackis never=> true. - If you pin, there is a backup pin and a plan for rotation and expiry.
- Releases are built with
--obfuscate --split-debug-info, and the symbols are archived per build. - Security Rules or server checks enforce access, and App Check enforcement is on for supported Firebase products.
- Platform channels, deep links and plugin permissions have been reviewed (MASVS-PLATFORM).
dart pub getadvisories are read, and the Flutter SDK is on the current stable release.- Each MASVS group has been walked through once, with the MASTG tests for the risky ones.
Frequently Asked Questions
Is Flutter secure enough for a production app?
Flutter's security page says it commits to security updates for the stable branch and treats reports as P0. The rest is up to your app: storage, network, backend rules and release builds decide the outcome, not the framework (Flutter).
Is flutter_secure_storage enough to store tokens?
For tokens and small keys, yes: it uses the iOS Keychain, and on Android RSA-wrapped AES by default. Check Android backups, because restored backups can raise "Failed to unwrap key" errors, and pick the strictest Keychain accessibility your app can live with (pub.dev).
Does Flutter obfuscation stop reverse engineering?
No. Flutter says it "does not encrypt resources nor does it protect against reverse engineering"; it only renames symbols, works on release builds and is not supported on web. Keep your symbol files to read crash traces (Flutter).
Should I use certificate pinning in Flutter?
Only if your threat model needs it and you can operate it. Dart ignores certificates installed on the device, but pinned keys and certificates expire or rotate, so always ship a backup pin or you must release an update to restore connectivity (Android).
Where should I store an API key in a Flutter app?
Not in the app. Flutter calls storing secrets in an app a poor practice; keep provider keys on a server and let the app call your endpoint (Flutter). My secure proxy guide shows the pattern for LLM keys.
Is google-services.json or a Firebase API key a secret?
No. Firebase says keys restricted to Firebase services do not need to be treated as secrets, because Security Rules, IAM and App Check control access. A Gemini Developer API key is the exception and must stay out of code and config files (Firebase).
How often should I update the Flutter SDK and packages?
Regularly. Flutter's security page recommends keeping the SDK and dependencies current because updates may fix security defects found in earlier versions, and pub prints advisories whenever you resolve dependencies (Dart).
Need a Flutter app built with these controls from the first commit, or a security review before launch? See my Flutter app development service or get in touch.