A password or secret key is written in the source
What it finds
password = "hunter2": a password or secret key written in the source is known to everyone who can read the repository, its history and every copy of it, and changing it means changing the code (CWE-798). Read it from the environment or a secret store.
Reported are string literals assigned to a variable or attribute, passed as a keyword argument or given as the value of a dict key, whose name ends in password, passwd, secret_key, api_key, private_key or access_token. Values that look like placeholders or field names are left alone: passwords shorter than eight characters or without a digit, keys and tokens shorter than sixteen characters or with fewer than two digits, values with spaces, braces, $ or %, values made of one repeated character, and values that repeat the name.
From the rule's source, hardcoded_password.rs.
import psycopg2 password = "s3cr3t-Value"tx0 reports: password is given a literal valueDB_PASSWORD = ""API_KEY = "<your key here>"settings = {"secret_key": "a8f5f167f44f4964e6c998dee827110c"}tx0 reports: secret_key is given a literal value def connect(user_password): conn = psycopg2.connect(host="db", password="Tr0ub4dor")tx0 reports: password is given a literal value conn.password = user_password return conn, psycopg2.connect(password="password") 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/python:hardcoded-password" = "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/python:hardcoded-password] reason="..."tx0 explain tx0/python:hardcoded-password shows the same in the terminal. Found a false positive? Report it.