Skip to main content

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/db.py · PythonReported on line 12
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

app/db.py · Python
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

src/session.ts · TypeScriptReported on line 2
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

src/session.ts · TypeScript
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

  1. 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.
  2. Runs with --danger. Python and TypeScript/JavaScript use different checks.
  3. Python looks for proven secrets, not names. A value is a secret when it comes from os.getenv(), os.environ.get() or os.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), from getpass.getpass(), or from input() whose prompt contains one of those words.
  4. Python follows that value through assignments, f-strings, %, .format(), +, join(), lists, dicts and object fields, and through unknown helper calls: a function named redact() is not trusted.
  5. 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.
  6. Python reports HIGH at a print() call or a standard logging call (logging.info(), or debug, info, warning, error, exception, critical or log on a logging.getLogger() logger) that receives the value. It stays quiet when the value is replaced by a literal on every path, passes through len() or bool(), or when only another field of a container is printed. A parameter merely named password is not a source.
  7. TypeScript and JavaScript check console.log, warn, error, info, debug and trace. For each argument that is a name, a member such as user.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 in sessionId counts only with an authentication context, such as req.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.

app/db.py · Python · the fix, against the flagged file
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, spin or a csrfToken sent 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 --baseline accept the existing findings and report only new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.