A password is hashed with a fast general-purpose hash instead of a password hashing function

tx0/go:password-fast-hashrecommendedwarningsecurity, cwe-916

What it finds

sha256.Sum256([]byte(password)): general-purpose hashes are built to be fast, so someone with a copy of the hashes tries billions of guesses per second, and without a salt one table cracks every account. Passwords are stored with a slow, salted function made for them: bcrypt, scrypt or argon2.

Reported are calls of Sum and Sum256, Sum224, Sum512, Sum384 of crypto/md5, crypto/sha1, crypto/sha256 and crypto/sha512, resolved through the imports, whose argument mentions a variable or field whose name contains password, passwd or pwd, in any case.

From the rule's source, password_fast_hash.rs.

Example from the rule's tests
package p import (	"crypto/sha256"	"crypto/sha1") type user struct{ Password string } func store(u user, password string, data []byte) {	_ = sha256.Sum256([]byte(password))tx0 reports: password is hashed with a fast hash	_ = sha1.Sum([]byte(u.Password))tx0 reports: Password is hashed with a fast hash	_ = sha256.Sum256(data)}
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/go:password-fast-hash" = "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/go:password-fast-hash] reason="..."

tx0 explain tx0/go:password-fast-hash shows the same in the terminal. Found a false positive? Report it.