The .env file contains sensitive information and should NEVER be committed to git:
- API keys (Resend, Brevo)
- Admin secrets
- SMTP passwords
- Private keys
- Added
.envto.gitignore - Removed
.envfrom git history (usinggit rm --cached) - Created
.env.exampleas a template
If your .env file was already pushed to GitHub:
-
Immediately rotate all API keys and secrets:
- Resend API key
- Brevo API key
- Admin secret
- SMTP password
-
Remove from git history:
# Remove .env from all commits
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch .env" \
--prune-empty --tag-name-filter cat -- --all
# Force push (WARNING: This rewrites history!)
git push origin --force --all- Or use BFG Repo-Cleaner (easier):
# Install BFG
brew install bfg # macOS
# or download from https://rtyley.github.io/bfg-repo-cleaner/
# Remove .env from history
bfg --delete-files .env
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push origin --force --allIf your .env was exposed, rotate these immediately:
- Go to: https://resend.com/api-keys
- Delete old key
- Create new key
- Update
.env
- Go to: https://app.brevo.com/settings/keys/api
- Delete old key
- Create new key
- Update
.env
- Generate new random string:
openssl rand -base64 32- Update
.env
- If using Gmail App Password:
- Go to: https://myaccount.google.com/apppasswords
- Revoke old password
- Generate new one
- Update
.env
Always maintain a .env.example file with dummy values:
# .env.example
RESEND_API_KEY=re_your_key_here
BREVO_API_KEY=xkeysib-your_key_here
ADMIN_SECRET=your_secret_here// β BAD
console.log('API Key:', process.env.RESEND_API_KEY);
// β
GOOD
console.log('API Key:', process.env.RESEND_API_KEY ? '***' : 'not set');.env # Local development (gitignored)
.env.example # Template (committed)
.env.production # Production (gitignored, set on server)Never expose secrets in client-side code:
// β BAD - Exposed to browser
const apiKey = import.meta.env.VITE_SECRET_KEY;
// β
GOOD - Server-side only
const apiKey = process.env.SECRET_KEY;For production, set environment variables in your hosting platform:
Vercel:
- Go to Project Settings β Environment Variables
- Add each variable
- Redeploy
Netlify:
- Go to Site Settings β Environment Variables
- Add each variable
- Redeploy
-
Immediately rotate all API keys
-
Check for unauthorized usage:
- Resend: Check email logs
- Brevo: Check campaign logs
- Check for unexpected charges
-
Remove from git history (see above)
-
Monitor for abuse:
- Set up billing alerts
- Check API usage dashboards
- Review access logs
-
Update documentation to prevent future exposure
Before committing:
-
.envis in.gitignore - No secrets in code
-
.env.exampleis up to date - No API keys in commit messages
- No secrets in error messages
If you've exposed secrets and need help:
- Rotate all keys immediately
- Contact support for each service
- Review billing for unauthorized usage
- Clean git history
- Update security practices