A token, password or key is made with the predictable random module
What it finds
token = random.choice(alphabet): the functions of random use a generator whose next outputs can be computed from earlier ones, so tokens, passwords, keys and salts made with it can be guessed (CWE-338). The secrets module draws from the operating system's secure source.
Reported are calls of random functions in a value assigned to a name that contains token, password, secret, nonce, salt or otp.
From the rule's source, insecure_random.rs.
import randomimport secrets def make(): token = "".join(random.choice("abcdef") for _ in range(16))tx0 reports: token is made with random.choice, whose output can be predicted reset_password = random.randint(0, 999999)tx0 reports: reset_password is made with random.randint salt = secrets.token_hex(16) delay = random.random() return token, reset_password, salt, delay 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/python:insecure-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/python:insecure-random] reason="..."tx0 explain tx0/python:insecure-random shows the same in the terminal. Found a false positive? Report it.