Technical Guide

API Keys on GitHub: ChatGPT Secrets Leak

An .env commit exposed credentials; we purged history, rotated keys, and secured CI rules.

January 15, 2025 5 min read

The problem

A developer accidentally committed the production .env file containing API keys for Stripe, AWS, SendGrid, and database credentials. The file sat in the public repository for 3 weeks before discovery. Automated bot scanners had already harvested the credentials, leading to $12,000 in AWS charges from crypto mining instances and customer data exposure.

How AI created this issue

ChatGPT suggested creating a .env file for configuration but never mentioned adding it to .gitignore. The example it provided looked legitimate:

# ChatGPT's incomplete advice
"Create a .env file with your credentials:
DATABASE_URL=postgresql://user:pass@localhost/db
STRIPE_KEY=sk_live_actualKeyHere
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE"

# But forgot to mention: "Add .env to .gitignore!"

The AI's instructions worked perfectly in development but created a ticking time bomb for production security.

The solution

  1. Immediately rotated all exposed credentials across every service
  2. Used git filter-branch to completely remove .env from Git history
  3. Implemented HashiCorp Vault for centralized secret management
  4. Created .env.example with dummy values for developer onboarding
  5. Set up GitGuardian for real-time secret scanning on all repositories
  6. Configured CI/CD to pull secrets from Vault, never from files
  7. Added pre-commit hooks that block commits containing potential secrets

The results

Zero credential exposures in 18 months since implementation. GitGuardian has blocked 47 attempted secret commits. AWS implemented a security credit for the mining charges after reviewing our remediation. The entire team completed security training, and our SOC 2 audit specifically praised our secret management infrastructure. Deploy times improved by 30% with centralized secret injection.

Ready to fix your codebase?

Let us analyze your application and resolve these issues before they impact your users.

Get Diagnostic Assessment →