Remove exposed .env and configuration files
अपडेट: 1 दिस॰ 2026
यह गाइड अभी अंग्रेज़ी में है।
What it means
A configuration file such as .env, config.php.bak or a database dump is publicly downloadable. These usually contain database passwords, API keys and encryption secrets.
Why it matters
Critical: direct path to data breach, fraudulent cloud spend and full application takeover.
How to fix it
- Delete the file from the web root (or block it) right away.
- Rotate every credential it contained: database, mail, payment and cloud keys, APP_KEY/SECRET_KEY.
- Move secrets outside the document root or into a secrets manager.
- Check logs for earlier downloads of the file.
Configuration examples
nginx
location ~* (\.env|\.bak|\.sql|\.old|~)$ {
deny all;
return 404;
}
Apache
<FilesMatch "(\.env|\.bak|\.sql|\.old)$">
Require all denied
</FilesMatch>
Laravel / PHP
Point the web server document root at /public (never the project root), so .env is outside it.
IIS (web.config)
<requestFiltering>
<fileExtensions>
<add fileExtension=".env" allowed="false" />
<add fileExtension=".bak" allowed="false" />
</fileExtensions>
</requestFiltering>
Cloudflare
Security -> WAF -> Custom rules: (http.request.uri.path contains "/.env") -> Block
Any platform
Keep secrets out of the document root; deny .env, .bak, .sql, .old files.
Check your fix
curl -s -o /dev/null -w "%{http_code}" https://YOUR_DOMAIN/.env (expect 403 or 404)
References
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration/