A password or secret is written in the code as a string literal

tx0/csharp:hardcoded-credentialrecommendedwarningsecurity/secretsdepth fastsecurity, cwe-798

What it finds

A secret in the source is in every copy of the repository and every build, and cannot be changed without a release. Configuration, a secret store or environment variables keep it out. Reported are string literals of at least four characters, without spaces, assigned to or initializing a variable, field, property or named argument whose name says password, secret or API key; values that look like placeholders or names of settings are left alone.

From the rule's source, hardcoded_credential.rs.

Example from the rule's tests
class Settings{    private const string DbPassword = "s3cr3t!x";tx0 reports: DbPassword is set to a secret written in the code    public string ApiKey { get; set; } = "a8f5f167f44f4964e6c998dee827110c";tx0 reports: ApiKey is set to a secret written in the code    private const string PasswordField = "password";     void Connect(Options options)    {        options.Password = "hunter22";tx0 reports: Password is set to a secret written in the code        options.Password = "";        var passwordPrompt = "Enter password";    }} class Options{    public string Password;}
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:hardcoded-credential" = "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:hardcoded-credential] reason="..."

tx0 explain tx0/csharp:hardcoded-credential shows the same in the terminal. Found a false positive? Report it.