Join our Newsletter — 33% off our NHI Course
Home› Guides› Exposed .git and .env Files for Beginners: How…
Guide Secrets Management

Exposed .git and .env Files for Beginners: How Website Leftovers Leak Passwords and Keys

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 28 November 2026 12 min read
On this page

An exposed .git or .env file is a hidden project file left where anyone on the internet can download it.

This guide is for website owners, students and anyone new to running a site. You do not need to write code to be affected: if someone builds or hosts a website for you, these files may sit on your server.

In short

  • Websites are often built from a project folder that holds hidden files as well as web pages.
  • The .git folder can hold the code's whole history. The .env file often holds passwords and keys.
  • If these files are copied to the public web folder, automated tools can find and download them.
  • Copy only the files the site needs, block hidden files, keep secrets in a locked store and change any that leaked.

What you will learn

  • Explain what .git and .env files are in plain words.
  • Spot why a website copy can leak passwords and keys.
  • Check, with your web supplier, that these files stay private.
  • Ask for the right fix if one has been exposed.
Settings file (.env)
a small text file that holds an app's settings, often including its passwords and keys.
History folder (.git)
a hidden folder where the Git tool keeps every saved version of a project.
Public web folder
the folder on a web server whose files anyone can ask for by typing an address.

What are exposed .git and .env files?

Think of a builder who finishes a shop but leaves the site office unlocked. The plans, the spare keys and the alarm codes are all inside. Anyone walking past can step in.

Websites are often built in a project folder on a developer's computer. Next to the web pages sit hidden files that visitors should never see. Two are common.

The first is the .git folder. Git is a tool that keeps a history of saved versions of a project. It stores that history, and its own settings, in this hidden folder.[3]

The second is the .env file. Many apps keep settings that change between places, like test and live, outside the code. These are often environment variables (named settings the app reads when it starts), and a .env file is a simple way to list them. These settings often include the passwords and keys the app uses to connect to other services.[4]

A web server is the computer that sends web pages to visitors. It hands out files from one chosen folder.[6] If someone copies the whole project into that folder, the hidden files can go with it. Then anyone who asks for them by name may get them.

Where the comparison stops working: a passer-by has to notice an open door. On the internet, automated tools check huge numbers of websites for these file names, so nobody needs to notice anything.

Why does it matter?

The keys inside these files let software connect to databases, cloud accounts and payment services. In 2024, researchers at Palo Alto Networks described criminals who looked for exposed .env files on at least 110,000 domains. They used cloud keys they found to steal and delete data, then asked for a ransom.[1]

If you own a small business website

What could happen: a stranger downloads the file holding your shop's database password.

Check this: ask your web supplier how they stop hidden files being served.

Next: Web Servers for Beginners

If you are learning web development

What could happen: you upload your whole project folder, history and settings included.

Check this: before you upload, list exactly which files the site needs.

Next: Secrets in Code for Beginners

If you look after IT for a team

What could happen: an old test site still holds live keys that nobody remembers.

Check this: keep a list of every website and who looks after it.

Next: Leaked Secret Response for Beginners

What does it look like?

Here is a made-up web folder for a bakery's site. It is what the server can hand out.

Example only. All values are made up.

public web folder for bakery.example.com
  index.html                  (web page, meant to be seen)
  menu.html                   (web page, meant to be seen)
  .git/                       (1)
  .env                        (2)
     DB_PASSWORD=FAKE-Loaf-0000
     CLOUD_KEY=EXAMPLE-KEY-0000-FAKE   (3)
  1. In a real file listing, this would be the hidden history folder. Someone could use it to rebuild the code.
  2. The settings file, copied up with everything else.
  3. In a real file, this line would contain a cloud key that lets software act as the business.

Why this is risky: the server hands out files from this folder to anyone who asks. Visitors see only the menu, but automated tools ask for the hidden names directly.[1]

The safer way: the public folder holds only the pages and pictures the site needs. The server is set to refuse hidden files. The passwords and keys live in the hosting service's secure settings or a secrets store, not in a file in that folder.

How does it work?

Here is how a hidden file usually ends up in a stranger's hands.

  1. The upload. Someone copies the whole project folder to the server, because it is quick. The hidden .git folder and .env file go too.
  2. The open door. The server is not told to refuse hidden files, so it treats them like any other file.
  3. The scan. Automated tools ask many websites for /.env and /.git/, looking for a reply.[1]
  4. The harvest. From a .git folder, they may rebuild the code and its history, including any password saved in an older version. From a .env file, they read the keys straight away.[3]
  5. The use. If a key still works, they can use it to reach the service it opens, with whatever rights it has.[1]
Before and after diagram titled How website leftovers get found. Left panel, labelled Risky: the whole project folder is copied to the public web folder, so a .git folder holding the full history and a .env file holding passwords and keys sit there. Arrows lead to a box saying an automated scanner asks for the file and the server may hand it over. Right panel, labelled Safer: only the files the site needs go to the public web folder, the server refuses hidden files such as .git and .env, passwords and keys come from a locked store not a file, and a green box says regular check that these files stay private.
Figure 1. Risky and safer: copying the whole project versus copying only what the site needs.

This is a known kind of weakness. A long-running list of software weaknesses describes leaving a code history folder where outsiders can reach it, and suggests removing it from live servers.[5] One 2026 study reported nearly 5 million web addresses showing a public .git folder. The researchers have not published their method, so treat the number as their own count.[2]

A worked example

Kaia Osei runs a small fictional bakery with an online order page. Emil Erikson, a freelance developer, built and hosts the site.

One morning Kaia's card payment service emails her. It has seen order requests from a country where she has no customers. She calls Emil.

Emil checks the server. When he built a new menu page last month, he copied his whole project folder up in one go. The .env file went with it. It held the database password and the payment key.

Kaia thinks of the builder's unlocked site office. Locking the door now does not help if someone has already copied the keys. So the first job is to change them.

Emil asks the payment service for a new key and turns the old one off. He changes the database password too. Once the changes have taken effect, the old copies should no longer give access.

Next he deletes the .env file and the .git folder from the public folder. He sets the server to refuse hidden files. The app now reads its keys from the hosting service's secure settings.

Then he checks the payment and database records since the upload. He finds the strange requests, which the payment service had already blocked, and no other unusual activity in the records available to him.

Last, they agree a simple rule. Only the files the site needs go to the server, and Emil writes down which ones they are.

Myths and mistakes

What people thinkWhat is true
Nobody can find a file that no page links to.Automated tools ask for common file names directly. A link is not needed.[1]
Hidden files are hidden from the internet too.The dot only hides them in normal folder views. A web server may still send them.
Deleting the file fixes the leak.Anyone who already downloaded it still has the keys. Change them first, then remove the file.
The .git folder holds no passwords.It holds the project's history, so a password saved in an older version may be inside.[3]
Our site is too small to be targeted.Scanning is automated and broad. Small sites are checked along with large ones.

What can I do this week?

  • Ask your web supplier whether the server refuses hidden files such as .git and .env.
  • Ask how files get onto the server, and whether only the needed files are copied.
  • List every website you run, including old test sites, and who looks after each.
  • Agree what happens if a file has been exposed: change the keys first, then clean up.

Checklist

  • Only the files the site needs are copied to the public web folder.
  • The web server is set to refuse hidden files and folders.
  • No passwords or keys sit in files inside the public web folder.
  • Secrets come from the hosting service's secure settings or a secrets store.
  • Someone checks after each change that hidden files cannot be opened from the internet.
  • Old test and staging sites are removed or locked down.
  • Everyone knows to change exposed keys first, then remove the files.

Common questions

What is a .env file for?

A .env file lists an app's settings, such as which database to use and the password for it. It lets the same code run in different places with different settings. It is meant to stay on the server's private side, never in the public web folder.

Why is a .git folder on a website a problem?

A .git folder holds the project's saved history, not just today's files. Someone who downloads it may rebuild the code and read older versions. If a password was ever saved in the project, even once, it may still be in there.

How do I know if my site has this problem?

Ask the person who runs your server to check that hidden files cannot be opened from the internet. They can do this safely on your own site. Only test websites you own or have permission to check. See How to find exposed .env, .git and config files on your web servers before attackers do.

What should I do first if a file was exposed?

Change every password and key in it first, at the service that issued each one. Then remove the file and block hidden files. Then check the records for unusual use since the file went up. See Exposed .git Directory Response.

Is this the same as secrets in code?

No, but they are related. Secrets in code is about passwords saved into a project and shared through Git. This page is about project files copied to a live website, where anyone online can ask for them. The same keys can leak both ways.

Where next?

Ready for the detail? Read the practitioner analysis: Misconfigured Git Servers 2026: How Nearly 5 Million Exposed .git Folders Leak Source Code and Deployment Credentials. It goes further into what the study found, the kinds of credentials in exposed folders and the controls that close the gap.[2]

Also useful:

Related NHI Mgmt Group resources: Exposed .git Directory Response · Directory Listing and Exposed Backup Files Guide · Secrets Management Guide

Key terms

Environment variable
A named setting an app reads when it starts, often used for things that change between test and live.
Git
A tool that tracks changes to a set of files and keeps a history of saved versions.
Repository
A project's files plus their full Git history, kept in the hidden .git folder.
Web server
A computer program that sends web pages and files to visitors who ask for them.
Secret
A password, key, token or certificate that software uses to prove who it is.
Non-human identity (NHI)
A digital identity, or the credential behind it, that represents a machine, application, automated process, service or AI agent, so it can authenticate, carry out tasks and connect to other systems without a person.[7]
Secrets manager
A tool that stores secrets locked away, controls who can read them and records each use.

Sources and further reading

  1. Leaked Environment Variables Allow Large-Scale Extortion Operation in Cloud Environments. Unit 42, Palo Alto Networks, 15 August 2024. https://unit42.paloaltonetworks.com/large-scale-cloud-extortion-operation/, accessed 28 Nov 2026.
  2. Misconfigured Git Servers 2026: How Nearly 5 Million Exposed .git Folders Leak Source Code and Deployment Credentials. NHI Mgmt Group, 5 February 2026, reporting a Mysterium VPN study. https://nhimg.org/millions-of-misconfigured-git-servers-are-leaking-secrets-online, accessed 28 Nov 2026.
  3. gitrepository-layout: Git Repository Layout. Git documentation. https://git-scm.com/docs/gitrepository-layout, accessed 28 Nov 2026.
  4. The Twelve-Factor App: III. Config. Adam Wiggins. https://12factor.net/config, accessed 28 Nov 2026.
  5. CWE-527: Exposure of Version-Control Repository to an Unauthorized Control Sphere. MITRE. https://cwe.mitre.org/data/definitions/527.html, accessed 28 Nov 2026.
  6. Module ngx_http_core_module (root and location directives). nginx documentation. https://nginx.org/en/docs/http/ngx_http_core_module.html, accessed 28 Nov 2026.
  7. The Ultimate Guide to Non-Human Identities. Lalit Choda, NHI Mgmt Group, January 2025. https://nhimg.org/the-ultimate-guide-to-non-human-identities, accessed 27 Nov 2026.

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.