ShriD5/claude-mods/tree/main/secret-guard
secret-guard
透過 tool.call hook 阻擋 Write、Edit、MultiEdit、NotebookEdit 與 Bash 重新導向把看似真實的憑證寫入檔案,同時允許佔位符、開發預設值與 .env 檔案。
關於這個 mod
secret-guard 加入 tool.call hook,檢查檔案工具即將寫入的文字,以及 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-…, legacysk-…), and other longsk-…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
localhostor a docker service name, documentation hosts likeexample.com, and default passwords likepostgres:postgres. - Secrets the file already holds: editing next to an existing key isn't blocked.
- Env files:
.env,.env.local,.env.productionand.dev.vars, which is where the deny message tells Claude to put secrets..env.example,.env.sampleand.env.templateare 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 或網站,連回本頁。
其他同名作品
- secret-guarddavidho27941 · ★ 1
- secret-guard0xGondarxyz · ★ 0
