Exposed .git folder: your source code and old config files, open to anyone
Last reviewed
Your site is handing out its source code and old config files.
An exposed .git folder is the hidden folder that Git, a tool developers use to track every version of a website, left where any browser can download it. Two leftovers often sit beside it: editor backups such as wp-config.php.bak, which serve your database password as plain text, and Mac .DS_Store files that list what a folder holds. Closing them takes a server rule and, where passwords leaked, new passwords.
Why a leaked .git folder or backup file costs you customers
With the .git folder open, a stranger can rebuild your site's code along with its whole edit history, including any password a developer once typed into a file and later deleted. A readable wp-config.php.bak gives away the database login outright. A .DS_Store file is milder, but it maps out file and folder names you never linked to, pointing a curious visitor at the next thing to try.
What usually causes a leaked .git folder or backup file
- The site was deployed by copying the whole working folder from a developer's computer, hidden .git folder and all
- Someone made a quick copy of wp-config.php before editing it, or their editor saved one automatically, with an ending such as .bak, .old, .save or ~
- Files were dragged from a Mac to the server, carrying the hidden .DS_Store file that Finder writes into folders it opens
- The server runs .php files as code but hands any other file type, a .bak copy included, to the browser as readable text
- Nobody added a rule refusing requests for hidden files and folders, the ones whose names begin with a dot
How to check for a leaked .git folder or backup file yourself
- On a site you own, type your domain followed by /.git/config into a browser. A short text file of settings, usually including a line that names where the code is stored, means the folder is open. A 403 or 404 error page means it is closed.
- Do the same with /wp-config.php.bak, /wp-config.php.old and /wp-config.php~ on a WordPress site. Any of them showing text that mentions your database name and password means that login is public.
- Try /.DS_Store as well. If a file downloads instead of an error page, it is exposed. Opened in a text editor, it usually shows file names from that folder scattered among odd characters.
- Ask whoever deploys the site how files get onto the server. If the answer is uploading or copying the whole project folder, check whether hidden folders are going up with it.
How to fix a leaked .git folder or backup file
- Your developer deletes every stray copy of wp-config.php and every .DS_Store file from the server, and takes the .git folder out of the public web folder, or blocks it with the rules below if their deploy process needs it there.
- On an Apache or LiteSpeed server, the usual setup on cPanel hosting, your developer adds two lines of protection to the .htaccess file in the site's main folder: RedirectMatch 404 /\.(?!well-known/) to hide every dot file and dot folder, and a FilesMatch block that denies names ending in .bak, .old, .orig, .save, .swp or ~. The exception keeps /.well-known/ open, because security.txt and certificate renewals rely on it.
- On an Nginx server, your developer or host adds location ~ /\.(?!well-known/) { deny all; } near the top of the site's server block, plus a second location that refuses the same backup endings, then reloads Nginx.
- On managed or static hosting with no server file to edit, the fix lives in the deploy itself: publish only the finished site folder, and ask the host whether it can refuse requests for hidden paths.
- Treat anything those files revealed as known to strangers. After a leaked wp-config backup, your developer changes the database password and generates fresh WordPress security keys, which signs everyone out. After a .git leak, they revoke any access token found in the repository settings or the code history. The guide to exposed .env files covers rotation and log review step by step.
- Your developer adds .git, .DS_Store and backup endings to the deploy's exclude list, and you repeat the browser checks above after every redesign, plugin overhaul or move to a new host.
How Prsona catches a leaked .git folder or backup file
When you ask for the deeper security check on a site you own, Prsona tests whether its .git folder, a .bak copy of wp-config.php or a Mac .DS_Store file can be fetched by a stranger. Each finding names the exact address that answered, so your developer can open it and see the same thing.
Prsona looks for a leaked .git folder or backup file as part of website security monitoring.
Find out whether hidden folders or backup copies on your own site can be downloaded.
Questions about a leaked .git folder or backup file
Is an exposed .DS_Store file a real security problem?
On its own it is a small one. The file holds no passwords, only the names of files and folders in the directory where it sits. Those names can point someone at a forgotten backup, an old admin page or a test upload, so delete it, block it, and check whether anything it lists should be public at all.
Can someone really rebuild my website from the .git folder?
Often, yes. Even when the server refuses to list the folder's contents, the files inside follow a standard layout, so freely available tools can fetch them one at a time and reassemble the code with its history of changes. That history can still hold passwords or keys a developer removed long ago, which is why blocking the folder is only half the job.