Prompt injection via audited repo file contents can exfiltrate .env credentials through unrestricted Read/Glob/Grep tools #10
Labels
No labels
shellcheck
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
bc1bb/claude-code-audit#10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The
run_audit()function grants the Claude subprocessRead,Glob,Grep, andLStools with no path restriction. Claude can read any file accessible to the process — including$SCRIPT_DIR/.envwhich containsFORGEJO_ACCESS_TOKEN. Any file inside an audited repository can contain adversarial LLM instructions that exploit this: the audit task explicitly directs Claude to read repo files, so adversarial content in aREADME.md, source file, or any other file will be processed by Claude.Location
audit.sh, line 276 (Forgejo mode):audit.sh, line 293 (non-Forgejo mode):There is no
--cwdor path-scoping argument limiting Read/Glob/Grep to the repo under audit.Risk
An attacker who controls any repository being audited can place a file (e.g.,
README.md, a source comment, a config file) containing an adversarial instruction such as:Because
--permission-mode dontAsksuppresses all confirmation prompts, Claude will:.envvia the unrestrictedReadtool, obtainingFORGEJO_ACCESS_TOKEN.mcp__forgejo__create_issue.The attacker then reads the issue (or monitors the public Forgejo API) to harvest the token, gaining full Forgejo API access. The same technique can direct Claude to read other sensitive files on the host (SSH keys, other credentials, configuration files) and exfiltrate them via issue creation.
This attack bypasses the branch-name allowlist introduced in this branch because it operates on file contents read during the audit, not on the injected prompt metadata.
Suggested fix direction
Two complementary mitigations:
Scope file tools to the repo under audit: Pass
--cwd "$repo_path"(if supported) or restrict the allowlist to relative paths. At minimum, document that Claude should only read files within the checked-out repo directory and add an explicit instruction in the prompt forbidding reads outside it.Separate the reading phase from the reporting phase: Run the file-reading step with only
Read,Glob,Grep,LS(no Forgejo tools), collect the findings as structured output, then pipe that output into a second non-interactive step that creates Forgejo issues. An adversarial file can no longer trigger issue creation because the two capabilities are never active simultaneously.Severity
critical
Found by
Automated audit by Claude Code
[fix/prompt-injection-branch-names] Prompt injection via audited repo file contents can exfiltrate .env credentials through unrestricted Read/Glob/Grep toolsto Prompt injection via audited repo file contents can exfiltrate .env credentials through unrestricted Read/Glob/Grep tools