Claude Code 的「Don't Ask Again」功能令機密資料外洩至公開儲存庫
Claude Code Has Been Leaking Secrets Through Its "Don't Ask Again" Feature
Apiiro 發現,Claude Code 的「Don't Ask Again」功能會把命令核准規則存入本機設定檔,令內含憑證、密碼及 API tokens 的內容可能外洩至公開儲存庫。
報道説明命令核准規則如何令機密資料進入公開儲存庫,並列出兩家安全公司的檢出數據及避免憑證留在命令中的處理建議。
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.
About the Author
Sergio De Simone
Show moreShow less
來源:InfoQ · infoq.com