Data is encrypted with RSA and PKCS #1 v1.5 padding, which leaks the plaintext to padding queries

tx0/go:rsa-pkcs1v15-encryptionstrictwarningsecurity, cwe-780

What it finds

rsa.EncryptPKCS1v15(rand.Reader, pub, msg): the PKCS #1 v1.5 padding for encryption lets anyone who can tell whether a ciphertext decrypts with valid padding recover the plaintext with enough queries, and timing or error messages usually tell. OAEP, with rsa.EncryptOAEP, has no such weakness; signatures with PKCS #1 v1.5 are not affected.

Reported are calls of EncryptPKCS1v15, DecryptPKCS1v15 and DecryptPKCS1v15SessionKey of crypto/rsa, resolved through the imports. Protocols that prescribe the padding still need it, so the rule is strict.

From the rule's source, rsa_pkcs1v15_encryption.rs.

Example from the rule's tests
package p import (	"crypto/rand"	"crypto/rsa"	"crypto/sha256") func seal(pub *rsa.PublicKey, msg []byte) ([]byte, []byte) {	a, _ := rsa.EncryptPKCS1v15(rand.Reader, pub, msg)tx0 reports: rsa.EncryptPKCS1v15 uses the PKCS #1 v1.5 padding	b, _ := rsa.EncryptOAEP(sha256.New(), rand.Reader, pub, msg, nil)	return a, 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:rsa-pkcs1v15-encryption" = "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:rsa-pkcs1v15-encryption] reason="..."

tx0 explain tx0/go:rsa-pkcs1v15-encryption shows the same in the terminal. Found a false positive? Report it.