Free check
Is your .env file public?
A .env file holds your database passwords, API keys and other secrets. If it ends up in your web root, anyone can download it with one request, and automated bots look for it constantly.
Why it matters
Exposed .env files are one of the most common causes of serious breaches: one request hands an attacker your database password, payment keys and cloud credentials.
Bots scan the internet for /.env around the clock, so if yours has been public for any length of time, assume the secrets in it have already been collected.
What this check looks at
- /.env plus common variants: .env.local, .env.production, .env.prod, .env.backup, .env.bak, .env.old
- Common subfolders: /app/.env and /api/.env
- Each response's content, so a site that returns a normal page for every address isn't flagged by mistake
How to fix it
Blocking the file isn't enough if it was ever public: rotate every password, key and token it contained.
Nginx
# Deny every dotfile and dot-folder except /.well-known
location ~ /\.(?!well-known) {
deny all;
return 404;
}
Apache (.htaccess)
# Deny every dotfile and dot-folder except /.well-known
RedirectMatch 404 /\.(?!well-known)
Vercel, Netlify, Cloudflare Pages
These hosts only serve your build output folder (for example dist/, build/, out/ or public/).
Make sure .env and .git are never copied into that folder, and don't set the
output directory to your project root.
Express
// Serve static files without exposing dotfiles
app.use(express.static("public", { dotfiles: "deny" }));
Questions
What should I do if my .env file was public?
Block it straight away, then rotate every secret it contained: database passwords, API keys, payment keys and tokens. Check your logs for requests to /.env to see whether it was downloaded.
Is .env.example safe to publish?
Yes, as long as it only contains placeholder values. It's meant to document which settings exist, not to hold real secrets.
Why would a .env file be in my web root?
Usually because the whole project folder is served, instead of only the public or build folder. Frameworks like Laravel, Symfony and many Node apps expect the web server to point at a public subfolder.