No hardcoded secrets in source code
Why it matters
Hardcoded secrets in source code violate CWE-798 (Use of Hard-coded Credentials) and OWASP A07 (Identification & Authentication Failures), and they are permanent: unlike a leaked .env file, a credential baked into a function call survives every deployment, every refactor, and every repo clone. A Stripe live key or database password embedded in a TypeScript file is readable by every developer, CI runner, contractor, and open-source contributor who touches the repo. NIST IA-5 requires credential management controls — hardcoded values have no rotation path, no access control, and no audit trail.
Severity rationale
Critical because hardcoded credentials are unrevokable without a code change and are visible to everyone with repository access, making targeted rotation impossible.
Remediation
Move every secret out of source files and into environment variables. Validate presence at startup so missing config fails fast rather than failing silently mid-request.
// src/config/secrets.ts
// BEFORE (wrong)
export const STRIPE_KEY = 'sk_live_51234...'
// AFTER (correct)
export const STRIPE_KEY = process.env.STRIPE_SECRET_KEY
if (!STRIPE_KEY) throw new Error('STRIPE_SECRET_KEY not set')
For each secret removed from source code, generate a new credential in the service dashboard (the old one is compromised), store it in your secrets manager or CI environment, and delete it from git history with git filter-repo.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Environment Security Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-798 — Use of Hard-coded Credentials
- cwe · CWE-259 — Use of Hard-coded Password
- owasp:2021 · A07 — Identification and Authentication Failures
- nist:rev5 · IA-5 — Authenticator Management
- pci-dss:4.0 · Req 3.4 — Primary Account Number protection
- soc2:2017 · CC6.1 — Logical access security software, infrastructure, and architectures
- soc2:2017 · C1.1 — Identification and protection of confidential information
Taxons
History
- 2026-04-18·v1.0.0·Initial import from environment-security·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC6.1, C1.1) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2