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.

Dr. Security2 MIN READ

๐Ÿ’ก The short version: files like .env, .git folders 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

PathWhat's inside if it answers
/.envEnvironment settings: database passwords, API keys, tokens
/.git/config and /.git/HEADYour repository's internals, often the way to rebuild the whole source
/backup.zip, /db.sql, /dump.sql, *.bakCopies of your site or database
/phpinfo.php, /server-statusServer details that help someone plan an attack
/.DS_StoreA 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, .git and 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

  1. Remove it from the live site and make sure the build or deploy step can't put it back.
  2. Rotate every secret that was in it. Assume it was read. Passwords, API keys, database credentials, all of them.
  3. For .git: assume the full history was readable, including old commits with keys you deleted later.
  4. Check your logs for who requested the file and what changed afterwards.
  5. 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.

  • exposed env file
  • exposed git folder
  • backup files exposed
  • sensitive file exposure
  • website security

FIND OUT WHAT YOU'RE EXPOSING.