A public site exposes its .git folder. How do I fix it?
Short answer: block repository metadata at the web server, remove it from the deployment artifact, and rotate any credentials found in history. This guide explains what to verify and what the public scan cannot prove, without logging in, changing records, or treating an inconclusive response as a pass.
What the publicly exposed .git folder check covers
A public .git directory can reveal repository metadata, object names, commit history, and sometimes source files. A response to one marker path does not prove that the entire repository can be reconstructed.
The finding describes a public condition, not proof that someone has abused it. First preserve the relevant deployment details, then rotate exposed credentials or close the access path before investigating billing, logs, or affected records.
Treat repository metadata as private even if the current source appears harmless. Historical commits can retain secrets removed later, so a clean current tree does not clear credentials that were once committed.
Understand the evidence before changing code
Configure the build to publish only the application output and deny .git paths at the origin. Do not try to fix the issue only with a client-side redirect or by hiding links in the page.
Severity reflects potential impact and reach, not certainty of exploitation. A public key can be intentionally visible; the important distinction is what the provider allows that key to do and which server-side policy still applies.
Apply the narrow, safe change
If a credential appears in repository history, revoke or rotate it with the provider and follow the repository host's history-cleanup process. Rewriting history alone does not invalidate a copied secret.
location ~ /.git {
deny all;
return 404;
}Prefer the smallest repair that restores the intended boundary. Keep public client configuration public, move privileged operations behind an authenticated server route, and make data rules depend on the authenticated owner or an explicit role.
Verify the production result
Deploy a clean artifact, request a known metadata path, and confirm the origin and CDN return a denial or not-found response. Verify the public site still serves its intended assets.
Use the snippet as a starting point, not a blind migration. Confirm the real table, environment, route, identity claim, and deployment platform first; a copied policy with the wrong owner field can block legitimate users or expose the wrong records.
Keep the issue from returning
Add a build assertion that the output directory contains no .git directory, and use repository secret scanning. Keep deployment packaging explicit so hidden files are not copied accidentally.
Verify the repair from the same public vantage point that exposed it. Check the deployed response, confirm the finding is gone, and test the intended signed-in user and an unrelated user through the normal application flow.
Limits and next steps
The scanner does not download repository objects or determine whether private code can be recovered. Treat the public marker as a signal to inspect deployment packaging safely.
Prevent recurrence with a reviewed migration, a secret scanner, and a small regression test that runs before deploy. Store only the minimum required credential, scope it to one project, and define who can rotate it.
A public scanner cannot establish whether private records were accessed or whether an account was compromised. If a real secret shipped, revoke it with the provider and review the provider's usage and audit history.
Key facts
- A current clean tree can still have secrets in earlier commits.
- Build artifacts should include only files needed to serve the application.
- Credential rotation is necessary even after repository history is rewritten.
Questions
Can a clean publicly exposed .git folder check prove the app is secure?
What should I do first if the finding is real?
Does ProofForge change application data?
What should I do after the repair?
Official documentation referenced
Related
Last updated 2026-11-25 · Reviewed by ProofForge · Methodology · Markdown