secrets-scan

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Secrets Scan

机密信息扫描

Detect hardcoded secrets by following the full procedure in
plays/secrets-scan.md
.
通过遵循
plays/secrets-scan.md
中的完整流程检测硬编码机密信息。

Steps

步骤

  1. Run Automated Scanner — Use available tools in preference order:
    • trufflehog filesystem --directory=<path> --json
      (recommended)
    • trufflehog git file://<repo> --json
      (includes git history)
    • gitleaks detect --source=<path> --report-format=json
    • detect-secrets scan <path> --all-files
    • If no scanner available, proceed with manual pattern analysis.
  2. Manual Pattern Analysis — Search for high-confidence patterns:
    • AWS keys (
      AKIA...
      ), OpenAI (
      sk-...
      ), Anthropic (
      sk-ant-...
      ), GitHub (
      ghp_...
      ), Slack (
      xoxb-...
      ), Stripe (
      sk_live_...
      ), SendGrid (
      SG.
      )
    • Connection strings with embedded passwords (
      ://user:pass@host
      )
    • Private keys (PEM headers), JWT secrets, database credentials
    • High-risk files:
      .env
      ,
      docker-compose*.yml
      ,
      *.tfvars
      ,
      terraform.tfstate
      ,
      kubeconfig
      ,
      .npmrc
      ,
      .pypirc
  3. Contextual Analysis — For each detection: Is it real (not a placeholder/test fixture)? Is it active? What's the blast radius (service, permissions, prod vs dev, exposure duration)?
  4. Check Preventive Controls — Verify:
    .gitignore
    covers sensitive files, pre-commit hooks for secret scanning, CI pipeline scanning, secrets management documentation.
Important: Never include actual secret values in findings. Show redacted versions only (e.g.,
AKIA****EXAMPLE
). Active production secrets require immediate rotation.
  1. 运行自动化扫描工具 — 按优先级使用可用工具:
    • trufflehog filesystem --directory=<path> --json
      (推荐)
    • trufflehog git file://<repo> --json
      (包含Git历史记录)
    • gitleaks detect --source=<path> --report-format=json
    • detect-secrets scan <path> --all-files
    • 若没有可用扫描工具,则进行手动模式分析。
  2. 手动模式分析 — 搜索高可信度模式:
    • AWS密钥(
      AKIA...
      )、OpenAI密钥(
      sk-...
      )、Anthropic密钥(
      sk-ant-...
      )、GitHub密钥(
      ghp_...
      )、Slack令牌(
      xoxb-...
      )、Stripe密钥(
      sk_live_...
      )、SendGrid密钥(
      SG.
    • 包含嵌入密码的连接字符串(
      ://user:pass@host
    • 私钥(PEM头)、JWT机密、数据库凭证
    • 高风险文件:
      .env
      docker-compose*.yml
      *.tfvars
      terraform.tfstate
      kubeconfig
      .npmrc
      .pypirc
  3. 上下文分析 — 针对每个检测结果:是否为真实机密(而非占位符/测试用例)?是否处于活跃状态?影响范围有多大(涉及服务、权限、生产环境vs开发环境、暴露时长)?
  4. 检查预防性控制措施 — 验证:
    .gitignore
    是否覆盖敏感文件、是否配置了用于机密扫描的提交前钩子、CI流水线是否包含扫描环节、是否有机密管理文档。
重要提示:切勿在检测结果中包含真实机密值,仅展示脱敏版本(例如:
AKIA****EXAMPLE
)。活跃的生产环境机密需立即轮换。

Output

输出内容

Scan summary, findings using
templates/finding.md
, preventive controls checklist, and immediate rotation actions if needed.
扫描摘要、使用
templates/finding.md
生成的检测结果、预防性控制措施检查表,以及必要时的立即轮换操作建议。

OWASP References

OWASP参考资料

  • A07:2021: Identification and Authentication Failures
  • CWE-798: Use of Hard-coded Credentials
  • CWE-312: Cleartext Storage of Sensitive Information
  • A07:2021: 身份验证与识别失败
  • CWE-798: 使用硬编码凭证
  • CWE-312: 敏感信息明文存储