Hardcoded credentials (CWE-798): secrets belong in env vars or a secret manager, never in source
An API key, password, or private key written as a literal in source code is compromised the moment it is committed — git history keeps it even after you delete the line. Read secrets from the environment or a secret manager; rotate anything that was ever hardcoded.
Hardcoded credentials (CWE-798)
A secret written as a string literal — an API key, a database password, a signing key, a private-key PEM block — is exposed to everyone with read access to the repository, forever, because git keeps every past commit. Deleting the line in a new commit does not remove it from history; the key must be treated as burned and rotated.
The rule
Secrets are configuration, not code: read them from the environment, a mounted secret file, or a secret manager (AWS Secrets Manager, Vault, Doppler, 1Password, …) — never as a literal.
// BAD — CWE-798: committed, logged in shell history, visible in git blame forever
const apiKey = 'sk-live-aBcDeFgH1234567890';
const dbPassword = 'tr0ub4dor&3xyz';
// GOOD — read at runtime, never printed, never committed
const apiKey = process.env.STRIPE_SECRET_KEY;
const dbPassword = process.env.DB_PASSWORD;
if (!apiKey) throw new Error('STRIPE_SECRET_KEY is not set');
# BAD
AWS_SECRET = "AKIAIOSFODNN7EXAMPLE"
# GOOD
import os
AWS_SECRET = os.environ["AWS_SECRET_ACCESS_KEY"]
Private keys
A -----BEGIN PRIVATE KEY----- block in source is the same problem with higher stakes (it can impersonate a
service, decrypt traffic, or sign tokens). Load it from a file path given by an env var, or from a secret manager —
never paste the key material into a .ts/.py/.env.example file.
.env files
.env holds real secrets and must never be committed — keep it in .gitignore, and commit .env.example with
placeholder values (STRIPE_SECRET_KEY=sk-...) instead. If a secret is already committed, rotating it is the only
real fix; rewriting git history helps hygiene but does not un-expose a key that may already be scraped/cached.
What codexguild_scan_security checks
Three rules: a literal matching the AWS access-key shape (AKIA...), a PEM private-key header, and a generic
key|secret|password|token = "literal" assignment where the literal isn't a placeholder, an env-var reference, or
too short to be a real secret. False positives look like password: 'CHANGE_ME' or apiKey: process.env.X — both
are explicitly excluded by the pattern, so a hit is usually real.