Skip to main content
CriticalSupply chainOWASP A05:2021CWE-538

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

  1. 1Immediately rotate every credential in the exposed .env file.
  2. 2Set the web server document root to public/ or dist/, not the project root.
  3. 3Block access to .env* files at the web server level as defense-in-depth.
  4. 4Add *.env to .gitignore and ensure it has never been committed to version control.

Code examples

Block .env files in Nginx

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.

See every supply chain check

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.

Propose a checkHow a check is built

Scan your own site for .env file exposed at public url

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: .env File Exposed at Public URL | VulnRadar