Data is encrypted with a mode that does not detect changes to the ciphertext

tx0/go:unauthenticated-cipher-modestrictwarningsecurity/cryptodepth fastsecurity, cwe-353

What it finds

cipher.NewCBCEncrypter(block, iv): CBC, CFB, OFB and CTR hide the content but do not detect changes to it, so an attacker can flip bits of the plaintext, and with CBC often decrypt it through padding errors. An authenticated mode such as GCM, or a MAC over the ciphertext, makes changes detectable.

Reported are calls of NewCBCEncrypter, NewCBCDecrypter, NewCFBEncrypter, NewCFBDecrypter, NewOFB and NewCTR of crypto/cipher in a file that does not import crypto/hmac.

From the rule's source, unauthenticated_cipher_mode.rs.

Example from the rule's tests
package p import (	"crypto/aes"	"crypto/cipher") func encrypt(key, iv, dst, src []byte) {	block, _ := aes.NewCipher(key)	cipher.NewCBCEncrypter(block, iv).CryptBlocks(dst, src)tx0 reports: CBC does not detect changes to the ciphertext}
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:unauthenticated-cipher-mode" = "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:unauthenticated-cipher-mode] reason="..."

tx0 explain tx0/go:unauthenticated-cipher-mode shows the same in the terminal. Found a false positive? Report it.