A password, secret or token is written into the source as a string literal

tx0/go:hardcoded-credentialstrictwarningsecurity, cwe-798

What it finds

password := "hunter2" or Config{APIKey: "sk-..."}: a credential in the source is readable by everyone who can read the repository, its history and the built binary, and changing it needs a new release. Credentials belong in the environment, a file outside the repository or a secret store.

Reported are string literals of at least six characters that mix letters and digits, without spaces, assigned to a variable, constant or field, or given for a key of a composite literal, whose name contains password, passwd, secret, apikey, accesskey, privatekey or token, in any case and ignoring underscores. Values that look like placeholders, names of environment variables, paths, URLs without credentials or format strings are left out. Tests and examples often hold fake credentials, so the rule is strict.

From the rule's source, hardcoded_credential.rs.

Example from the rule's tests
package p type config struct {	APIKey   string	Password string} const dbPassword = "s3cr3tP4ss"tx0 reports: dbPassword is given a credential written into the source func f(c *config) config {	c.APIKey = "AKia4XK2pq7Z"tx0 reports: APIKey is given a credential written into the source	token := "ghp_9fK2mQ7xL0aZ"tx0 reports: token is given a credential written into the source	passwordEnv := "DB_PASSWORD"	tokenFile := "/var/run/token"	_, _, _ = token, passwordEnv, tokenFile	return config{		APIKey:   "Zx9-Q7vB2mK4",tx0 reports: APIKey is given a credential written into the source		Password: "changeme",	}}
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: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/go:hardcoded-credential] reason="..."

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