🛡️ Security Hardening — Dotenv File Access Blocking
Problem
Users reported that /.env (and common variants like /.env.local, /.env.production) were not blocked by NPG's default exploit rules and instead passed through to the upstream application. Investigation showed two gaps:
- Redirect hosts include
block_exploits.confbut that file had no.envrule. - Proxy hosts use DB-driven
exploit_block_ruleswhich had no path-based (request_uri) rule for.env. The only defence was OWASP CRS — which doesn't block when the host's WAF mode isDetectionOnly.
Fix
- ENV-001 rule added to
nginx/includes/block_exploits.confcovering/.env,/.env.local,/.env.production,/.env.backup,/.env.example, nested/path/.env, etc. (does NOT match/environment.txt— no false positives). - Dotenv File Access seed rule added to
exploit_block_rulestable (pattern_type=request_uri,pattern=/\.env(\.|$|/), categoryrfi). Proxy hosts withblock_exploitsenabled now drop.envrequests regardless of WAF mode. - Nginx entrypoint
update_managed_includes()added — syncsincludes/*.conffrom image defaults on every startup (following the existingupdate_modsec_configs/update_static_htmlpattern). Without this, upgraders would keep the staleblock_exploits.confbaked into their/etc/nginxvolume and never pick up ENV-001.
Migration Behaviour
- Fresh install: rule seeded from
001_init.sql. - Existing install (pre-v2.13.7): rule backfilled via
ON CONFLICT DO NOTHINGmigration entry; admin edits preserved. - On startup,
SyncAllConfigsregenerates every proxy_host nginx config and the new rule is applied immediately.
Verification (dev env)
Access log with primary block:
GET /.env HTTP/1.1 403 ... block=\"exploit_block\" exploit_rule=\"c1e7f001-0000-4000-8000-000000000001\"
Upgrade
docker compose pull && docker compose up -dDocker Images
docker pull svrforum/nginxproxyguard-api:2.13.7
docker pull svrforum/nginxproxyguard-ui:2.13.7
docker pull svrforum/nginxproxyguard-nginx:2.13.7Architectures: linux/amd64, linux/arm64
| Component | Status |
|---|---|
| API | Built |
| UI | Built |
| Nginx | Built |