Mobile application development presents certain security challenges that are unique compared to web applications and other forms of software. This cheat sheet provides guidance on security considerations for mobile app development. It is not a comprehensive guide by any means, but rather a starting point for developers to consider security in their mobile app development.
- Opt for a secure design at the beginning of development, not as an afterthought.
- Keep in mind security principles like least privilege, defense in depth, and separation of concerns.
- Follow industry standards and best practices, such as:
- National Institute of Standards and Technology (NIST)
- Internet Engineering Task Force (IETF)
For more information, see the Secure Product Design Cheat Sheet.
- Ensure that your mobile app communicates securely with backend services.
- Use OAuth2, JWT, or similar for secure authentication.
- Regularly update and rotate any used API keys or tokens.
- Request only the permissions your app needs.
- This applies not only to device permissions granted by the user, but also to permissions granted to the app by backend services.
- Avoid storing application files with overly permissive permissions.
- Secure by default: applications should have the most secure settings by default.
Developing with third-party libraries and components introduces the possibility of security unknowns.
- Ensure app signing.
- Use only trusted and validated third-party libraries & components.
- Establish security controls for app updates, patches, and releases.
- Monitor and detect security incidents of used third-party products.
See the Vulnerable Dependency Management Cheat Sheet for recommendations on managing third-party dependencies when vulnerabilities are discovered.
Authentication is a complex topic and there are many pitfalls. Authentication logic must be written and tested with extreme care. The tips here are only a starting point and barely scratch the surface. For more information, see the Authentication Cheat Sheet and M1: Insecure Authentication/Authorization from the OWASP Mobile Top 10.
- Perform authentication/authorization server-side and only load data on the device after successful authentication.
- If storing data locally, encrypt it using a key derived from the user’s login credentials.
- Do not store user passwords on the device; use device-specific tokens that can be revoked.
- Avoid using spoofable values like device identifiers for authentication.
- Assume all client-side controls can be bypassed and perform them server-side as well.
- Include client side code to detect code/binary tampering.
- Do not hardcode credentials in the mobile app.
- Encrypt credentials in transmission.
- Do not store user credentials on the device. Consider using secure, revocable access tokens.
- Require password complexity.
- Do not allow short PINs such as 4 digits.
- Use platform specific secure storage mechanisms, such as Keychain (iOS) or Keystore (Android).
- Use platform-supported methods for biometric authentication.
- Always provide a fallback, such as a PIN.
- Sessions should timeout after inactivity.
- Offer a remote logout feature.
- Use randomly generated session tokens.
- Secure session data, both client and server side.
- Store authentication tokens securely.
- Handle token expiration gracefully.
- Require users to re-authenticate for sensitive operations like changing passwords or updating payment information.
- Consider requring re-authentication before displaying highly sensitive information as well.
- Require authorization checks on any backend functionality.
- Encrypt sensitive data both at rest and in transit.
- Store private data on the device's internal storage.
- Use platform APIs for encryption. Do not attempt to implement your own encryption algorithms.
- Beware of caching, logging, and background snapshots. Ensure that sensitive data is not leaked through these mechanisms.
See the Logging Cheat Sheet for examples of data that should not be logged.
- Always use HTTPS for network communications.
- Ensure all third-party libraries are secure and up to date.
- Minimise any PII to neccessity.
- Attempt to replace PII with less critical information if possible.
- Reduce PII, e.g. less frequent location updates.
- Implement automatic expiration and deletion of PII to minimize retention.
- Ask for user consent before collecting or using PII.
- Assume that all network communication is insecure and can be intercepted.
- Use HTTPS for all network communication.
- Do not override SSL certificate validation to allow self-signed or invalid certificates.
- Avoid mixed version SSL sessions.
- Encrypt data even if sent over SSL, in case of future SSL vulnerabilities.
- Use strong, industry standard cipher suites, with appropriate key lengths.
- Use certificates signed by a trusted CA provider
- Avoid sending sensitive data via SMS.
- Consider certificate pinning. See the Pinning Cheat Sheet for pros and cons of this approach.
- Mask sensitive information on UI fields to prevent shoulder surfing.
- Inform the user about security-related activities, such as logins from new devices.
- Validate and sanitize user input. See the Input Validation Cheat Sheet for more information.
- Validate and sanitize output to prevent injection and execution attacks.
- Use static analysis tools to identify vulnerabilities.
- Make security a focal point during code reviews.
- Keep all your libraries up to date to patch known vulnerabilities.
- Disable debugging.
- Include code to validate integrity of application code.
- Obfuscate the app binary.
- Perform ethical hacking to identify vulnerabilities.
- Example tests:
- Cryptographic vulnerability assessment.
- Attempt to execute backend server functionality anonymously by removing any session tokens from POST/GET requests.
- Leverage automated tests to ensure that security features are working as expected and that access controls are enforced.
- Ensure that security features do not harm usability, which could cause users to bypass security features.
- Have a clear incident response plan in place.
-
Plan for regular updates and patches. In the case of mobile apps, this is especially important due to the delay between when a patch is released and when users actually receive the updated version due to app store review processes and the time it takes for users to update their apps.
-
Use a mechanism to force users to update their app version when necessary.
- Use real-time monitoring to detect and respond to threats.
- Use Android’s ProGuard for code obfuscation.
- Avoid storing sensitive data in SharedPreferences. See the Android docs on working with data securely for more details.
- Disable backup mode to prevent sensitive data being stored in backups.
- Use ATS (App Transport Security) to enforce strong security policies for network communication.
- Do not store sensitive data in plist files.
For further reading, visit the OWASP Mobile Top 10 Project. For a more detailed framework for mobile security, see the OWASP Mobile Application Security Project.