ESP API credentials stored in environment variables
Why it matters
A hardcoded SendGrid or Mailgun API key in a committed source file is a credential that any engineer with repository read access — and any attacker who gains access to the repo, a build artifact, or a public GitHub fork — can use immediately to send email at your expense, under your sending domain, to any recipient list. This maps to OWASP A02 (Cryptographic Failures) and CWE-798 (Use of Hard-coded Credentials). The damage is not theoretical: repositories are leaked, build logs are captured, and Docker image layers are extracted. Committing credentials is an irreversible exposure until the key is rotated.
Severity rationale
Critical because a committed API key grants immediate unauthorized send access to the account and cannot be made safe after the fact without key rotation.
Remediation
Load all ESP credentials via process.env and fail loudly at startup if the variable is absent, in lib/esp-client.ts:
const apiKey = process.env.SENDGRID_API_KEY
if (!apiKey) {
throw new Error('SENDGRID_API_KEY environment variable is required')
}
sgMail.setApiKey(apiKey)
Audit .env.example to confirm it contains only placeholder values like your-key-here. Rotate any key that has ever appeared in a committed file, even in a branch that was never merged.
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 Sending Pipeline & Infrastructure 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-312 — Cleartext Storage of Sensitive Information
- owasp:2021 · A02 — Cryptographic Failures
Taxons
History
- 2026-04-18·v1.0.0·Initial import from sending-pipeline-infrastructure·automated