I Audited 50 GitHub Repos — Here Are the 3 Security Mistakes Everyone Makes
After scanning 50+ open-source repos with dotguard, I found the same 3 mistakes over and over again.
Here they are — and how to fix them before your API key leaks.
Mistake #1: Hardcoded API Keys in Source Code
// DON'T do this
const apiKey = "sk-abc123def456ghi789"
const dbPassword = "super_secret_password_123"
This is the #1 cause of security breaches in open-source projects. Someone copies your code, runs it, and suddenly your AWS keys are exposed.
The Fix: Use .env Files
// DO this instead
require('dotenv').config()
const apiKey = process.env.API_KEY
But here's the catch: .env files get committed to git anyway, because nobody adds them to .gitignore.
That's why I built dotguard — it scans your entire project for exposed secrets before they leak.
npm i -g @wuchunjie/dotguard
dotguard
Mistake #2: No .gitignore for Sensitive Files
Most developers ignore node_modules/, .DS_Store, and dist/. But they forget:
# Missing from .gitignore:
.env
.env.local
*.pem
*.key
config/database.yml
The Fix: Add These to .gitignore
.env
.env.*
!/.env.example
*.pem
*.key
*.p12
*.pfx
secrets.json
local-settings.php
Pro tip: Run dotguard before every commit. It catches what .gitignore misses.
Mistake #3: Committing Credentials to Git History
Even after you remove the key from the code, it's still in your git history. Anyone who clones the repo can still find it:
git log -p | grep "api_key"
# Boom. Your key is exposed.
The Fix: Use BFG Repo-Cleaner or git filter-branch
# Install BFG
bfg --replace-text secrets.txt my-repo.git
# Or use git-filter-repo (recommended)
git filter-repo --replace-text secrets.txt
Better approach: Use environment variables from the start. Never commit secrets.
Bonus: How to Scan Your Project Automatically
Add dotguard to your CI/CD pipeline:
# GitHub Actions
- name: Scan for secrets
run: npx @wuchunjie/dotguard --path . --report json > security-report.json
This runs on every PR. If a secret is found, the build fails.
Why This Matters for Open-Source Developers
Your code is public. Your secrets shouldn't be.
I found production database passwords, AWS keys, Slack tokens, and Stripe keys in public repos. Some had been exposed for months before anyone noticed.
Don't be that person.
- Use
.envfiles - Add sensitive files to
.gitignore - Run dotguard before every commit
- Rotate any keys you've ever committed
Deploy Your Project Securely
Once your code is clean and your secrets are safe, deploy it. I use DigitalOcean for my open-source projects — $200 free credit on signup, no credit card needed.
Free tools I use:
- dotguard — Secret scanning for your projects
- gitpulse — Git analytics & health
- snippetx — CLI code snippet manager
- scaffoldx — 12 project templates
☕ Buy me a coffee | ☁️ Get $200 free hosting
Top comments (0)