A cryptographic key is made from a string literal in the code
What it finds
A key written in the source is in every copy of the program and its history, and cannot be rotated without a release. Keys belong in a secret store or configuration. The rule reports the bytes of a string literal assigned to a Key property or passed to SymmetricSecurityKey or an HMAC... constructor.
From the rule's source, literal_crypto_key.rs.
using System.Security.Cryptography;using System.Text; class Signer{ byte[] Sign(byte[] data, byte[] key) { using var mac = new HMACSHA256(Encoding.UTF8.GetBytes("super-secret-key"));tx0 reports: the key is made from a literal in the code using var good = new HMACSHA256(key); return mac.ComputeHash(data); }} 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:
[rules]
"tx0/csharp:literal-crypto-key" = "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/csharp:literal-crypto-key] reason="..."tx0 explain tx0/csharp:literal-crypto-key shows the same in the terminal. Found a false positive? Report it.