Safeguard
Application Security•

CWE-339 Small Seed Space in a PRNG: Brute-Forcing the Seed

If a generator can start from only a few seeds, an attacker can try them all and predict every later output. CWE-339 explained with the Java RandomStringUtils case.

Safeguard Security Team
2 min read

CWE-339, Small Seed Space in PRNG, is when a pseudo-random number generator uses a relatively small seed space. That makes it open to brute force.

Any code that builds passwords, tokens or keys from a generator seeded with a small value is affected, including code that does so indirectly through a utility library.

How it happens

MITRE explains that PRNGs are entirely deterministic once seeded, so guessing the seed should be extremely difficult. If an attacker collects outputs and tries every possible seed until one matches, the attacker then knows the output of every later call. A small seed space means far fewer possibilities to exhaust.

// Vulnerable: java.util.Random has a 48-bit internal seed
Random r = new Random();
String pw = RandomStringUtils.random(12, 0, 0, true, true, null, r);

The observed example is CVE-2019-10908: a product generated passwords through org.apache.commons.lang.RandomStringUtils, which uses java.util.Random internally. The weakness sat inside a helper that looked harmless.

What an attacker gains

The record lists impact as varying by context. For passwords and tokens, it means predicting values the system trusts.

How to find it

The record lists no specific detection method. Trace the source of randomness behind every generated password or token, including library helpers, and check whether it is a cryptographic generator.

How to fix it

  1. Use well vetted pseudo-random algorithms with adequate length seeds. MITRE gives 256 bits as a good starting point for "random enough" output.
  2. Use modules that conform to FIPS 140-2, or the more recent FIPS 140-3 if possible.
  3. Replace helpers that wrap a weak generator with ones that accept a secure source.
SecureRandom sr = new SecureRandom();
String pw = RandomStringUtils.random(12, 0, 0, true, true, null, sr);

Quick check

Why does a small seed matter if outputs look random?

Because the whole sequence is determined by the seed. Fewer seeds means fewer sequences to test.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.