Predictable random values in mobile applications
Security-sensitive random values must resist prediction from previous outputs or device state. Understanding predictable random values in mobile applications helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Cryptographic protection depends on the whole operation: the algorithm, its parameters, key handling and the way results are verified. Different mechanisms provide confidentiality, integrity or evidence of origin. Substituting one property for another can leave the important business requirement unprotected.
Android apps sometimes use an insecure pseudorandom number generator (PRNG), such as java.util.Random, which is a linear congruential generator and produces a predictable sequence for any given seed value. As a result, java.util.Random and Math.random (the latter simply calls nextDouble on a static java.util.Random instance) generate reproducible sequences across all Java implementations whenever the same seed is used. This predictability makes them unsuitable for cryptographic or other security-sensitive contexts.
In general, if a PRNG is not explicitly documented as being cryptographically secure, it should not be used where randomness must be unpredictable. Refer to the Android Documentation and the "random number generation" guide for further details.
Why it matters
Consider a realistic failure: a token uses a predictable timestamp and a non-cryptographic random generator.
A weakness can undermine trust in stored records or messages even when their appearance does not change. Assessment should connect the defect to the data or action it protects and the capabilities available to an attacker.
Mobile behaviour can change between a fresh installation, an authenticated session, background activity and a device migration. The assessment needs the actual release and representative supported device states.
How penetration testers check for it
Trace random APIs, seeding and error handling for keys, tokens and challenges.
- Determine whether the generated random values are used for security-relevant purposes, such as generating cryptographic keys, initialization vectors (IVs), nonces, authentication tokens, session identifiers, passwords, or PINs.
- Determine whether the generated values are used for security-relevant purposes, such as generating cryptographic keys, initialization vectors (IVs), nonces, authentication tokens, session identifiers, passwords, or PINs.
- Exercise the app extensively to trigger as many flows as possible and enter sensitive data wherever you can.
- Trace key generation, access, replacement and verification.
- Test invalid inputs and failure handling with controlled data.
How to fix it
Use operating system cryptographic randomness and fail safely if generation fails.
- Use maintained standard implementations and appropriate parameters.
- Protect keys throughout generation, use and retirement.
- Authenticate the content and identity that the operation actually relies on.
- Reject failed verification before trusting or processing the result.
An unusual cryptographic implementation is not enough to establish practical compromise. The report should explain the failed property and a defensible consequence.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Weak cryptography and random values in firmware
- Reviewing random values used by application security controls
- Generating strong mobile encryption keys
Read about our methodology or contact pentested.com to discuss your mobile applications.