检测仓库中的密钥与敏感信息
gitleaks 扫描 Git 历史、工作区和暂存区中的密钥、token、私钥和密码模式,适合提交前检查和 CI 门禁。
gitleaks detect --source . --report-format json --report-path leaks.json
gitleaks detect --source . --no-git
gitleaks protect --staged
gitleaks git --log-opts="--since=2026-01-01"
gitleaks detect --baseline-path baseline.json
.gitleaks.toml:
[allowlist]
paths = [
'''docs/examples/.*''',
]
regexes = [
'''AKIAIOSFODNN7EXAMPLE''',
]
protect --staged 适合 pre-commit,但要确保钩子真正安装。git-filter-repo — 清理历史中的敏感文件pre-commit — 提交前钩子semgrep — 代码安全扫描