A key is derived from a password with fewer than 10,000 iterations

tx0/csharp:few-key-iterationsrecommendedwarningsecurity/cryptodepth fastsecurity, cwe-916

What it finds

PBKDF2 slows down guessing by repeating its hash; with a few thousand rounds, a leaked hash can be brute-forced on ordinary hardware. Current guidance asks for hundreds of thousands of rounds of SHA-256. Reported are literal iteration counts below 10,000 passed to new Rfc2898DeriveBytes and Rfc2898DeriveBytes.Pbkdf2, and constructors of Rfc2898DeriveBytes without a count, which use 1,000.

From the rule's source, few_key_iterations.rs.

Example from the rule's tests
using System.Security.Cryptography; class Keys{    byte[] Derive(string password, byte[] salt)    {        var a = new Rfc2898DeriveBytes(password, salt, 1000);tx0 reports: 1000 iterations are too few to slow down guessing        var b = new Rfc2898DeriveBytes(password, salt);tx0 reports: without a count, 1000 iterations are used, too few to slow down guessing        var c = new Rfc2898DeriveBytes(password, salt, 600000, HashAlgorithmName.SHA256);        return c.GetBytes(32);    }}
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:few-key-iterations" = "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:few-key-iterations] reason="..."

tx0 explain tx0/csharp:few-key-iterations shows the same in the terminal. Found a false positive? Report it.