Exposed .git: take your source code back off the public internet
Blocking /.git and rotating any committed secrets stops anyone from downloading and rebuilding your entire codebase
The threat
The scanner asked for /.git/HEAD and got back a valid git reference. That one response means the whole .git folder is sitting under your web root, and .git is not just your current files: it is every version, every branch, every file ever committed. Off-the-shelf tools like git-dumper walk that folder over plain http and rebuild your entire working tree on someone elseβs laptop, no login required.
The part that surprises people is the history. Anything ever committed comes back too: an old config with a database password, an API key someone pasted in and βremovedβ the next week, private comments. Deleting a secret in a later commit does not remove it from the repository, so this is two problems at once: your source is now public, and every credential that ever lived in it is now public.
The exact fix
Step 1, contain: rotate every secret that has ever been committed. Because git keeps full history, βwe deleted that line months agoβ does not help you here. Scan the history and rotate anything sensitive it turns up:
- Run a secret scanner over the repo (
gitleaks detectortrufflehog git file://.), orgit log -pand read. - Rotate what it finds: database passwords, API keys and tokens, signing keys, webhook secrets. Treat each as public.
Step 2, stop serving the repository. Two parts, and the first is the real cure:
- Deploy build output, not the repo. The web root should contain compiled or built files, never the
.gitfolder. If your server deploys by runninggit pullinto the served directory, that is the root cause: switch to publishing built artifacts into a clean directory. On a static host like Netlify only the build output ships, so there is no repository to serve. - Block the path at the server as a backstop.
nginx:
location ~ /\.(git|svn|hg) {
deny all;
return 404;
}
Apache (vhost or .htaccess):
# Apache 2.4
RedirectMatch 404 "/\.git"
The block is the seatbelt, not the cure. If a working git checkout is your web root, blocking
/.githides the symptom while the repo is still one misconfiguration away from exposure. Fix the deploy so built artifacts, and only built artifacts, land in the served directory.
Verify it
curl -sI https://yourdomain.com/.git/HEAD
You want HTTP/2 404 (or 403). A 200 means the folder is still being served, and you can confirm it by fetching the body: if ref: refs/heads/... comes back, anyone can clone you.
Proof
The ApeCyber scanner flags this passively, from the outside, with a single GET of /.git/HEAD, touching nothing else. apecyber.com deploys built artifacts to Netlify, so the repository never reaches the web root and there is nothing at /.git to fetch. At β40 this is the single heaviest line on a posture score, and it clears the moment the repo stops being served and any committed secrets are rotated.