Next.js › Environment Variables & Configuration Management
What security risks are associated with environment variables, and how do you avoid them?
AdvancedAnswer
The biggest risk is accidentally exposing a secret to the browser by using the NEXT_PUBLIC prefix on something sensitive, or committing an env file containing real secrets to version control. You avoid this by carefully reviewing which variables are public, adding your env files to .gitignore, and using your hosting platform's secret management for production values.
# .gitignore
.env.local
.env.production.localReal-world example A company accidentally committed a database password to their git repository history, so they rotated the credential immediately and added stricter rules to prevent env files from being tracked in the future.