Rfc2898DeriveBytes is created without a hash algorithm, so it uses SHA-1
What it finds
The constructors of Rfc2898DeriveBytes that take no HashAlgorithmName use HMAC-SHA1, which makes guessing passwords on GPUs cheaper than with SHA-256 or SHA-512. Passing the algorithm, or calling Rfc2898DeriveBytes.Pbkdf2, makes the choice explicit.
From the rule's source, key_derivation_default_hash.rs.
using System.Security.Cryptography; class Passwords{ byte[] Derive(string password, byte[] salt) { var weak = new Rfc2898DeriveBytes(password, salt, 100000);tx0 reports: Rfc2898DeriveBytes uses SHA-1 without an explicit hash algorithm var strong = new Rfc2898DeriveBytes(password, salt, 100000, HashAlgorithmName.SHA256); return strong.GetBytes(32); }} 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:key-derivation-default-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/csharp:key-derivation-default-hash] reason="..."tx0 explain tx0/csharp:key-derivation-default-hash shows the same in the terminal. Found a false positive? Report it.