A password is hashed with a salt written in the source

tx0/python:constant-saltrecommendedwarningsecurity, cwe-760

What it finds

A salt makes the same password hash differently for every user, so that one table of precomputed hashes cannot crack them all. A salt written in the code is the same for everyone and gives no such protection. Reported are string and bytes literals given as the salt of hashlib.pbkdf2_hmac, hashlib.scrypt and bcrypt.hashpw.

From the rule's source, constant_salt.rs.

Example from the rule's tests
import hashlibimport os a = hashlib.pbkdf2_hmac("sha256", password, b"static", 100000)tx0 reports: this salt is written in the sourceb = hashlib.scrypt(password, salt=b"pepper", n=2, r=8, p=1)tx0 reports: this salt is written in the sourcec = hashlib.pbkdf2_hmac("sha256", password, os.urandom(16), 100000)
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/python: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/python:constant-salt] reason="..."

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