Skip to content
AI / LLM Write-up Advanced

Expand file tree

Claude Code accepted a worktree named '.git', which combined with a repo whose root doubles as a git directory caused gitdir confusion. A prompt injection in a cloned repo could then drive Claude's own worktree tools to overwrite the user's shell startup file and run code outside the macOS seatbelt sandbox.

github.com

Published on github.com

Metnew / write-ups Public

The author, on github.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the worktree-name validation did not reject the name '.git', so a worktree path could collide with git's metadata directory and, with a repo laid out as a valid gitdir, redirect git operations to attacker-controlled config and paths.

Impact

An attacker who gets a prompt injection into a cloned repo could achieve code execution outside the sandbox even in the most restricted mode, though the PoC only demonstrated opening a calculator.

What the attacker needed

Victim clones and opens a malicious repo; prompt injection in the repo is followed; sandbox enabled, Bash not auto-allowed

The fix

The fix was deployed and released in Claude Code 2.1.163, rejecting '.git' as a worktree name.

How it was found

  1. Make the malicious repo the current working directory.
  2. Create a worktree named '.git' and exit it without cleanup.
  3. Move the working directory to another folder and create and exit a second '.git' worktree there.
  4. Enter the worktree registered at the user's home path.
  5. Run git status so the redirected gitdir overwrites the shell startup file.
  6. Run a command so the shell reads the poisoned startup file and executes the payload.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Claude Code is a command-line assistant that can run commands for you, and it tries to keep those commands inside a restricted 'sandbox' so they cannot harm the rest of the computer. A cloned project can contain hidden instructions that the assistant reads and follows, and here those instructions tricked it into writing a startup file that the shell reads before the sandbox is switched on. That meant the attacker's command ran with full access to the user's home folder.

What is AI / LLM?

Prompt injection, data exfiltration and tool abuse in features built on language models, and the ordinary bugs around them.

Similar reports

View all

Same bug class and techniques, clearest first.

AI and LLM vulnerabilities

The lesson behind this report.

Prompt injection, data exfiltration and tool abuse in features built on language models, and the ordinary bugs around them.