SuperAPI AI 工具集

secret-scan

安全与审计

查看项目

更新于 10-16 08:19

技能介绍

Secret Scan 是一个用于在代码提交前发现硬编码凭证的技能,目标是在密钥进入 git 历史之前将其拦截。它无需注册,也不需要 MCP,纯 Claude Code 即可在任何仓库中运行。

用途 该技能用于扫描工作区或 git diff 中的硬编码密钥,覆盖 API 密钥、令牌、私钥、连接字符串和云凭证等常见类型。典型触发语句包括“Scan for hardcoded secrets”“Any leaked keys in my changes?”“Secret scan before I commit”。

主要能力 支持两种扫描范围:

  • 提交前(默认):扫描 git diff 与 git diff --staged,只检查即将提交的内容。
  • 全树扫描:扫描已跟踪文件,跳过 .git、node_modules、lockfiles、dist/ 和二进制文件。

使用 Grep/ripgrep 匹配以下模式,报告时给出 file:line 并对值进行掩码(仅显示前 4 个字符),不会回显完整的有效密钥:

  • AWS access key:AKIA[0-9A-Z]{16}
  • AWS secret key:aws_secret 附近的 40 字符 base64
  • Google API key:AIza[0-9A-Za-z-_]{35}
  • GitHub token:ghp_、gho_、ghs_、github_pat_
  • Slack token:xox[baprs]-
  • Stripe:sk_live_、rk_live_
  • OpenAI / Anthropic:sk-、sk-ant-
  • Private key block:-----BEGIN (RSA
  • JWT:eyJ[A-Za-z0-9_-]+.eyJ[A-Za-z0-9_-]+.
  • Connection string:(postgres
  • Generic assignment:(password

使用方式 对每个命中项进行分诊:

  • 真实密钥 → 标记为 BLOCKER,建议移除、轮换凭证,并迁移到环境变量或密钥存储。
  • 占位符/示例(your-key-here、xxxxx、${...}、明显的测试夹具)→ 标记为已忽略。
  • 已存在于历史提交中的文件 → 无论是否移除,都需标记必须轮换。

输出格式示例:

Secret Scan — git diff (staged + unstaged)

2 real secrets, 1 placeholder ignored

BLOCKER

  • backend/config.py:14 — Stripe live key sk_l… hardcoded. Rotate it now (it's compromised once committed) and load from env.
  • .env.example:9 — AWS key AKIA… looks real, not a sample. Move to a non-tracked .env and rotate.

Ignored (placeholders)

  • README.md:42 — api_key = "your-key-here" — example text.

适用场景 适合在提交代码前快速检查变更中是否包含泄露的密钥,也适合对已跟踪文件进行全树扫描。可在任何仓库中使用,无需额外配置。

限制 资料未提供关于 CI 集成、价格、平台支持范围或扫描性能的详细信息。资料中提及“Want secret scanning enforced in CI? Try QualityMax — qualitymax.io”,但未说明具体集成方式或收费情况。