SKY-D251 · Security in code
Password or token written to logs
Log lines are copied to files, terminals, CI output and log services that many people can read. SKY-D251 reports a password, token or other secret that reaches print(), Python logging or console.log() and friends.
- Languages
- Python, TypeScript/JavaScript, Rust
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- Sensitive data in logs
Why it matters
A database password in a log file is as good as a published one: anyone with access to the logs, a support dashboard or a CI run page can copy it and log in. Logs are also kept for months and rarely protected like a secrets store.
What Skylos flags
import loggingimport os import psycopg log = logging.getLogger(__name__) def connect(): password = os.environ["DATABASE_PASSWORD"] dsn = f"postgresql://app:{password}@db.internal:5432/app" log.info("connecting with %s", dsn) return psycopg.connect(dsn)What Skylos leaves alone
import loggingimport os import psycopg log = logging.getLogger(__name__) def connect(): password = os.environ["DATABASE_PASSWORD"] host = os.environ.get("DATABASE_HOST", "db.internal") log.info("connecting to %s (password set: %s)", host, bool(password)) return psycopg.connect(host=host, user="app", password=password)Why Skylos leaves it alone
The password is read from the environment and passed to the driver, but only bool(password) reaches the log, which is True or False. DATABASE_HOST is not a secret name, so the host may be logged.
More languages
TypeScript
Flagged
export async function refreshSession(refreshToken: string): Promise<string> { console.log(`refreshing session with ${refreshToken}`); const response = await fetch("/api/session/refresh", { method: "POST", body: JSON.stringify({ refreshToken }), }); const { accessToken } = await response.json(); return accessToken;}Not flagged
export async function refreshSession(refreshToken: string): Promise<string> { console.log(`refreshing session, token length ${refreshToken.length}`); const response = await fetch("/api/session/refresh", { method: "POST", body: JSON.stringify({ refreshToken }), }); const { accessToken } = await response.json(); return accessToken;}Why Skylos leaves it alone
Only the token's length is logged. In TypeScript the rule reads the last name of each logged value, and refreshToken.length ends in length, not in a secret word.
How Skylos decides
- In Rust, Skylos follows an exposed secrecy::SecretString into a recognized log or tracing macro. It checks simple formatted arguments and tracing fields. The wrapped value and its length stay quiet.
- Runs with
--danger. Python and TypeScript/JavaScript use different checks. - Python looks for proven secrets, not names. A value is a secret when it comes from
os.getenv(),os.environ.get()oros.environ[...]with a literal name that contains password, passwd, secret, token, credential(s), api key, private key or access key as a separate word (DATABASE_PASSWORD,GITHUB_TOKEN), fromgetpass.getpass(), or frominput()whose prompt contains one of those words. - Python follows that value through assignments, f-strings,
%,.format(),+,join(), lists, dicts and object fields, and through unknown helper calls: a function namedredact()is not trusted. - Python retains secret sources through slices and concatenation, including fragments that rebuild a whole token. The conventional bounded
text[:n] + "..." + text[-m:]mask remains quiet; a slice alone is not proof of redaction. - Python reports HIGH at a
print()call or a standardloggingcall (logging.info(), ordebug,info,warning,error,exception,criticalorlogon alogging.getLogger()logger) that receives the value. It stays quiet when the value is replaced by a literal on every path, passes throughlen()orbool(), or when only another field of a container is printed. A parameter merely namedpasswordis not a source. - TypeScript and JavaScript check
console.log,warn,error,info,debugandtrace. For each argument that is a name, a member such asuser.password, or a${...}part of a template string, the last name is lower-cased with_removed. HIGH is reported when it ends in password, passwd, pwd, secret, token, apikey, credential(s), authorization, privatekey, accesstoken, refreshtoken, ssn, creditcard, cardnumber, cvv or pin. A name ending insessionIdcounts only with an authentication context, such asreq.cookies.sessionId. One finding per call.
How to fix it
Log what helps debugging without the secret: the host, the user name, or whether a value is set. Pass credentials to the library as separate arguments instead of building a URL that is easy to print.
import loggingimport os import psycopg log = logging.getLogger(__name__) def connect(): password = os.environ["DATABASE_PASSWORD"]Removed: dsn = f"postgresql://app:{password}@db.internal:5432/app"Removed: log.info("connecting with %s", dsn)Removed: return psycopg.connect(dsn)Added: log.info("connecting to db.internal:5432 as app")Added: return psycopg.connect(Added: host="db.internal", port=5432, user="app", password=passwordAdded: )When it can be wrong
- Python: an environment variable whose name contains a secret word but holds a file path, such as
GOOGLE_APPLICATION_CREDENTIALS, is reported when printed. - TypeScript: names that end in a listed word but hold nothing secret are reported, such as
mapPin,spinor acsrfTokensent to the page anyway. - Missed: in Python, secrets from other places (a config file, a vault client, a request) and other loggers such as loguru or structlog. In TypeScript, string concatenation (
"t=" + token), object arguments ({ password }) and loggers such as pino or winston.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark the reported line and say why the output is safe.
Python print(creds_path) # skylos: ignore[SKY-D251] file path, not the key[tool.skylos] ignore = ["SKY-D251"]turns the rule off for the whole project.skylos baseline .and then--baselineaccept the existing findings and report only new ones.