secret-scan-gitleaks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSecret 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 (or download from GitHub releases)
brew install gitleaks - Verify:
gitleaks version
- 已安装Gitleaks(或从GitHub发布版下载)
brew install gitleaks - 验证安装:
gitleaks version
Instructions
操作步骤
-
Identify the target — Determine the repository or directory to scan.
-
Run the scan:Scan current state (no git history):bash
gitleaks detect --source=<path> --no-git --report-format=json --report-path=gitleaks-results.jsonScan git history:bashgitleaks 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
- Verbose output: add
-
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.
- 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 / vault
.env - Suggest adding allowlist for false positives
.gitleaks.toml
-
确定目标 —— 确定要扫描的仓库或目录。
-
运行扫描:扫描当前状态(不包含Git历史):bash
gitleaks detect --source=<path> --no-git --report-format=json --report-path=gitleaks-results.json扫描Git历史:bashgitleaks detect --source=<path> --report-format=json --report-path=gitleaks-results.json- 详细输出:添加 参数
--verbose - 自定义配置:
--config=<path-to-.gitleaks.toml> - 仅扫描暂存的更改:
gitleaks protect --staged --report-format=json
- 详细输出:添加
-
解析结果 —— 读取JSON输出并展示检测结果:
| 序号 | 规则 | 密钥(已脱敏) | 文件:行号 | 提交记录 | 作者 | 日期 |
|---|------|--------------------|-----------|--------|--------|------|重要提示: 始终对密钥值进行脱敏处理——仅显示前4位和后2位字符。
- 总结 —— 提供以下内容:
- 按类型统计的总密钥数量(API密钥、密码、令牌等)
- 哪些密钥存在于当前代码中,哪些仅存在于Git历史中
- 修复建议:轮换密钥、从代码中移除、添加到 / 密钥管理库
.env - 建议添加 白名单以处理误报
.gitleaks.toml