A password or secret key is written into the source as a literal
What it finds
$password = 'hunter2', define('DB_PASSWORD', 's3cret'), 'api_key' => 'sk_...': a password or key written in the source is readable by everyone who can read the code or its history, and changing it means changing the code. Read it from the environment or a secrets store. Placeholders such as empty strings, 'changeme', values with spaces and values that are names of other things, such as 'FTP_PASS', and test code, are left alone.
From the rule's source, hardcoded_credential.rs.
<?phpdefine('DB_PASSWORD', 'Xk9!p2Lq');tx0 reports: DB_PASSWORD is set to a literal secret$config = [ 'api_key' => 'sk_live_51Hx',tx0 reports: api_key is set to a literal secret 'password' => '', 'password_field' => 'pass',];$password = getenv('APP_PASSWORD');$db_password = 'hunter22';tx0 reports: db_password is set to a literal secret$secret = 'changeme'; 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/php: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/php:hardcoded-credential] reason="..."tx0 explain tx0/php:hardcoded-credential shows the same in the terminal. Found a false positive? Report it.