env.dev

Environment Variables Security: Secrets, Leaks & Best Practices

Why environment variables are not truly secure and what to do about it. Covers secret rotation, leak detection, client-side exposure risks, and when to use a dedicated secrets manager.

Last updated:

Loading…

Frequently Asked Questions

Are environment variables secure?

Not inherently. Environment variables are visible in process listings (/proc/PID/environ on Linux), crash dumps, logs, and child processes. They are better than hardcoding secrets in source code but worse than a dedicated secrets manager.

What should I do if a secret is leaked?

Immediately rotate the compromised credential (generate a new key, revoke the old one). Audit access logs to determine if the secret was used maliciously. Update all deployments with the new credential. Investigate how the leak occurred and fix the root cause.

What is the NEXT_PUBLIC_ / REACT_APP_ / VITE_ exposure risk?

Variables with these prefixes are embedded into client-side JavaScript bundles at build time. They are visible to anyone inspecting your site. Never put API keys, database URLs, or any secret in a client-side exposed variable.

Was this helpful?

Stay up to date

Get notified about new guides, tools, and cheatsheets.