Mobile apps run on devices you do not control, talk to servers over networks you do not control, and ship as binaries anyone can download and inspect. That shapes every security decision: assume the client can be read, modified and replayed, and design so that compromise of one device does not compromise your users or your backend.
These mobile app security best practices are organized around the OWASP Mobile Application Security Verification Standard (MASVS), which gives teams a shared vocabulary for requirements, and the Mobile Application Security Testing Guide (MASTG), which explains how to verify them. They are engineering guidance, not legal advice; regulated apps should involve counsel and a qualified security assessor. If you are building in healthcare or fintech, treat this as the baseline, not the ceiling.
Key takeaways
- Use OWASP MASVS as your requirements checklist and the MASTG as your testing manual; pick the controls that match your risk profile.
- Treat the app binary as public: no API secrets in code, keys in the Keychain or Android Keystore, and authorization enforced on the server.
- Use OAuth 2.0 with PKCE through the system browser for sign-in, short-lived access tokens, and biometrics bound to keystore-protected keys rather than a simple yes/no check.
- Root and jailbreak detection only raise the cost of attacks; server-verified signals from Play Integrity API and App Attest are stronger, but still one input among several.
- Supply-chain hygiene and privacy are security too: scan dependencies, keep privacy manifests accurate, and keep personal data out of logs.
What are OWASP MASVS and MASTG?
MASVS defines what a secure mobile app should do. Version 2 groups requirements into control areas: storage, cryptography, authentication and authorization, network communication, platform interaction, code quality, resilience against reverse engineering and tampering, and privacy. MASTG is the companion manual with test cases and techniques for iOS and Android, and the OWASP project also maintains a weakness enumeration (MASWE) that links the two.
Rather than trying to satisfy every control, decide your risk profile. A content app and a banking app should not carry the same resilience requirements. Use the standard to agree on scope with your team, vendor or penetration tester, then test against it.
| MASVS area | Core question | Examples of controls |
|---|---|---|
| STORAGE | Is sensitive data stored safely on the device? | Keychain/Keystore, no secrets in preferences, backup exclusions |
| CRYPTO | Is cryptography used correctly? | Platform crypto APIs, no custom algorithms, hardware-backed keys |
| AUTH | Are authentication and authorization sound? | OAuth 2.0 with PKCE, server-side authorization, biometrics bound to keys |
| NETWORK | Is data in transit protected? | TLS everywhere, ATS and Network Security Config, optional pinning |
| PLATFORM | Does the app use platform features safely? | Validated deep links, safe WebViews, minimal exported components |
| CODE | Is the code and its dependencies kept secure? | Dependency scanning, input validation, forced updates for critical fixes |
| RESILIENCE | Does the app resist tampering where it matters? | Play Integrity API, App Attest, obfuscation, tamper detection |
| PRIVACY | Is user data minimized and handled transparently? | Data minimization, privacy manifests, Data safety form accuracy |
Secure data storage on iOS and Android
The first rule of mobile storage is to store less. Every token, document and cached response on the device is something that can leak through backups, a lost phone or a compromised OS. For what must be stored, use the platform’s protected stores.
- iOS: store credentials and keys in the Keychain with an appropriate accessibility class (for example, available only after first unlock and only on this device). Use Data Protection classes for files, and the Secure Enclave for keys that should never leave the hardware.
- Android: generate and hold keys in the Android Keystore, hardware-backed where the device supports it (including StrongBox on supported devices), and use those keys to encrypt sensitive data you store in files or databases.
- Never put tokens, personal data or secrets in UserDefaults, SharedPreferences, plain SQLite or log files.
- Exclude sensitive files from cloud backups, and clear caches and tokens on logout.
- Protect screens with sensitive data from appearing in the app switcher snapshot, and consider FLAG_SECURE on Android for screens like card details.
Network security: TLS, ATS and certificate pinning tradeoffs
All traffic should use TLS. iOS App Transport Security and Android’s Network Security Configuration block cleartext traffic by default on current OS versions; keep it that way and avoid broad exceptions. Validate certificates with the platform’s default trust evaluation rather than custom code, which is a frequent source of bugs.
Certificate pinning restricts the app to specific certificates or public keys, which defends against interception by a mis-issued or user-installed certificate. It is not free. If a pinned key rotates without an app update, the app stops working for every user on that version. Android supports pin sets with expiry dates in the Network Security Configuration, and iOS supports pinned public keys through NSPinnedDomains in Info.plist.
- Pin public keys (SPKI hashes), not leaf certificates, and always include at least one backup pin.
- Coordinate pins with whoever manages your certificates, including CDN and API gateway providers.
- Consider pinning only for high-risk apps such as banking and health, and pair it with a forced-update mechanism.
- Remember that pinning protects the channel, not the server: an attacker with a modified app can still call your API, so authorization must live server-side.
Authentication: OAuth 2.0 with PKCE, tokens and biometrics
For sign-in with an identity provider, follow the OAuth 2.0 for Native Apps guidance (RFC 8252): use the authorization code flow with PKCE (RFC 7636), opened in the system browser via ASWebAuthenticationSession on iOS or Custom Tabs on Android. Do not use embedded WebViews for login, and do not use the implicit flow or ship a client secret in the app.
Keep access tokens short-lived and refresh tokens protected in the Keychain or Keystore. Rotate refresh tokens where your provider supports it, and revoke them server-side on logout or suspected compromise. Passkeys are now well supported on both platforms and remove passwords from the phishing equation; consider them for consumer apps.
Using biometrics correctly
A biometric prompt that returns “success” to app code can be bypassed on a compromised device. The stronger pattern is to bind biometrics to a cryptographic key: on iOS, a Keychain item or Secure Enclave key with an access control that requires biometry; on Android, BiometricPrompt with a CryptoObject backed by a Keystore key that requires user authentication. The key only becomes usable after a successful biometric check, so the check cannot simply be skipped.
- Decide whether enrolling a new fingerprint or face should invalidate the key; for high-risk actions it usually should.
- Always offer a fallback such as device passcode or re-authentication with the server.
- Use step-up authentication for sensitive actions (payments, changing contact details), not only at login.
App integrity: Play Integrity API, App Attest, and the limits of root and jailbreak detection
Root and jailbreak detection checks for signs of a modified OS. It is useful as a speed bump and as a risk signal, but determined attackers can hide root or patch the check out of the binary. Do not build your security model on it, and avoid locking out legitimate users on the basis of a single client-side check.
Attestation is stronger because the verdict is signed by the platform and verified on your server. On Android, the Play Integrity API (which replaced the SafetyNet Attestation API) reports whether the request comes from your genuine app binary, installed through Google Play, on a device that passes integrity checks. On iOS, App Attest in the DeviceCheck framework lets your server verify that requests come from a legitimate instance of your app on a genuine Apple device.
- Verify attestation tokens on the server, never only in the app.
- Bind attestation to a server-issued nonce or request hash to prevent replay.
- Use verdicts as risk signals: require step-up verification or limit high-risk actions rather than blocking outright.
- Respect quotas and handle unavailability gracefully, since not every device or region supports every check.
- Add code obfuscation (R8 on Android, plus commercial tools if your risk warrants it) to raise the cost of reverse engineering.
Keep secrets out of the app binary
Anything compiled into an app can be extracted, whether it sits in code, a plist, resources or a .env file bundled at build time. Obfuscating a secret only delays discovery. The fix is architectural.
- Call third-party APIs that require secret keys (payments, AI models, SMS) through your own backend, which holds the key.
- Use per-user, short-lived tokens issued after authentication instead of shared static keys.
- For keys that must ship in the app, such as maps or analytics client IDs, restrict them by bundle ID, package name and signing certificate in the provider console.
- Keep build-time secrets (signing keys, store API keys) in CI secret stores, and scan the repository for leaked credentials with tools such as gitleaks or GitHub secret scanning.
Dependency scanning and supply-chain security
A typical app pulls in dozens of open-source and commercial SDKs through Swift Package Manager, CocoaPods, Gradle, pub or npm. Each one runs with your app’s permissions and collects whatever it is allowed to.
- Enable automated vulnerability alerts (Dependabot, Renovate, Snyk or OWASP Dependency-Check) and review updates on a schedule.
- Pin versions and commit lockfiles so builds are reproducible.
- Generate a software bill of materials (SBOM) for regulated or enterprise customers.
- Vet SDKs for data collection before adding them, and remove unused ones.
- On iOS, confirm third-party SDKs ship their own privacy manifests and, for SDKs on Apple’s list of commonly used SDKs, signatures; Xcode can generate a privacy report that aggregates them.
Privacy manifests, platform disclosures and logging hygiene
Privacy is part of the MASVS and a store requirement. Apple requires privacy manifests that declare collected data types, tracking domains and the reasons for using certain “required reason” APIs, and App Tracking Transparency consent before tracking across apps and websites. Google Play requires an accurate Data safety section. Mismatches between what you declare and what the app does are a common cause of review rejections. US privacy laws such as CCPA/CPRA and state laws like the Texas Data Privacy and Security Act may add obligations; work with counsel on those.
Logs are a frequent and overlooked leak. Debug logs end up in crash reports, analytics events and device logs that other tools can read.
- Never log tokens, passwords, full card numbers, health data or precise location.
- Strip verbose logging from release builds and configure crash reporters to scrub personal data.
- Keep analytics event properties free of personal data unless disclosed and necessary.
- Review clipboard use, screenshots and push notification content for sensitive information on the lock screen.
How to test and maintain mobile app security
Security is a release practice, not a one-off audit. Build checks into CI, test before major releases, and keep watching after launch. Our mobile app testing services include security checks aligned with MASTG test cases.
- Threat-model new features that touch auth, payments or personal data before building them.
- Run static analysis (SAST) and dependency scanning in CI; add mobile-specific scanners such as MobSF for binary checks.
- Commission an independent penetration test against agreed MASVS controls before launch for high-risk apps, and after major changes.
- Maintain a forced-update mechanism so critical fixes reach users.
- Monitor for abuse: unusual API patterns, credential stuffing, and attestation failures.
- Keep a written incident response plan that includes app-store and user-communication steps.
Need a second opinion on your app plan?
Talk to a mobile engineer about scope, stack and team. No obligation.