A SecureRandom gets a seed written in the source
What it finds
new SecureRandom("seed".getBytes()) or random.setSeed(42) with a constant seed can make a SecureRandom produce the same sequence on every run, depending on the provider: the values are then as predictable as the seed in the source (CWE-336). Without a seed, the generator seeds itself from the operating system.
Reported are constant seeds, integer literals, array literals and the bytes of string literals, given to the SecureRandom constructor or to setSeed on a SecureRandom.
From the rule's source, seeded_secure_random.rs.
import java.security.SecureRandom; class Seeds { void make() { SecureRandom a = new SecureRandom("fixed".getBytes());tx0 reports: this seed is written in the source SecureRandom b = new SecureRandom(); b.setSeed(42L);tx0 reports: this seed is written in the source b.setSeed(System.nanoTime()); }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:seeded-secure-random" = "off"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/java:seeded-secure-random] reason="..."tx0 explain tx0/java:seeded-secure-random shows the same in the terminal. Found a false positive? Report it.