How to fix: .env File Exposed at Public URL
A .env or .env.local file was found publicly accessible. Environment files contain application secrets, database credentials, API keys, and encryption keys in plaintext.
Why it matters
A single .env file exposure can compromise every service the application uses: database (full data access), third-party APIs (billing and data exfiltration), email (sending forged messages), payment processing, and encryption keys (decrypting stored data).
.env files are the most sensitive files in a web application. They are in the project root precisely because they should be gitignored and never deployed to the web root. When the webroot equals the project root, .env files become instantly accessible.
How to fix it
- 1Immediately rotate every credential in the exposed .env file.
- 2Set the web server document root to public/ or dist/, not the project root.
- 3Block access to .env* files at the web server level as defense-in-depth.
- 4Add *.env to .gitignore and ensure it has never been committed to version control.
Code examples
Block .env files in Nginx
location ~* /\.env {
deny all;
return 404;
}
# Also block hidden files in general
location ~ /\. {
deny all;
return 404;
}References
Detected automatically by VulnRadar. The check id is supply-chain-env-file-exposed, stable across every scan so you can filter or diff on it.
More supply chain checks
- Mediumnpm/yarn Lock File Exposed
- MediumPython Requirements File Exposed
- MediumRuby Gemfile or Gemfile.lock Exposed
- MediumExternal CDN Script Without SRI Hash
- HighHTTP Script Loaded on HTTPS Page
- MediumPHP composer.json or composer.lock Exposed
- HighDockerfile or docker-compose.yml Exposed
- MediumCDN Script With No Version Pin and No Integrity Hash
Questions
- How severe is .env File Exposed at Public URL?
- VulnRadar rates this critical severity in the supply chain category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id supply-chain-env-file-exposed, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does .env File Exposed at Public URL map to?
- It maps to CWE-538. In the OWASP Top 10 it falls under A05:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.