.env files are listed in .gitignore
Why it matters
A .env file committed to git is a permanent credential leak — even after deletion, the file lives in git history and is readable to anyone with repository access, including all future contributors, CI/CD systems, and anyone who ever clones the repo. Stripe keys, database passwords, and OAuth secrets committed to a private repo are exposed the moment the repo is accidentally made public or an employee account is compromised. OWASP A02 (Cryptographic Failures) covers secret exposure; CWE-540 and CWE-538 specifically address sensitive information in committed files. AI code generators routinely create .env.local files and forget to update .gitignore, making this one of the highest-frequency findings across AI-built projects.
Severity rationale
High because secrets committed to git history are irrecoverable without rotation — a single accidental public repo exposure or account compromise exposes all credentials permanently.
Remediation
Add .env patterns to .gitignore before committing any environment files. If .env files are already tracked, remove them from git's index immediately.
# .gitignore — add all of these
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.env*.local
If secrets were already committed: git rm --cached .env.local, then commit the removal, then rotate every secret in that file immediately — treat them as compromised. Only .env.example with placeholder values should ever be committed.
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 Security Headers & Basics Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-540 — Inclusion of Sensitive Information in Source Code
- cwe · CWE-538 — Insertion of Sensitive Information into Externally-Accessible File or Directory
- owasp:2021 · A02 — Cryptographic Failures
- soc2:2017 · C1.1 — Identification and protection of confidential information
Taxons
History
- 2026-04-17·v1.0.0·Initial import from security-headers·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (C1.1) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2