Is my .env file public? How to check and fix it
The 10-second check
Open https://yoursite.com/.env in a private window. You should see a 404 or your site's not-found page. If you see lines like API_KEY=..., every value in that file is public.
Why it happens
- The whole project folder was uploaded to a static host instead of just the build output.
- The
.envfile was placed inpublic/, whose contents are copied to your site as-is. - A server is configured to serve the project root.
The fix
- Rotate every secret in the file. Assume all of them were copied.
- Delete the file from anything your host serves, and deploy only your build folder (often
dist/,build/orout/). - Add
.env*to.gitignore. - Set secrets in your host's environment variable settings instead of a file.
- Deploy and check
/.envagain.