Environment Variables Security Checklist: 23-Item Guide

TL;DR

Add every .env file to .gitignore, and never put a secret behind a NEXT_PUBLIC_ or VITE_ prefix. Production values belong in your hosting platform's settings, not in a file you deploy. Keep development and production on different keys. If a secret was ever committed, it's compromised: rotate it. 7 critical items must be fixed before launch, 10 important items within the first week, and 6 recommended items when you can.

Env vars look simple. They're also one of the most common sources of security incidents. One wrong prefix and your secret key ships to the browser, sitting in a bundle anyone can download. Miss a single gitignore entry and your credentials are on GitHub for the world to see. This checklist catches the mistakes that trip up experienced developers too.

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

Work through each section in order. The mistake that shows up most often is a public prefix on something that should have been server-only, which quietly puts the value in your browser bundle where anyone can read it.

What happens if I accidentally commit a secret?

Consider it compromised, right away. Rotate it: generate 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 scrub it from git history.

How do I know if a variable is exposed to the browser?

Check your framework's documentation, though the pattern is the same everywhere. A prefix marks a variable as public. Next.js uses NEXT_PUBLIC_, Vite uses VITE_, and Create React App uses REACT_APP_. Anything carrying one of those prefixes gets 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.

Security Checklists

Environment Variables Security Checklist: 23-Item Guide