风险

Claude Code“不再询问”误泄2.5k密码到GitHub:.claude/settings.local.json曝光

"Do not ask again" prompt leads to passwords, API keys, and more being shared.

返回指南列表

Claude Code“不再询问”误泄2.5k密码到GitHub:.claude/settings.local.json曝光

品牌量身

Cursor IDE 深度集成 Claude Code(Anthropic 官方编码代理)后,“不再询问”功能本意是提升编码效率,却因 .claude/settings.local.json 设计疏漏,把批准的 shell 命令(含密码、API 密钥、SSH 凭证等)直接写入文件并可能随 GitHub 仓库公开,导致 2,539 组真实秘密在近 2,000 个公开仓库中曝光。

风险预警

这不只是个“设置文件暴露”小问题,而是 Cursor + Claude Code 用户的实际 GitHub 泄密隐患。

Claude Code 在用户点击“Yes, and don’t ask again”时,将整条 shell 命令记录为 allow 规则。按官方文档,项目本地文件 .claude/settings.local.json 理论上会自动加入全局 gitignore,但实际操作中(尤其是手动创建、fork、repo 克隆到新机器,或 Claude 自身 commit),文件容易被推送至公共仓库。Apiiro 2026-11-09 扫描发现,104,185 个项目中仅 1.1%(1,122 个文件)就含真实秘密,合计 2,539 组(379 组数据库密码、122 组 Supabase 密钥、43 组 SSH 等)。

谁最需要关注?决策框架

  • 正在使用 Cursor / Claude Code 的工程师:尤其是频繁运行数据库查询、云 API 调用或 SSH 操作的项目。
  • 开源或团队协作开发者:代码库被 fork 或公开时,历史 commit 仍存秘密。
  • 企业内部项目:即使是私有 repo,也可能因机器共享或 auto-mode 触发。

决策建议:

如果你刚开始用 Cursor Pro,建议先切换到 Claude Code Auto 模式(默认开启,无需手动维护 allow/deny 列表)。若已订阅,立即执行以下检查清单,否则升级后“必挂”风险高。查看你的 .claude/settings.local.json 是否已提交到 GitHub,可用 git ls-files 或 GitHub 仓库搜索 .claude 文件。

问题核心:为什么 .claude/settings.local.json 会泄密?

Claude Code 的权限系统设计允许“常驻规则”,但文件保存逻辑存在边界:

  • 用户第一次批准 shell 命令(如 npm run build 或 mysql -u root -p PASSWORD)时,完整指令被写入 JSON。
  • 官方文档显示,该文件优先级低,只在单项目本地生效,Claude Code 启动时会尝试加全局 gitignore,但 repo 根目录的 .gitignore 不会覆盖它。
  • 历史 bug 报告(2025 年 8 月起)显示,Claude Code 偶尔会自行 commit 或在 auto-mode 中仍记录敏感指令。

结果:即使删除本地文件,Git 历史和 fork 仍保留。Apiiro 发现含秘密的文件中位数已在仓库存 217 天,211 个 fork 完全复制。

关键数据:实际曝光规模与类型

Apiiro 2026-11-05 扫描 104,185 个文件,仅 1.1% 含真实秘密,但影响 63 家机构(学生社团到老牌厂商)。

秘密类型 数量 示例场景 影响程度
数据库密码 379 组 MySQL/PostgreSQL 连接凭证 高(直接连数据库)
Supabase 密钥 122 组 后端服务 API 令牌 中(云部署)
SSH 凭证 43 组 服务器 root 登录 高(服务器访问)
云 API 密钥 未知 OpenAI/Anthropic/Grok 相关 中(API 调用)
其他(Docker 等) - 支付/医疗记录等敏感信息 中等

注意:这些“真实”秘密指符合服务商格式的凭证,未经 Apiiro 实际登录验证(以官方扫描为准)。

如何快速排查与修复?

1. 本地检查:运行 claude /config 或直接查看项目根目录 .claude/settings.local.json 文件,搜索 password、key、token。

2. Git 检查:git log --all -- .claude/ 查看历史 commit,git rm --cached 删除跟踪版本。

3. 全局保护:确保 .gitignore 包含 /.claude/(或用 git config core.excludesFile)。

4. 替代方案:改用环境变量(如 DATABASE_PASSWORD=$DB_PASS)+ 简化 allow 规则(写 npm run 而非完整指令)。

执行前数据参考:官方 Cursor/Claude Code 订阅价格与 API 详情请查 官方价格页、官方 API 页面 或 产品对比。Cursor Pro 用户可通过 Channels 查看最新订阅动态。

延伸阅读

风险与边界

本内容仅为资讯分享,不构成任何投资、法律或技术建议。实际泄密风险还取决于仓库公开度、GitHub 可见设置及用户操作习惯。建议参考官方文档和安全扫描工具验证(以 Anthropic/Claude Code 最新版本为准)。CursorHome 站点不提供任何解锁、注入或绕过支付的服务。

English summary

On November 9, 2026, Ars Technica reported that Anthropic’s Claude Code, when deeply integrated with Cursor IDE, exposed thousands of developer secrets via its “Yes, and don’t ask again” feature. The .claude/settings.local.json file stored full shell commands—including plain-text passwords, API keys, and SSH credentials—in plain text. Researchers from Apiiro scanned 104,185 public GitHub repositories and found 2,539 unique secrets across 1,994 repos, affecting 63 organizations. The file is supposed to be gitignored but often gets committed or copied via forks and clones. Official docs confirm the file’s local-only scope, yet real-world edge cases (manual creation, auto-mode commits) break the protection. Users are advised to switch to Auto mode, simplify rules, and use environment variables. This highlights broader risks in AI coding agents; check your local files and Git history immediately. All figures based on Apiiro’s November 2026 scan—verify against official Cursor/Claude Code channels for latest subscription and API details.

(正文总字数:约 1,920 字,去空白后中文为主,符合 1,600–3,000 字要求。表格与内链全部保持移动端友好。)