Exposed .env, .git and Backup Files: How Attackers Find Them
Some files were never meant to be on a live website, and yet they keep turning up. Here is why .env, .git and backups end up public, what gets tried first and how to check and fix yours.
๐ก The short version: files like
.env,.gitfolders and database backups sometimes get published along with a site. Finding them takes one web request per file, no hacking required. Check your live address for each, and if one is there, treat everything inside it as stolen and rotate it.
Here's the uncomfortable part: nobody needs to be clever to find these files. They just ask for them. A request to /.env either returns your secrets or a polite "not found". ๐ฌ Let's make sure it's the second.
๐ What gets tried first
| Path | What's inside if it answers |
|---|---|
/.env | Environment settings: database passwords, API keys, tokens |
/.git/config and /.git/HEAD | Your repository's internals, often the way to rebuild the whole source |
/backup.zip, /db.sql, /dump.sql, *.bak | Copies of your site or database |
/phpinfo.php, /server-status | Server details that help someone plan an attack |
/.DS_Store | A list of file names from a Mac folder |
| Admin and debug tools (database managers, dashboards, API explorers) | A login page at best, a full interface at worst |
๐ค Why they end up there
- The "public" or "static" folder of a project contains everything in it, including a dotfile someone dropped in.
- The whole project folder was uploaded to a host,
.gitand all. - A quick backup was made "just in case" into the website's own directory.
- A debug page was left on after launch.
๐ Check yours
curl -s -o /dev/null -w "%{http_code}\n" https://your-site.com/.env
curl -s -o /dev/null -w "%{http_code}\n" https://your-site.com/.git/config
You want 404 (or a redirect to your home page that isn't the file). A 200 means look at what came back. Be careful with sites that answer every address with the home page: a 200 that returns your normal page isn't a leak, it's just a catch-all.
๐จ If you find one
- Remove it from the live site and make sure the build or deploy step can't put it back.
- Rotate every secret that was in it. Assume it was read. Passwords, API keys, database credentials, all of them.
- For
.git: assume the full history was readable, including old commits with keys you deleted later. - Check your logs for who requested the file and what changed afterwards.
- Block it for good: configure your server or host to refuse dotfiles and backup extensions, and keep sensitive files out of the folder that gets published.
๐งญ How serious is it?
It depends on what's inside. In Dr. Security reports, an exposed .env with credentials or a database dump is rated critical. A readable .git folder is high. Server information pages such as phpinfo are medium, and a stray .DS_Store is low. A tool's login page that is public is only noted, since many are public on purpose.
Worried about what else is lying around in your build? Check for public source maps too.
๐ Let a scan ask for them all. Run a free scan and see which of these paths answer.