Claude Code的“不再询问”文件在GitHub的1,122个公开副本中暴露了密码和密钥
Swati Khandelwal2026年11月7日
人工智能 / 开发者安全
开发人员批准执行的命令中输入的密码和API密钥正存放在公开的GitHub仓库中,任何人都可以读取它们。
当用户选择“是,并且不再询问”时,Anthropic的AI编程助手可以将该命令逐字保存,包括其中的秘密信息,存入项目设置文件中。
软件安全公司Apiiro昨日指出,1,122个公开副本的文件中至少包含一个秘密,尽管他们并未测试这些密钥是否仍然有效。本周早些时候收到研究人员通知的一家公司确认其密钥仍在生效。
该文件名为.claude/settings.local.json。从项目中删除它并不能撤销泄露,因为旧版本仍保留在git历史记录和仓库的Fork(分支)中。研究人员的建议是先轮换:更改该文件曾持有的所有密码、令牌和密钥,然后再进行清理。
秘密如何落入文件中
默认情况下,Claude Code在执行大多数shell命令前会进行询问。根据权限文档,如果用户选择“是,并且不再询问”,它会在项目内的.claude/settings.local.json中保存一条允许规则。随后在会话中,匹配的命令将无需再次询问即可运行。
该规则仅涵盖提示符提供的范围。有时这是一个模式,例如npm test *,有时则是确切的单一命令。当它是确切命令时,输入其中的任何密码或令牌也会以明文形式被保存。
在公开文件中,研究人员发现了仍包含秘密的已保存命令,并使用最新模型Opus 5.5和Fable 5.1重现了该行为。
Claude Code试图将该文件排除在git之外。其设置文档称,当它在git仓库中首次写入该文件时,会将该文件添加到用户的全局git排除列表中。此后,该计算机上的Git将在所有仓库中忽略该文件。
研究人员表示,这种保护仅存在于单个用户在单台电脑上的git设置中。对于已经提交的文件,它毫无作用。Claude Code从未将该文件添加到项目自身的.gitignore中,因此这种保护不会随项目一起传播。
在研究人员追踪的1,105个仓库中的539个里,一次将Claude列为共同作者的提交更改了该文件。他们认为这意味着Claude经常自行提交该文件。
Apiiro的发现
Apiiro对公开GitHub的搜索显示,其研究报告指出共找到104,185个该文件的副本,分布在103,617个仓库中。其中约1.1%,即1,122个副本,至少包含一个秘密。它们共同持有1,379个不同的秘密。
当某个值匹配已知的密钥格式,或者密码或令牌位于公共服务器地址旁边时,即被视为秘密。AI审核员也必须同意这一判断。研究人员并未说明是否有人使用了这些秘密。
超过三分之一的秘密可直接打开数据库,其中包括379个数据库密码。其他包括43个用于公共服务器的SSH登录凭据、42个GitHub、GitLab和npm的令牌,以及23个AWS密钥。
这些文件的所有者中包括63个组织,大多是各种规模的软件公司。研究人员指出,最严重的案例包括一家数据库供应商自身的管理员级云密钥,以及一个医疗记录数据库的所有者密码。
截至周一,所有包含秘密的文件仍位于其仓库的默认分支上,其中一半的仓库中该文件已存在至少217天。
该文件的旧版本在509个仓库中包含另外734个秘密,这些秘密未出现在任何当前副本中,通常是因为该文件已被删除。Fork进一步扩散了这些文件:74个仓库中的211个Fork携带与原始文件相同的秘密。
在共享的 .claude/settings.json 文件的 76,011 个副本中,有 298 个副本中也隐藏着秘密,这些文件通常是团队有意提交的,且大多位于允许规则内。加上那些旧版本和保存的代理聊天记录,总计在 1,994 个存储库中发现了 2,539 个秘密。
研究人员对比了 16 种编码代理的文档,发现 Claude Code 是唯一默认将完整批准的命令保存在项目文件中的代理。
该做什么
对于开发人员,研究人员建议采取以下步骤:
在 GitHub 组织中搜索 .claude/settings.local.json 和 .claude/settings.json,并检查每个存储库的 git 历史以查找这些文件,即使文件已被删除也要查。
清理之前,轮换这些文件曾经包含过的所有密码、令牌和密钥。
使用 git rm --cached .claude/settings.local.json 停止通过 git 跟踪本地文件,并将其添加到存储库自身的 .gitignore 中。
在您自己的计算机上打开该文件(即使它从未被提交过),并删除其中包含秘密的所有规则。
将秘密从命令中移除。将其作为变量从密钥管理器中引用,例如 $DB_URL,以便保存的规则仅持有变量名而非秘密本身。
批准模式(如 Bash(npm run:*)),而不是单个命令。
研究人员表示,那些从未到达 GitHub 的副本同样重要。该文件是项目文件夹中的纯 JSON 格式,它也可能留在 npm 包、Docker 镜像、zip 归档文件或同步文件夹中。
恶意软件此前曾试图在开发人员机器上寻找秘密。2025年9月,Shai-Hulud 蠕虫在被感染的计算机上运行了 TruffleHog 秘密扫描器,扫描器将超过一半的文件标记为包含秘密。
常见的秘密扫描器会遗漏许多此类文件。研究人员对每个副本运行了 gitleaks 和 TruffleHog,但未使用这些工具的验证步骤。在 1,122 个包含秘密的文件中,gitleaks 标记了 564 个,TruffleHog 标记了 643 个,而两者均未标记的有 215 个。
大多数遗漏的是命令中输入的密码。扫描器寻找已知的密钥格式,而 PGPASSWORD=、sshpass -p 或 mysql -p 之后的密码看起来就像普通命令行中的普通单词。
对于安全团队,研究人员建议:
将 .claude/、.cursor/、.gemini/ 和 .specstory/ 等代理文件夹以及代理记忆文件视为包含秘密的文件,如同笔记本电脑上的 .env 文件一样,也要将其视为存储库中的秘密。
将它们添加到 pre-commit 和 CI 秘密扫描中,包括 git 历史,并确保扫描器能捕获命令内的密码,而不仅仅是已知的密钥格式。
将 .claude/settings.local.json 添加到组织的 .gitignore 模板中。
首先检查与公共服务器配对的凭据,因为那些是提供访问权限的凭据。
早期报告
Claude Code 用户此前曾报告过这种行为。2025年8月11日提交的一份早期错误报告指出,带有 API 密钥和令牌的批准命令被逐字存储在 settings.local.json 中。
该报告在60天无活动后,于1月3日被一个自动化机器人关闭,状态为“不计划修复”。
截至今天,研究人员引用的四个相关报告均已被同一机器人关闭,最近的一个是昨天关闭的。他们说,Anthropic 均未对此作出回复。
觉得这篇文章有趣?在 Google News、Twitter 和 LinkedIn 上关注我们,阅读我们发布的更多独家内容。
分享
推文
分享
分享
分享
⚡ 本周头条新闻
中国黑客使用 AI 驱动的 ARTEX 针对全球超过 200 家组织
Microsoft 365 令牌重放攻击导致 79 家组织的 97 个账户受损
威胁操作者的崛起:AI 将如何重新定义安全运营与职业道路
存在 16 年历史的 UEFI 关键漏洞可在网络启动服务器的 Secure Boot 之前执行代码
PHP2Shell 攻击根植于 25 台服务器,入侵美国关联政府网络
AI 生成的虚假登录页面使账户接管变得更加容易
GoAhead TLS 漏洞允许使用已吊销的客户端证书并实现会话解密
为何紧急安全修复未能落实?通过观察、证明、行动、确认推动修复进程
加载更多 ▼
⭐ 精选资源
通过本实用指南评估您组织的 AI 代码 sprawl(无序扩张)暴露风险
了解 Bitdefender GravityZone 如何识别影子 AI 并优先处理终端风险
超越 CVE 扫描:预约演示,体验持续 AI 驱动的 Web 渗透测试
使用 Corelight 的开放 NDR 平台检测横向移动与规避攻击
Claude Code's “Don't Ask Again” File Exposes Passwords and Keys in 1,122 Public Copies on GitHub
Swati KhandelwalNov 07, 2026
Artificial Intelligence / Developer Security
Passwords and API keys that developers typed into commands they approved in Claude Code are sitting in public GitHub repositories, where anyone can read them.
When a user selects "Yes, and don't ask again," Anthropic's AI coding assistant can save the command, word-for-word, including the secret, in a project settings file.
Software security company Apiiro said yesterday that 1,122 public copies of that file hold at least one secret, though it did not test whether any still work. One company the researchers notified earlier this week confirmed its key had been live.
The file is .claude/settings.local.json. Removing it from a project does not undo the leak, because older versions stay in git history and in forks of the repository. The researchers' advice is to rotate first: change every password, token, and key the file has ever held, then clean up.
How a Secret Lands in the File
By default, Claude Code asks before it runs most shell commands. If the user picks "Yes, and don't ask again," it saves an allow rule in .claude/settings.local.json inside the project, according to its permissions documentation. Matching commands then run without asking in later sessions.
The rule covers only what the prompt offered. Sometimes that is a pattern, such as npm test *, and sometimes one exact command. When it is the exact command, any password or token typed into it is saved too, in plain text.
In public files, the researchers found saved commands with the secret still inside, and they reproduced the behavior with the latest models, Opus 5.5 and Fable 5.1.
Claude Code tries to keep the file out of git. The first time it writes the file in a git repository, it adds the file to the user's global git excludes, its settings documentation says. Git on that computer then ignores the file in every repository.
That protection stays in one user's git settings on one computer. It does nothing for a file that was already committed, the researchers say. Claude Code never adds the file to the project's own .gitignore, so the protection does not travel with the project.
In 539 of the 1,105 repositories the researchers traced, a commit listing Claude as a co-author changed the file. They take this to mean Claude often commits the file itself.
What Apiiro Found
Apiiro's search of public GitHub found 104,185 copies of the file in 103,617 repositories, its research write-up shows. About 1.1% of them, or 1,122 copies, hold at least one secret. Together they hold 1,379 different secrets.
A value counted as a secret when it matched a known key format, or when a password or token sat beside the address of a public server. An AI reviewer also had to agree. The researchers do not say whether anyone has used these secrets.
More than a third of the secrets open a database directly, including 379 database passwords. Others include 43 SSH logins for public servers, 42 tokens for GitHub, GitLab and npm, and 23 AWS keys.
Among the owners of these files are 63 organizations, mostly software companies of all sizes. The strongest cases include a database vendor's own admin-level cloud key and the owner password of a medical-records database, the researchers say.
As of Monday, every file with a secret was still on its repository's default branch, and in half of those repositories it had been there for at least 217 days.
Older versions of the file contain 734 more secrets across 509 repositories that are not present in any current copy, usually because the file was deleted. Forks spread the files further: 211 forks of 74 repositories carry the same secrets as the originals.
Secrets also sit in 298 of 76,011 copies of the shared .claude/settings.json file, which teams commit on purpose, mostly inside allow rules. Including those, the older versions, and saved agent chat logs, the total is 2,539 secrets across 1,994 repositories.
Of 16 coding agents whose documentation the researchers compared, Claude Code is the only one confirmed to save the full approved command in a project file by default.
What to Do
For developers, the researchers recommend these steps:
Search your GitHub organization for .claude/settings.local.json and .claude/settings.json, and check each repository's git history for them, even where the files are gone.
Rotate every password, token and key the files have ever held, before cleaning up.
Stop tracking the local file with git rm --cached .claude/settings.local.json, and add it to the repository's own .gitignore.
Open the file on your own computer, even if it was never committed, and delete every rule that contains a secret.
Keep secrets out of commands. Refer to them as variables from a secrets manager, such as $DB_URL, so the saved rule holds the variable name and not the secret.
Approve patterns, such as Bash(npm run:*), instead of single commands.
Copies that never reach GitHub still matter, the researchers say. The file is plain JSON in the project folder, and it can also be left inside an npm package, a Docker image, a zip archive, or a synced folder.
Malware has previously looked for secrets on developer machines. In September 2025, the Shai-Hulud worm ran the TruffleHog secret scanner over infected computers, and the scanner flagged more than half of the files as secret.
Common secret scanners miss many of these files. The researchers ran gitleaks and TruffleHog over every copy, without the tools' verification step. Of the 1,122 files with a secret, gitleaks flagged 564 and TruffleHog 643, and neither flagged 215.
Most misses are passwords typed inside commands. Scanners look for known key formats, and a password after PGPASSWORD=, sshpass -p , or mysql -p looks like an ordinary word in an ordinary command line.
For security teams, the researchers recommend:
Treat agent folders such as .claude/, .cursor/, .gemini/ and .specstory/, and agent memory files, as holding secrets, like .env files, on laptops as well as in repositories.
Add them to pre-commit and CI secret scanning, including git history, and make sure the scanner catches passwords inside commands, not only known key formats.
Add .claude/settings.local.json to the organization's .gitignore templates.
Check credentials paired with a public server first, because those are the ones that give access.
Earlier Reports
Claude Code users have reported this behavior before. An earlier bug report, filed on August 11, 2025, said approved commands with API keys and tokens were being stored word for word in settings.local.json.
An automated bot closed that report as "not planned" on January 3, after 60 days without activity.
As of today, the four related reports the researchers cite have all been closed by the same bot, the most recent yesterday. None got a reply from Anthropic, they say.
Found this article interesting? Follow us on Google News, Twitter and LinkedIn to read more exclusive content we post.
SHARE
Tweet
Share
Share
Share
⚡ Top Stories This Week
Chinese Hackers Use AI-Powered ARTEX to Target Over 200 Organizations Worldwide
Microsoft 365 Token-Replay Attacks Compromise 97 Accounts at 79 Organizations
The Rise of the Threat Operator: How AI Will Redefine Security Operations and Careers
Critical 16-Year-Old UEFI Flaw Can Run Code Before Secure Boot on Network-Booting Servers
PHP2Shell Attack Roots 25 Servers, Breaches U.S. Government-Affiliated Network
AI-Generated Fake Login Pages Are Making Account Takeovers Easier
GoAhead TLS Flaws Allow Revoked Client Certificates and Enable Session Decryption
Why Urgent Security Fixes Aren't Fixed. Observe, Prove, Act, Confirm Gets Them Moving
LOAD MORE ▼
⭐ Featured Resources
Assess Your Organization's AI Code Sprawl Exposure With This Practical Guide
See How Bitdefender GravityZone Identifies Shadow AI and Prioritizes Endpoint Risks
Beyond CVE Scanning: Book a Demo of Continuous AI-Powered Web Pentesting
Detect Lateral Movement and Evasive Attacks With Corelight's Open NDR Platform
首次收录 · 2026-11-08 · 9.21 分