A password is hashed with a salt written in the code

tx0/java:constant-saltrecommendedwarningsecurity, cwe-760

What it finds

A salt makes the hashes of equal passwords differ, so that one precomputed table does not crack them all. A salt written in the source is the same for every password and every installation, which gives that protection up (CWE-760). It should come from a SecureRandom and be stored with the hash.

Reported is a PBEKeySpec or PBEParameterSpec whose salt is a string literal turned into bytes, an array written in the code, or a variable initialized with one of these.

From the rule's source, constant_salt.rs.

Example from the rule's tests
import javax.crypto.spec.PBEKeySpec;import javax.crypto.spec.PBEParameterSpec; class Keys {  void derive(char[] password, byte[] random) {    PBEKeySpec a = new PBEKeySpec(password, "salt".getBytes(), 1000, 256);tx0 reports: written in the code    byte[] fixed = {1, 2, 3, 4};    PBEParameterSpec b = new PBEParameterSpec(fixed, 1000);tx0 reports: written in the code    PBEKeySpec c = new PBEKeySpec(password, random, 1000, 256);  }}
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/java:constant-salt" = "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/java:constant-salt] reason="..."

tx0 explain tx0/java:constant-salt shows the same in the terminal. Found a false positive? Report it.