secret-scan-gitleaks

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Secret Scanning with Gitleaks

使用Gitleaks进行密钥扫描

You are a security engineer running secret detection using Gitleaks to find hardcoded secrets, API keys, tokens, and credentials in code.
你是一名安全工程师,正在使用Gitleaks进行密钥检测,以查找代码中的硬编码密钥、API密钥、令牌和凭据。

When to use

适用场景

Use this skill when asked to scan for secrets, credentials, or API keys in a codebase or git history.
当需要扫描代码库或Git历史记录中的密钥、凭据或API密钥时,使用此技能。

Prerequisites

前提条件

  • Gitleaks installed (
    brew install gitleaks
    or download from GitHub releases)
  • Verify:
    gitleaks version
  • 已安装Gitleaks(
    brew install gitleaks
    或从GitHub发布版下载)
  • 验证安装:
    gitleaks version

Instructions

操作步骤

  1. Identify the target — Determine the repository or directory to scan.
  2. Run the scan:
    Scan current state (no git history):
    bash
    gitleaks detect --source=<path> --no-git --report-format=json --report-path=gitleaks-results.json
    Scan git history:
    bash
    gitleaks detect --source=<path> --report-format=json --report-path=gitleaks-results.json
    • Verbose output: add
      --verbose
    • Custom config:
      --config=<path-to-.gitleaks.toml>
    • Scan staged changes only:
      gitleaks protect --staged --report-format=json
  3. Parse the results — Read JSON output and present findings:
| # | Rule | Secret (redacted) | File:Line | Commit | Author | Date |
|---|------|--------------------|-----------|--------|--------|------|
IMPORTANT: Always redact secret values — show only first 4 and last 2 characters.
  1. Summarize — Provide:
    • Total secrets found by type (API key, password, token, etc.)
    • Which secrets are in current code vs only in git history
    • Remediation: rotate secret, remove from code, add to
      .env
      / vault
    • Suggest adding
      .gitleaks.toml
      allowlist for false positives
  1. 确定目标 —— 确定要扫描的仓库或目录。
  2. 运行扫描:
    扫描当前状态(不包含Git历史):
    bash
    gitleaks detect --source=<path> --no-git --report-format=json --report-path=gitleaks-results.json
    扫描Git历史:
    bash
    gitleaks detect --source=<path> --report-format=json --report-path=gitleaks-results.json
    • 详细输出:添加
      --verbose
      参数
    • 自定义配置:
      --config=<path-to-.gitleaks.toml>
    • 仅扫描暂存的更改:
      gitleaks protect --staged --report-format=json
  3. 解析结果 —— 读取JSON输出并展示检测结果:
| 序号 | 规则 | 密钥(已脱敏) | 文件:行号 | 提交记录 | 作者 | 日期 |
|---|------|--------------------|-----------|--------|--------|------|
重要提示: 始终对密钥值进行脱敏处理——仅显示前4位和后2位字符。
  1. 总结 —— 提供以下内容:
    • 按类型统计的总密钥数量(API密钥、密码、令牌等)
    • 哪些密钥存在于当前代码中,哪些仅存在于Git历史中
    • 修复建议:轮换密钥、从代码中移除、添加到
      .env
      / 密钥管理库
    • 建议添加
      .gitleaks.toml
      白名单以处理误报