HighLong standing

Your .git folder is exposed to the internet

A published .git directory lets anyone reconstruct your entire source code and read every secret your repository has ever contained. Check it in one request and fix it today.

The problem

Deploying by running git pull on the server is convenient, and it leaves a .git directory next to your application. If that directory is inside the folder your web server publishes, it is readable over HTTP.

That matters more than it first appears. .git does not just describe the current files, it contains the repository's object database. With it, your full source code can be reconstructed, along with every version of every file that was ever committed.

So this exposes two things at once: your source code, including any server side logic you assumed was private, and your history. Credentials that were committed once and removed later are still in there, and they are still valid unless somebody rotated them.

Are you affected?

Ask your own site for the repository's config file:

https://your-domain.com/.git/config

If you get back a text file containing [core] and a [remote "origin"] section, the directory is exposed. A 404 or 403 is the correct answer.

Also try /.git/HEAD. A response of ref: refs/heads/main confirms the same problem. Some servers block the directory index while still serving the files inside it, so test a file and not just /.git/.

The fix

1. Stop serving the directory

Block it at the web server. For nginx, denying all dotfiles covers this and .env at the same time:

location ~ /\. {
  deny all;
  return 404;
}

For Apache:

<DirectoryMatch "/\.git">
  Require all denied
</DirectoryMatch>

2. Audit the history for secrets

Assume the repository was downloaded. Search the history for credentials that were committed and later removed, and rotate every one you find. They are still live keys.

3. Change how you deploy

Pulling a git repository into the web root is the root cause. Build elsewhere and publish only the build output, or deploy an artifact, or point the document root at a subdirectory such as public/ so the repository sits above it.

4. Point the document root at the right place

Most frameworks expect the server to publish a single subdirectory. Serving the project root is what exposes .git, .env, lockfiles and configuration all at once. Fixing the document root fixes a whole class of problems.

Let your agent fix it

Paste this into Claude Code, Cursor, or any coding agent with access to your project.

You are helping me fix a security misconfiguration on a website I own and operate.

Problem: my .git directory is reachable over HTTP, which exposes my source code and the full commit history, including any secrets ever committed.

Work through the following in order, and confirm with me before any destructive or irreversible step.

1. Identify the stack, the deploy method and the directory the web server publishes. Tell me whether the repository root is being served directly, and how you concluded that.
2. Explain how this project is deployed. If deployment works by running git pull on the server, say so clearly, because that is the root cause.
3. Add a web server rule that denies all requests for paths beginning with a dot, covering both .git and .env. Detect whether this project uses nginx, Apache, Caddy, or a managed host, and write the rule for that one only.
4. Propose the smallest change that stops the repository being inside the published directory: either repoint the document root at the framework's public directory, or switch to publishing build output or a deployment artifact. Show me the change, do not apply it to production yourself.
5. Scan the git history for committed secrets and report them BY NAME AND LOCATION ONLY. Never print a secret value. Useful starting points: git log --all --full-history for files such as .env, config files, private keys, .pem, .p12, id_rsa, and service account JSON.
6. From that scan, produce a rotation checklist naming each credential, the provider it belongs to, and where it gets rotated. I will do the rotating.
7. Tell me whether the exposed history contains anything beyond credentials that I should treat as disclosed, for example internal hostnames, customer data in fixtures, or private business logic.

Finish with a summary of the changes you made, and an ordered list of what I must do by hand.