TL;DR
Add all .env files to .gitignore. Never use NEXT_PUBLIC_ or VITE_ prefix for secrets. Set production variables in your hosting platform, not in files. Use different values for development and production. If a secret is committed, consider it compromised and rotate it. 7 critical items must be fixed before launch, 10 important items within the first week, and 6 recommended items when you can.
Quick Checklist (5 Critical Items)
.gitignore Configuration 4
Client vs Server Variables 3
Production Configuration 4
Secret Hygiene 4
::checklist-item{label="No secrets in code comments" description="Don't leave "old" API keys commented out. How to review code for secrets"} ::
Framework-Specific Checks 4
What To Do If Secrets Are Leaked 4
How to Use This Checklist
Go through each section to ensure your environment variables are properly secured. The most common mistake is using public prefixes for secrets, which exposes them in the browser bundle.
What happens if I accidentally commit a secret?
Consider it compromised immediately. Rotate the secret by generating a new one in the service's dashboard, update your production environment with the new secret, then revoke the old one. Don't waste time trying to remove it from git history.
How do I know if a variable is exposed to the browser?
Check your framework's documentation. In Next.js, NEXT_PUBLIC_ prefixed variables are exposed. In Vite, VITE_ prefixed ones are. In Create React App, REACT_APP_ prefixed ones are. Any variable with these prefixes will be bundled into your client-side code.
Should I use a secrets manager?
For most small to medium projects, your hosting platform's environment variable management is sufficient. Consider dedicated secrets managers like HashiCorp Vault or AWS Secrets Manager when you need advanced features like automatic rotation, audit logging, or cross-service secret sharing.
Scan for Exposed Secrets
Our scanner checks for hardcoded API keys, misconfigured environment variables, and exposed secrets.
Start Free Scan