科技
Claude Code通过其“不再询问”功能泄露了机密信息
中文译文
安全公司Apiiro发现,由于Claude Code在开发者的机器上以本地文件的形式存储相关数据以实现“无需再次询问”功能,该工具会在公共代码仓库中泄露机密信息。该公司在claude/settings.local.json文件中发现了1,122条机密信息,还在git历史记录、被刻意提交的shared settings.json文件以及存储在代码仓库中的智能体聊天记录中发现了另外1,160条机密信息。
问题的根源在于Claude Code处理命令授权的方式。当开发者回复“是的,无需再次询问”来批准某个shell命令时,Claude Code会将此操作作为永久性权限规则保存在本地配置文件 .claude/settings.local.json中,而这些文件可能会无意中包含敏感凭证、密码和API令牌。当[Claude Code]在git仓库中创建文件时,它会将该文件添加到开发者的全局git忽略列表中。这适用于常见情况,但无法处理后来变成仓库的文件夹、在另一台机器上克隆的文件,或是已被他人提交的文件。该规则永远不会被写入仓库自身的.gitignore文件中,因此没有机制能随项目一同存在以保护这些文件。
研究人员发现,在某些情况下,Claude Code本身会提交这些文件。共有63个组织受到影响,泄露的机密信息包括云API密钥、生产环境密码和访问令牌,以及npm令牌。诸如gitleaks和TruffleHog之类的通用机密扫描工具未能检测出所有泄露的机密信息,主要是因为这些信息被嵌入在shell命令中。
无论在何处,只要代理程序记录其运行内容——无论是转录文本、内存文件还是交接笔记——都会出现这种在命令中嵌入密码的模式,而针对特定格式设计的扫描工具在所有这些情况下都无法检测到它。这些研究还指出,Claude Code管理机密信息的方式本身就存在安全漏洞,因为对于任何恶意软件而言,“它只需搜索一个文件,就能获取开发者能够访问的系统列表以及打开这些系统的密码”,而这些文件在每个项目中都位于相同的路径下。
Apiiro的发现后来得到了GitGuardian的证实,后者在公共GitHub上的Claude Code的.claude/settings.local.json文件中发现了31,088个机密信息,其中5,343个在检测时仍然有效,此外在Docker Hub的镜像中还发现了613个机密信息。GitGuardian此前曾警告称,“Cursor、Claude Code和GitHub Copilot会将凭证分散存储在配置文件、日志和shell历史记录中”。
针对这些发现,Reddit用户T_Thriller_T评论道:“有人说过,人工智能公司正在忽视基本的网络安全原则。”
用户MattV0则提出了一种处理人工智能相关文件的有趣方法:虽然这涉及到机密信息,但我已经完全停止在项目中添加AI相关文件。也就是说,不再有各种设置文件、CLAUDE.md、AGENTS.md之类的文件。我甚至关闭了Claude的记忆功能。[…] 如今我通过mcp使用内存/任务/文档服务器,这确实改善了文档管理方面的问题。
至少,Apiiro建议使用git rm --cached .claude/settings.local.json来取消对该JSON文件的跟踪,并将其添加到仓库的.gitignore文件中,同时还要定期更换该文件中存储的所有凭证。为了更为稳妥的做法,研究人员还建议检查该文件,删除其中包含任何机密信息的规则,并避免直接在命令中输入机密信息,而是通过环境变量来引用它们。
原文
Agentic security firm Apiiro found that Claude Code has been exposing secrets in public repositories due to how it stores them in local file on developers' machines to implement the "Don't Ask Again" feature. The company identified 1,122 secrets in claude/settings.local.json files and another 1,160 in git history, in the shared settings.json intentionally committed, and in agent chat transcripts stored in repos.
The problem lies in how Claude Code handles command approval. When developers reply "Yes, and don’t ask again" to approve a shell command, Claude Code saves it as a permanent permission rule in the local configuration file .claude/settings.local.json, which may end up inadvertently containing embedded credentials, passwords and API tokens.
When [Claude Code] creates the file inside a git repo, it adds it to the developer's global git ignore list. That covers the common case. It doesn’t cover a folder that becomes a repo later, a clone on another machine, or a file someone already committed. The rule never goes into the repo's own .gitignore, so nothing travels with the project to protect it.
On some occasions, the researchers found, Claude Code itself committed the file. Overall 63 organizations were affected, with exposed secrets including cloud API keys, production passwords and access tokens, and npm tokens. Generic secret scanners such as gitleaks and TruffleHog failed to flag all exposed secrets, mostly because they were embedded inside shell commands.
The same password-in-a-command pattern appears wherever an agent records what it ran: transcripts, memory files, handoff notes, and a scanner tuned to key formats misses it in all of them.
The researches also note that the way Claude Code manages secrets is a security gap in itself, as to any malware "it’s a list of the systems the developer can reach and the passwords that open them, one file search away", available at the same path in every project.
Apiiro's findings were later reinforced by GitGuardian, which found 31,088 secrets in Claude Code’s .claude/settings.local.json on public GitHub, 5,343 of which were still valid at the time of detection, as well as another 613 in Docker Hub images. GitGuardian had previously warned that "Cursor, Claude Code, and GitHub Copilot leave credentials scattered across config files, logs, and shell history".
Commenting on the findings, Reddit user T_Thriller_T observed that "Somewhere, someone said AI companies are ignoring basic cyber security principles".
User MattV0 suggested an interesting approach to the whole matter of how to deal with AI files:
While this is about secrets, I totally stopped adding AI files into my projects. Means no settings, CLAUDE.md, AGENTS.md or anything else. I even turned off Claude's memory. [...] Nowadays I use a memory/task/docs server through mcp and it really improved such documentation issues.
At very very least, Apiiro recommends untracking the json file using git rm --cached .claude/settings.local.json and adding it to the repo's .gitignore, as well as rotating every credentials the file has ever contained. For a sounder approach, the researchers also recommend inspecting the file and deleting any rule that contains a secret, and avoid typing secrets directly into commands, referencing them instead through environment variables.