ClaudeMods
☰
ZH-CN
● — 人在线 · 浏览 — 次
赞助提交作品
GitHub 仓库 · 发布者 ShriD5

secret-guard

通过 tool.call 钩子阻止 Write、Edit、MultiEdit、NotebookEdit 和 Bash 重定向把看似真实的凭据写入文件,同时允许占位符、开发默认值和 .env 文件。

已翻译

关于这个 mod

secret-guard 添加 tool.call 钩子,检查文件工具准备写入的文本以及 Bash 命令重定向到文件的内容;发现看似真实的凭据就拒绝调用。它检测 AWS、Anthropic/OpenAI、GitHub、Slack、Stripe、Google 密钥、私钥块以及带内嵌密码的数据库 URL。占位符(xxxx、process.env.X、EXAMPLE 密钥)、开发默认值(localhost、example.com、postgres:postgres)、文件中已有的秘密和 .env 系列文件会放行,但 .env.example/.sample/.template 仍受保护。CLAUDE.md 和 AGENTS.md 会接受更严格检查。被阻止时会告诉 Claude 发现了什么及所在行,并要求改用环境变量,不回显秘密。使用 claude --plugin-dir ./secret-guard 或市集安装,并运行 /secret-guard 查看按类型统计的阻止结果。

安装

请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。

claude plugin marketplace add ShriD5/claude-mods
claude plugin install secret-guard
原文 / README

secret-guard

Stops Claude from writing secrets into files. When a Write, Edit, MultiEdit or NotebookEdit would put a real-looking credential into a file, or a Bash command would echo, printf, tee or heredoc one into a file, the call is refused. Claude is told what it found and on which line, and to read the value from an environment variable instead, with the value kept in a gitignored .env. The secret itself is never repeated back.

🔒 secret-guard blocked a GitHub token in config.ts

It catches:

  • AWS access keys (AKIA…, ASIA…)
  • Anthropic keys (sk-ant-…), OpenAI keys (sk-proj-…, legacy sk-…), and other long sk-… keys
  • GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_, github_pat_)
  • Slack tokens (xoxb-, xoxp-, …) and Slack webhook URLs
  • Stripe live keys (sk_live_, rk_live_)
  • Google API keys (AIza…)
  • private key blocks (-----BEGIN … PRIVATE KEY----- with a key body)
  • database URLs with an inline password (postgres://, mysql://, mongodb+srv://, redis://, amqp://)

It lets these through:

  • Placeholders: xxxx, your-key-here, <api-key>, ${VAR}, process.env.X, AKIA…EXAMPLE, low-variety strings.
  • Dev defaults: database URLs to localhost or a docker service name, documentation hosts like example.com, and default passwords like postgres:postgres.
  • Secrets the file already holds: editing next to an existing key isn't blocked.
  • Env files: .env, .env.local, .env.production and .dev.vars, which is where the deny message tells Claude to put secrets. .env.example, .env.sample and .env.template are still guarded, because those get committed.

CLAUDE.md and AGENTS.md get extra-strict checks. In those files any credential-named assignment with a random-looking value (api_key: "q8Zr…") is blocked too. The deny reason also tells Claude why: these files are often committed and public, and in a public sample of 25,784 CLAUDE.md files, 275 contained real-looking secrets.

Run /secret-guard to see how many secrets it has blocked so far, broken down by type.

Install

claude --plugin-dir ./secret-guard

or add this repo as a marketplace and install it with /plugin.

Options

None. The rules live in hooks/detect.ts. Each one is a regex for a format a real service issues, followed by placeholder checks.

How it works

A tool.call hook reads the text a file tool is about to write, or the files a Bash command redirects into, and runs the detector on it. If anything new turns up, it answers { deny } so the tool never runs. The running count is kept in $.store.

获取徽章

这是你的项目吗?把这个徽章放进 README 或网站,链接回本页。

Featured on ClaudeMods
尺寸
配色
Markdown
HTML

其他同名作品

更多类似作品