A token, password or key is made with a predictable random source
What it finds
$token = md5(uniqid()) or $password = rand(1000, 9999): rand, mt_rand, uniqid, lcg_value and str_shuffle are predictable, so tokens, passwords, salts and keys made from them can be guessed. random_bytes and random_int are made for secrets. A value counts as a secret when the variable, property, key or function it goes to is named like one.
From the rule's source, predictable_secret.rs.
<?phpfunction tokens($user){ $token = md5(uniqid());tx0 reports: $token is made with uniqid, which is predictable $user->password = rand(100000, 999999);tx0 reports: password is made with rand, which is predictable $row = ['csrf_token' => mt_rand()];tx0 reports: csrf_token is made with mt_rand, which is predictable $id = uniqid(); $safe = bin2hex(random_bytes(16)); return [$token, $row, $id, $safe];} 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/php:predictable-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/php:predictable-secret] reason="..."tx0 explain tx0/php:predictable-secret shows the same in the terminal. Found a false positive? Report it.