Skip to main content

SKY-L014 · Logic and resilience

Hardcoded credential

Varies

The catalog gives no severity. A credential literal is HIGH; a known placeholder value such as changeme, password or secret is MEDIUM.

A password, API key, token or signing secret written as a string in the source: assigned to a variable with a credential name, used as a default argument, or given as the fallback of an environment lookup such as os.environ.get("STRIPE_SECRET_KEY", "..."). It also finds database URLs with a user name and password inside.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Everyone who can read the repository, its forks, its CI logs or a leaked copy holds the key. A fallback is worse than it looks: when the setting is missing in production, the service quietly runs with the key from the source instead of failing at start-up.

What Skylos flags

payments/settings.py · PythonReported on line 5
"""Settings for the payments service.""" import os STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY", "sk_live_51HandbookDemo0nly")CHECKOUT_CACHE_KEY = "checkout:session"

What Skylos leaves alone

payments/settings.py · Python
"""Settings for the payments service.""" import os STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY")CHECKOUT_CACHE_KEY = "checkout:session"

Why Skylos leaves it alone

The secret is read from the environment with no literal fallback. CHECKOUT_CACHE_KEY ends in _KEY, but a plain _KEY name is only reported when its value looks like a random secret, and "checkout:session" does not.

How Skylos decides

  1. Runs with --quality on Python files. Skips test files (test_*.py, *_test.py and conftest.py).
  2. Looks at string literals assigned to a name or attribute, used as a default argument, or given as the fallback of os.environ.get(), os.getenv(), getattr() and similar lookups. Empty strings are ignored.
  3. The name must look like a credential: password, secret, api_key, dsn, database_url and other listed names, or a name ending in _password, _secret, _token, _key, _api_key or _private_key. A literal passed to a credential keyword elsewhere in the file counts as well.
  4. Names that say outright they hold a secret (password, token, secret, auth, session, *_secret_key, *_api_key and similar) are reported whatever the value. A plain *_key name is reported only when the value looks random (letters, digits and symbols with high entropy), is a database URL with user:password@, or starts with $, % or {{.
  5. Skips values that only name a setting, such as APP_URL_KEY = "APP_URL". Reports HIGH, or MEDIUM when the value is a known placeholder such as changeme, on the line of the literal.

How to fix it

Read the secret from the environment or a secrets manager and fail at start-up when it is missing. Then rotate the key that was in the source: removing it from the file does not remove it from Git history.

payments/settings.py · Python · the fix, against the flagged file
"""Settings for the payments service.""" import os Removed: STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY", "sk_live_51HandbookDemo0nly")Added: STRIPE_SECRET_KEY = os.environ["STRIPE_SECRET_KEY"]CHECKOUT_CACHE_KEY = "checkout:session"

When it can be wrong

  • A _KEY constant whose value mixes letters, digits and punctuation, such as CACHE_KEY = "checkout:session:v2", can look random enough to be reported as a credential.
  • database_url, dsn and connection_string count as credential names, so DATABASE_URL = "postgresql://localhost:5432/app" is reported even though it holds no password. Only reference forms such as "${DATABASE_URL}" are accepted under those names.
  • A clearly fake default used only in local development, such as password="changeme", is still reported (as MEDIUM).

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

  • Put the marker on the line of the literal.

    Python
    LOCAL_DB_PASSWORD = "changeme"  # skylos: ignore[SKY-L014] docker-compose only
  • [tool.skylos] ignore = ["SKY-L014"] turns the rule off for the project. Real keys are better caught by the secrets scan (--secrets), which recognises provider formats such as Stripe and AWS keys.

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