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

tx0/java:hardcoded-credentialrecommendedwarningsecurity, cwe-798

What it finds

String password = "hunter2"; puts a credential into the source, where everyone who can read the code or the compiled class can read it, and where it cannot be changed without a new release.

Reported are string literals stored in a variable or field named after a password, passphrase or secret (the words password, passwd, pwd, passphrase, secret), and literals passed as the password of DriverManager.getConnection, setPassword or PasswordAuthentication. Names that also say they hold a key, id, field, property, label, prompt, pattern and the like are left alone: such constants usually hold the name of a setting, not its value. So are values that cannot be a credential: empty or very short strings, values with spaces, placeholders such as ${db.password} or <password>, markers such as dummy, changeme or redacted, addresses and paths, and values that only repeat the name, such as the key "password" or "db.password".

From the rule's source, hardcoded_credential.rs.

Example from the rule's tests
import java.sql.Connection;import java.sql.DriverManager; class Db {  private static final String PASSWORD_KEY = "db.password";  private String password = "hunter2x";tx0 reports: password is written in the source  private String dbCredentials = "jdbc:admin";  private String adminPassword = "changeme123";  private String passwordPrompt = "Enter password:";  private String secret = "";   Connection open(String url) throws Exception {    return DriverManager.getConnection(url, "admin", "s3cr3t!");tx0 reports: the password of getConnection is written  }}
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/java: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/java:hardcoded-credential] reason="..."

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