Exposed .env Files and .git Folders: The Leak Nobody Notices

By · 7 November 2026 · 4 min read

Illustration of an .env file and a .git folder exposed on a website, then locked away

Plenty of company websites look perfectly fine from the outside. The pages load, the forms work and the browser shows no warnings. But in the same folder as those pages there is sometimes a file nobody should ever be able to open: an .env file holding the database password, or a .git folder holding the full history of the website's code.

Leaks like this are rarely noticed, because nothing breaks. The website carries on as normal while someone else reads your company's most important keys. This article explains what these two things are, why they end up exposed, and how to check for them and close them off.

What are the .env file and the .git folder?

An .env file is a settings file used by many web applications, for example those built with Laravel. It usually holds the most sensitive data of all: the database address and password, the email sending account, keys for payment or cloud storage services and the application's encryption key. Laravel's own documentation says this file must not be committed to the code repository, because the credentials in it would be exposed.

The .git folder is created by Git, the tool developers use to record every change to the code. According to Git's official documentation, almost everything Git stores lives in this folder, and copying it gives you nearly the whole repository. In other words, anyone who can download the .git folder from your website can rebuild the code, including old versions and files that were once saved and later deleted.

Why do these files end up exposed?

The cause is almost always how the website was deployed, not some sophisticated flaw. Common patterns include:

  • The whole project folder is made public. The server points at the project's main folder rather than at a folder meant for the public. Laravel's documentation warns that doing this exposes many sensitive configuration files to the internet.
  • The site is deployed by copying the repository straight onto the server. The .git folder comes along into a folder the browser can reach.
  • The server does not refuse files whose names start with a dot. The sample Nginx configuration in Laravel's documentation specifically denies all such files, but not every server is set up that way.
  • Backup files are left behind. For example .env.bak, .env.old or a ZIP archive made "just for a moment" during a fix. The OWASP testing guide names old and backup files like these as a source of leaked credentials and code.

Bots look for them every day

Nobody needs to know your website in particular to find these files. Automated bots try the same addresses on thousands of websites: /.env, /.env.backup, /.git/config and so on. If one of them answers, the bot has what it came for.

We see it ourselves. The sensor on digimasi.com records bot requests for addresses that do not exist on our site, and .env files are among the most requested. We publish the summary as it is on our research page.

OWASP, the non-profit that compiles the best-known list of web application security risks, ranks security misconfiguration second in the OWASP Top 10 2025. It also notes that every application tested had some form of misconfiguration.

How to check your own website

The basic check is simple and can be done in a browser, on your own company's website only:

  1. Open your website's address followed by /.env, for example yourdomain.com/.env.
  2. Do the same for /.git/config.
  3. A safe result is a "not found" (404) or "forbidden" (403) page. If you see text full of settings instead, or a file downloads, that file is exposed.
  4. Repeat this for any other subdomains you have, such as staging, dev or an admin panel. Test sites are often set up in a hurry and then forgotten.

This is only the most basic check. There are other file names worth looking for, such as backups and archives. A thorough review is best done by your website provider or through planned security testing.

How to close them off

  • Point the server at the public folder only. Settings files, application code and Git history stay outside the folder the browser can open. OWASP advises against storing data, log and configuration files inside the web folder.
  • Deny every file starting with a dot in the server settings, except the .well-known folder, which is genuinely needed, for example for SSL certificates.
  • Deploy the build, not the repository. The release process should only send the files the website needs to run, without the .git folder.
  • Don't edit directly on the server. OWASP notes that editing files on the server often leaves temporary backup files behind.
  • Don't keep secrets in code. The OWASP Top 10 advises against embedding credentials in code or configuration files, and recommends keeping them somewhere dedicated with restricted access.

If they are already exposed

Deleting the file is not enough, because you don't know who has already copied it. In order:

  1. Change every secret in it first: database passwords, email accounts, API keys, cloud service keys. GitHub's documentation gives the same advice for leaked secrets: revoke or rotate them first, because a rotated secret can no longer be used.
  2. Close off access using the steps in the previous section, then check again in the browser.
  3. Check the logs of the server and of every service whose keys leaked, for any unusual use.
  4. Find the cause in the release process, so the same file doesn't reappear in the next release.

Read also: the basics of company website security.

An .env file or a .git folder doesn't break how a website looks. That is exactly why the leak can last a long time without anyone noticing.

Want to know whether your company website has a leak like this? See how we work in our pentest methodology, or request a pentest quote.