All articles
Security Fundamentals8 min readJanuary 22, 2026
SecretsAPI KeysGitHubEnvironment Variables

Hardcoded API Keys: The #1 Security Mistake in Vibe Coding

AI tools frequently embed credentials in code. Learn how to find exposed secrets and prevent API key leaks before they reach GitHub.

Security Guide

The Secret Epidemic in AI-Generated Code

Every day, thousands of API keys, database passwords, and authentication tokens are accidentally pushed to GitHub. AI coding tools make this problem dramatically worse.

The Numbers Are Staggering

GitHub's 2025 Secret Scanning Report:

  • 12.8 million secrets detected in public repositories
  • 40% increase from 2024
  • AI-assisted repositories 3x more likely to contain exposed secrets

Why AI Tools Expose Secrets

1. Training Data Contains Real Secrets

AI models learn from code that includes:

  • Tutorial projects with placeholder credentials
  • Accidentally committed .env files
  • Code samples with real API keys

2. AI Generates "Realistic" Placeholders

javascript
// AI tries to be helpful with realistic-looking keys
const STRIPE_KEY = 'sk_live_51ABC123...'
const OPENAI_KEY = 'sk-proj-abc123...'

These look real because AI learned from real keys.

3. Vibe Coders Move Fast

The vibe coding workflow emphasizes speed:

  1. Prompt AI for feature
  2. Copy generated code
  3. Test it works
  4. Commit and push
Step 4 often happens before removing hardcoded values.

What Secrets Look Like

Stripe Keys

sk_live_51[A-Za-z0-9]{24,}
sk_test_51[A-Za-z0-9]{24,}

OpenAI Keys

sk-[A-Za-z0-9]{48}
sk-proj-[A-Za-z0-9]{48}

AWS Credentials

AKIA[0-9A-Z]{16}

GitHub Tokens

ghp_[A-Za-z0-9]{36}
github_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59}

Database Connection Strings

postgres://user:password@host:5432/db
mongodb+srv://user:password@cluster.mongodb.net

Real Consequences

Case 1: Indie hacker's Stripe test key was in code. Bot found it, made $3,400 in fraudulent charges to his account.

Case 2: Startup's AWS keys exposed. Crypto miners spun up $47,000 in EC2 instances overnight.

Case 3: Database credentials in GitHub. Entire user table exfiltrated, company faced GDPR fines.

How to Find Secrets in Your Code

Manual Search

bash
# Search for common patterns
grep -rn "sk_live\
sk_test\AKIA\ghp_\
password.*=" --include="*.ts" --include="*.js" src/

Git History Search

Secrets might be in old commits even if removed from current code:

bash
git log -p 
grep -i "api_key\secret\
password"

Automated Scanning

Tools like ShipReady scan for 100+ secret patterns automatically.

The Fix: Environment Variables

Step 1: Create .env File

bash
# .env (never commit this)
STRIPE_SECRET_KEY=sk_live_actual_key_here
DATABASE_URL=postgres://user:pass@host:5432/db
OPENAI_API_KEY=sk-actual_key_here

Step 2: Add to .gitignore

bash
# .gitignore
.env
.env.local
.env.*.local

Step 3: Access in Code

javascript
const stripeKey = process.env.STRIPE_SECRET_KEY
const dbUrl = process.env.DATABASE_URL

Step 4: Use Platform Secrets

  • Vercel: Settings → Environment Variables
  • Railway: Variables tab
  • Render: Environment section
  • GitHub Actions: Settings → Secrets

What If You Already Exposed a Secret?

Immediate Actions

  1. Revoke the credential immediately
- Don't just remove from code—the secret is in git history - Generate a new key/password

  1. Check for unauthorized usage
- Review API logs - Check billing statements - Monitor for unusual activity

  1. Clean git history (optional)
bash
git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch path/to/file" \
  --prune-empty --tag-name-filter cat -- --all

Prevention Going Forward

  1. Pre-commit hooks - Block commits containing secret patterns
  2. CI/CD scanning - Fail builds with exposed secrets
  3. Automated alerts - Get notified of new exposures

Environment Variable Checklist

Before every commit:

[ ] No API keys in source files
[ ] No passwords in source files
[ ] No connection strings with credentials
[ ] .env is in .gitignore
[ ] Secrets set in deployment platform
[ ] Old secrets rotated

The Bottom Line

Hardcoded secrets are the easiest vulnerability to exploit and the easiest to prevent. AI tools make them more common, but environment variables make them avoidable.

Never commit secrets. Use environment variables. Scan before you push.

Ready to secure your AI-generated code?

Stop reading about vulnerabilities. Start fixing them.

Start Scanning Free