Block public access to the .git directory
अपडेट: 1 दिस॰ 2026
यह गाइड अभी अंग्रेज़ी में है।
What it means
The /.git/ folder of your website is downloadable. Attackers can reconstruct your full source code and history, including any passwords or keys ever committed.
Why it matters
Critical: leaked credentials and source code give attackers a map of your application and often direct access to databases or cloud accounts.
How to fix it
- Block /.git (and other dot-folders) at the web server immediately.
- Better: deploy build artifacts only, never the repository folder.
- Assume every secret in the repo history is compromised: rotate them.
Configuration examples
nginx
location ~ /\.(?!well-known) {
deny all;
return 404;
}
Apache
RedirectMatch 404 /\.(?!well-known)
IIS (web.config)
<security>
<requestFiltering>
<hiddenSegments>
<add segment=".git" />
</hiddenSegments>
</requestFiltering>
</security>
Cloudflare
Security -> WAF -> Custom rules: (http.request.uri.path contains "/.git") -> Block
Node.js / Express
app.use((req, res, next) => (/\/\.(?!well-known)/.test(req.path) ? res.sendStatus(404) : next()));
Any platform
Deny every request whose path contains "/." except "/.well-known/".
Check your fix
curl -s -o /dev/null -w "%{http_code}" https://YOUR_DOMAIN/.git/HEAD (expect 403 or 404)
References
- https://owasp.org/www-project-web-security-testing-guide/