Skip to main content
CriticalCodeOWASP A07:2021CWE-798

How to fix: Hard-coded password in source

A password, passwd or pwd assignment in the source holds a literal value that looks like a real secret rather than UI copy, a placeholder, a route or a translated label. Keys named admin or root are not treated as credentials: their values are routes, class names and role labels, and default administrator logins are covered by the default-credentials and insecure-auth checks instead.

Why it matters

Hard-coded credentials are trivially extracted from the source file by anyone with read access, including other developers, CI systems, and anyone who decompiles the bundle. They also cannot be rotated without a code change and redeployment.

Credentials in source code become part of version history and distribution artifacts.

How to fix it

  1. 1Move credentials to environment variables
  2. 2Use a secrets manager (AWS Secrets Manager, HashiCorp Vault, Doppler)
  3. 3Rotate any credentials that have appeared in source code immediately

Code examples

Move credentials to environment variables

TypeScript
// BAD: hard-coded credentials in source
// const DB_PASS = "super_secret";

// GOOD: read from environment
const dbPass = process.env.DB_PASSWORD;
if (!dbPass) throw new Error("DB_PASSWORD is required");

// In production: use a secrets manager (AWS Secrets Manager, Vault)
// Never commit .env files, add to .gitignore

References

Detected automatically by VulnRadar. The check id is hardcoded-credentials, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is Hard-coded password in source?
VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id hardcoded-credentials, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Hard-coded password in source map to?
It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for hard-coded password in source

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Hard-coded password in source | VulnRadar