Env Fallback Secret

Secret env vars with hardcoded fallback values

criticalSecurityenv-fallback-secret

Severity depends on context. Critical for well-known secret names (JWT_SECRET, SESSION_SECRET, NEXTAUTH_SECRET, ENCRYPTION_KEY and similar). Warning for other variables named like a key, token or password, and for database URLs with a hardcoded fallback.

Why this matters

A hardcoded fallback means the app runs with a known secret when the env var is missing. In production, this is a backdoor. Locally, it hides misconfiguration.

Example

Flaggedlib/auth.ts
const jwtSecret = process.env.JWT_SECRET || "dev-secret-change-me";

export function sign(payload: object) {
  return jwt.sign(payload, jwtSecret, { expiresIn: "1h" });
}
Fixedlib/auth.ts
const jwtSecret = process.env.JWT_SECRET;
if (!jwtSecret) throw new Error("JWT_SECRET is required");

export function sign(payload: object) {
  return jwt.sign(payload, jwtSecret, { expiresIn: "1h" });
}

How to fix

Never provide fallback values for secrets. Fail fast with a clear error message if a required env var is missing.

Reference

In the output
Findings carry "ruleId": "env-fallback-secret" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line env-fallback-secret
Silence a whole file
// prodlint-disable env-fallback-secret at the top of the file
How it works
Matches text patterns. Source on GitHub