A password, API key or other secret is written into the source as a literal
What it finds
A password, API key or client secret written into the source is known to everyone who can read the repository, its history or a build, and changing it means changing code. Configuration or a secret store keeps it out.
A finding needs both a name and a value. The name of the variable, property or field that receives the literal, or that it is compared with, must end in a word for a secret: password, passwd, passphrase, secret, apiKey, accessKey, privateKey, clientSecret or authToken, in any case style, so that dbPassword counts and passwordLabel does not. The value must look like a secret: at least six characters, no spaces, digits or symbols mixed in, and not a placeholder such as changeme or <password>, an interpolation, the name of an environment variable or a dotted configuration key.
From the rule's source, hardcoded_credential.rs.
export const dbPassword = "s3cr3t-Pa55";tx0 reports: looks like a secretexport const config = { apiKey: "AKIA4F7X9Q2LMN8B",tx0 reports: looks like a secret passwordLabel: "Password", clientSecret: "", secretName: "prod-db", password: process.env.DB_PASSWORD, ACCESS_KEY: "sandbox.allowDevToolAccess",};export function login(user: { password: string }) { if (user.password === "hunter2!") {tx0 reports: looks like a secret return true; } const authToken = "${TOKEN}"; const placeholder = { password: "your-password-here" }; const env = { password: "DB_PASSWORD" }; return [authToken, placeholder, env];} 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/ts: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/ts:hardcoded-credential] reason="..."tx0 explain tx0/ts:hardcoded-credential shows the same in the terminal. Found a false positive? Report it.