MD5 or SHA-1 is used, whose collisions can be produced at will

tx0/go:weak-hashstrictwarningsecurity, cwe-328

What it finds

md5.Sum(data) or sha1.New(): both hashes are broken for collision resistance, so anything that relies on two inputs never sharing a hash, such as a signature, a certificate fingerprint, an integrity check of downloaded data or a password hash, can be fooled. SHA-256 from crypto/sha256 is as easy to use; passwords need a slow, salted function such as bcrypt, scrypt or argon2.

Calls of New and Sum of crypto/md5 and of New and Sum of crypto/sha1 are reported, resolved through the imports. Many uses are not about security at all, such as cache keys, checksums that a protocol prescribes or content addressing, so the rule is strict.

From the rule's source, weak_hash.rs.

Example from the rule's tests
package p import (	"crypto/md5"	"crypto/sha1"	"crypto/sha256") func f(data []byte) []byte {	a := md5.Sum(data)tx0 reports: MD5 is broken for collisions	h := sha1.New()tx0 reports: SHA-1 is broken for collisions	h.Write(data)	b := sha256.Sum256(data)	return append(append(a[:], h.Sum(nil)...), b[:]...)}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:weak-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:weak-hash] reason="..."

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