- NEVER put API keys directly in code
- NEVER put API keys in documentation files
- NEVER commit
.envfiles to git
- Copy
.env.exampleto.env - Fill in your actual API keys in
.env - The
.envfile is gitignored and won't be committed
- Go to your hosting dashboard
- Add environment variables in the UI
- Never hardcode them in your code
β DO:
- Use
.envfiles locally - Add secrets via hosting platform UI
- Use
.env.exampleas a template (without real values) - Rotate keys regularly
- Use different keys for dev/staging/production
β DON'T:
- Commit
.envfiles - Put keys in documentation
- Share keys in chat/email
- Use the same key across environments
- Hardcode keys in source code
-
Revoke the key immediately
- Google Gemini: https://aistudio.google.com/app/apikey
-
Generate a new key
-
Update your environment variables
- Locally: Update
.env - Render: Dashboard β Environment β Update variable
- Vercel: Dashboard β Settings β Environment Variables
- Locally: Update
-
Remove from git history (if committed)
# Option 1: Use BFG Repo-Cleaner java -jar bfg.jar --replace-text passwords.txt # Option 2: Use git filter-repo pip install git-filter-repo git filter-repo --replace-text passwords.txt
-
Close GitHub security alert once key is revoked
- Use strong passwords
- Never commit database credentials
- Use environment variables for connection strings
- Use strong JWT secrets
- Rotate secrets periodically
- Never log sensitive data
- Configure allowed origins properly
- Don't use
*in production
- Validate file types
- Limit file sizes
- Scan for malware if possible
- All API keys in environment variables
-
.envfiles gitignored - No hardcoded secrets in code
- Strong SECRET_KEY and JWT_SECRET_KEY
- CORS properly configured
- Database credentials secure
- HTTPS enabled in production
- Error messages don't leak sensitive info
Run these checks periodically:
# Check for accidentally committed secrets
git log -p | grep -i "api_key\|secret\|password"
# Scan for exposed secrets (install gitleaks)
gitleaks detect --source . --verbose
# Check dependencies for vulnerabilities
pip-audit # Python
npm audit # Node.jsIf you find a security vulnerability, please:
- Don't open a public issue
- Contact the maintainer directly
- Provide details about the vulnerability
- Allow time for a fix before public disclosure
Remember: Security is everyone's responsibility. When in doubt, ask!