Wiki / Exposed files

Risk: .git/ directory is publicly accessible

Anyone can download the full source code of the site with its change history from your server, including every password that was ever committed to the repository. Close it today: it takes one line.

What it does not mean. It is not proof that someone has already downloaded the code. The server access log shows that: look for requests to /.git/.

Aleksandr IzmalkovFacts checked:

In our report
Risk (red), the highest category weight, 2.0
Time to fix
5 minutes to close; changing the passwords takes longer
Can it break things
No. git pull on the server keeps working

How to fix it

Turning off directory listing does not help: the names of .git files are known in advance and the rest are found from their contents. The path itself has to be blocked.

nginx (tested on 1.26.3)

location ~ /\.git {
    return 404;
}

On the test server the response for /.git/config and /.git/HEAD changed from 200 to 404, in a subdirectory too (/sub/.git/config). deny all also closes it but answers 403, which confirms the directory exists.

Apache (tested on 2.4.59, also works in .htaccess)

RedirectMatch 404 /\.git

Needs mod_alias, which is enabled almost everywhere. Both rules also close .gitignore: the site does not need it.

After closing: passwords

git log --all --full-history -- .env wp-config.php config.php

The command shows whether these files were ever in the repository. If so, change every password and key they held: a file deleted in a later commit stays in the history. Check .git/config too: it often holds the repository address with an access token.

For good: deploy without .git

rsync -a --exclude='.git' ./ server:/var/www/site/

The most reliable setup is one where the site folder has no .git directory at all.

Terminal: before the fix curl prints .git/config with an access token in the repository address; after the fix the server answers 404
A test server before and after the rule. The repository address and token in the example are made up; on real sites that place holds real ones.

How to check

curl -s -o /dev/null -w "%{http_code}\n" https://example.com/.git/HEAD

Expected

404

A 200 response with the text ref: refs/heads/main means the directory is open.

What can break

  • Nothing changes for the site: the rule affects only requests made through a browser, while git pull on the server works with the files directly.
  • Closing the directory does not undo a leak. Until the passwords are changed, the problem is not solved.

Our data

126

of 73,386 inspected .lt websites (0.17%) serve the contents of their .git directory. Another 45 expose an .env file. Dataset, 16 November 2026

Sources

Next