A token, password or key is made from a random generator that is not cryptographically secure
What it finds
java.util.Random and kotlin.random.Random are fast but predictable: a few outputs give away the rest. A value named like a token, password, salt, nonce or key that is drawn from them can be guessed. SecureRandom is made for that.
From the rule's source, random_for_secret.rs.
fun issue(): String { val token = Random().nextLong().toString()tx0 reports: token is drawn from a predictable generator val resetPassword = Random.nextInt(100000, 999999)tx0 reports: resetPassword is drawn from a predictable generator val delay = Random.nextInt(100) val nonce = SecureRandom().nextLong() return token + resetPassword + delay + nonce} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:predictable-random-for-secret" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:predictable-random-for-secret] reason="..."tx0 explain tx0/kotlin:predictable-random-for-secret shows the same in the terminal. Found a false positive? Report it.