SKY-L014 · Logic and resilience
Hardcoded credential
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
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
"""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
"""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
- Runs with
--qualityon Python files. Skips test files (test_*.py,*_test.pyandconftest.py). - 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. - The name must look like a credential:
password,secret,api_key,dsn,database_urland other listed names, or a name ending in_password,_secret,_token,_key,_api_keyor_private_key. A literal passed to a credential keyword elsewhere in the file counts as well. - Names that say outright they hold a secret (password, token, secret, auth, session,
*_secret_key,*_api_keyand similar) are reported whatever the value. A plain*_keyname is reported only when the value looks random (letters, digits and symbols with high entropy), is a database URL withuser:password@, or starts with$,%or{{. - 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 aschangeme, 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.
"""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
_KEYconstant whose value mixes letters, digits and punctuation, such asCACHE_KEY = "checkout:session:v2", can look random enough to be reported as a credential. database_url,dsnandconnection_stringcount as credential names, soDATABASE_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.