A SecureRandom is seeded with a constant, which makes its output predictable

tx0/kotlin:seeded-secure-randomrecommendedwarningsecurity/cryptodepth fastsecurity, cwe-336

What it finds

SecureRandom(byteArrayOf(1, 2, 3)) or random.setSeed(42) with a constant makes the numbers reproducible, which is what an attacker needs. A SecureRandom seeds itself from the system when left alone.

From the rule's source, predictable_seed.rs.

Example from the rule's tests
import java.security.SecureRandom fun randoms() {    val a = SecureRandom("seed".toByteArray())tx0 reports: seeded with a constant    val secureRandom = SecureRandom()    secureRandom.setSeed(42)tx0 reports: seeded with a constant    val b = SecureRandom()}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/kotlin:seeded-secure-random" = "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:seeded-secure-random] reason="..."

tx0 explain tx0/kotlin:seeded-secure-random shows the same in the terminal. Found a false positive? Report it.