vibe-audit.lab

guides · 2026-11-14

How an Exposed .git Folder Lets Attackers Download Your Source Code

Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team

The short answer

A reachable /.git folder is not a partial leak. With the HEAD ref, the index and the object files, free tools rebuild your complete repository offline — every file, every branch, every secret you committed and later 'removed'. Block .git at the server, assume the history is public, and rotate anything that ever lived in it.

Check your own app free: paste your code or enter your site URL on the Vibe-Code Audit homepage — the free scan checks for exposed secrets, injection flaws, XSS patterns, missing headers and exposed .env/.git paths, with a copy-paste fix for every finding. No credit card.

What is actually inside .git

The .git directory is the repository. HEAD points at the current branch, config lists your remotes (sometimes with credentials embedded in the URL), the index lists every tracked file with its blob hash, and the objects directory holds the compressed content of every file version ever committed. Nothing in there is encrypted or obscured — it is compressed, which stops casual reading and nobody else.

That is why Vibe-Code Audit's live scan probes /.git/HEAD and /.git/config specifically: a 200 on either is proof the whole history is downloadable, not just a stray text file. AI-built apps ship this when the deploy method is 'copy the project folder to the server' — the folder includes .git because nobody told the copy to exclude it.

How reconstruction works, step by step

The attacker requests /.git/HEAD to learn the branch, then /.git/index to enumerate files and hashes, then walks the objects directory downloading each blob. Open-source tools automate the whole crawl in minutes, tolerating the fact that directory listing is off — git's own structure provides the map. The result is a working clone: they can check out any commit, run git log, and diff your history at leisure, offline, forever.

The history is the prize. The current code matters, but the commit from four months ago where a real API key was pasted 'temporarily' and removed in the next commit is still in there, recoverable in seconds. So are internal URLs, TODO comments naming infrastructure, and the email addresses of everyone who committed.

What is Exposed .git folder?

the version-control metadata directory of a project, accidentally served over HTTP. It contains compressed copies of every tracked file and the full commit history, so serving it is equivalent to publishing the repository itself.

Why 'the repo is private on GitHub' does not help

Teams dismiss this finding because the canonical repo is private. Irrelevant: the copy on the web server is the leak, and it is public by accident rather than by settings. Worse, the server copy often contains things GitHub never had — uncommitted local changes swept into a manual upload, a .env that was gitignored (so never pushed) but sits in the same folder tree, and build artefacts with embedded keys.

Treat an exposed .git exactly like a public-repo accident: the content is out, the only questions are what was in it and what you rotate.

Closing it properly

The durable fix is at the serving layer: your web server or host denies every path beginning /.git/ (and dotfiles generally), and your deploy pipeline stops shipping the folder at all — export a clean tree or build artefact instead of copying the working directory. Both layers, because either one alone fails the day someone changes the other.

Then do the archaeology: clone your own exposed history, grep it for the 32 secret patterns a scanner knows — AWS keys, GitHub tokens, Stripe keys, private key blocks, database URLs — and rotate every hit as if it were posted publicly, because functionally it was.

Worked example: Northbeam Outfitters' returns portal

Northbeam Outfitters (fictional) ran a small returns portal written by a contractor with AI help. A live scan flagged 'Publicly exposed: /.git/HEAD' and the score dropped to 38/100. The team downloaded their own history with a reconstruction tool in 11 minutes: 214 commits, including a March commit containing a live database password that had been 'removed' in April — still fully recoverable. They rotated the database password and a SendGrid key found in the same history, added an Nginx deny rule for dot paths, switched deploys to a clean export, and re-scanned at 94/100.

The five-step fix checklist

  1. Request /.git/HEAD and /.git/config on your production domain; a readable response means the full history is downloadable.
  2. Deny all /.git/ and dotfile paths at the web-server or CDN layer, and verify with a fresh request after the change.
  3. Change the deploy process so .git never reaches the server: ship a build artefact or a clean export, not the working folder.
  4. Reconstruct and grep your own history for secrets — keys, tokens, database URLs, private keys — and rotate every match.
  5. Re-scan the live site and confirm the probes return 404 or 403 while normal pages still load.

Sources

Frequently asked questions

Directory listing is disabled. Am I still exposed?

Yes. Reconstruction tools do not need a listing — git's index and refs name every object, and the tooling follows those references file by file.

My current code has no secrets. Why panic?

Because the download includes history. Secrets removed in later commits, old configuration and deleted files are all still present in earlier objects.

Is blocking .git in robots.txt enough?

No. robots.txt is advice to polite crawlers; attackers ignore it, and it actually advertises the path. Block at the server or CDN, and remove the folder from the deploy.

What if only /.git/HEAD responds but objects 404?

That usually means a partial copy or a filtering rule that misses some paths. Test config, index and a known object path too — and fix the rule to deny the whole prefix, not individual files.

Related guides

Browse the full library on the guides index, run the checks in the launch audit, or compare plans on pricing.


Informational explainer, not a security guarantee. Scan your code free before every deploy.

← all guides

← Back