How to protect .env, .git and other sensitive files
Configuration and repository files left readable expose passwords and source code. Block them at the web server.
Step by step, with screenshots: Backups that actually restore: a small-site backup plan you can test →
Check your own site
Runs this check and the other 186, free, in about 45 seconds.
What a passing site looks like
- No sensitive files are readablefail · −15 ptseffort S
Sensitive files are readable by anyone
Why it matters. /.env holds database passwords and API keys; /.git exposes your source code and every secret ever committed. Both are the first things an automated scanner asks for.
- Block dotfiles at the web server (nginx: location ~ /\. { deny all; }; Apache: RedirectMatch 404 /\..*$).
- Move .env outside the web root and rotate every credential in it; assume the file has already been copied.