git-secrets-scannerGit 安全扫描器 - 检查提交中的敏感信息泄露(API keys、密码、token)
Install via ClawdBot CLI:
clawdbot install guohongbin-git/git-secrets-scanner检查提交中的敏感信息泄露。
| 工具 | Stars | 特点 |
|------|-------|------|
| Gitleaks | 24,958 | 最流行,Go 编写,快速 |
| TruffleHog | 24,612 | 验证 secrets,支持多种格式 |
| git-secrets | 13,173 | AWS 官方,pre-commit hook |
# macOS
brew install gitleaks
# Linux
# 从 https://github.com/gitleaks/gitleaks/releases 下载
# 或使用 Go
go install github.com/gitleaks/gitleaks/v8@latest
# macOS
brew install trufflehog
# Linux
# 从 https://github.com/trufflesecurity/trufflehog/releases 下载
# 或使用 Docker
docker pull trufflesecurity/trufflehog:latest
# macOS
brew install git-secrets
# Linux
git clone https://github.com/awslabs/git-secrets.git
cd git-secrets
sudo make install
# Gitleaks
gitleaks detect --source . -v
# TruffleHog
trufflehog git file://. --only-verified
# git-secrets(需要先设置 hook)
git secrets --scan-history
# Gitleaks
gitleaks detect --source . --log-opts="HEAD~1..HEAD"
# TruffleHog
trufflehog git file://. --commit=HEAD
# Gitleaks
gitleaks detect --source . --log-opts="--all"
# TruffleHog
trufflehog git file://. --no-deletion
# git-secrets
cd your-repo
git secrets --install
git secrets --register-aws
# .github/workflows/security.yml
name: Security Scan
on: [push, pull_request]
jobs:
gitleaks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Finding: moltbook_sk_jX64MWE_yirqMSihBqb2B7slL64EygBt
Secret: moltbook_sk_jX64MWE_yirqMSihBqb2B7slL64EygBt
RuleID: generic-api-key
Entropy: 4.562345
File: memory/moltbook-art-of-focus-post.md
Line: 45
Commit: abc1234
Author: user@example.com
Date: 2026-02-19T03:11:00Z
Fingerprint: abc123...
# 添加到 .git/hooks/pre-commit
#!/bin/bash
gitleaks protect --staged
# 每周扫描
crontab -e
0 0 * * 0 cd /path/to/repo && gitleaks detect --source .
#!/bin/bash
for repo in ~/projects/*; do
echo "Scanning $repo..."
gitleaks detect --source "$repo" -v
done
如果发现泄露:
git push --force(谨慎使用)# 安装 BFG
brew install bfg
# 清理敏感文件
bfg --delete-files .env
# 清理敏感字符串
bfg --replace-text passwords.txt
# 强制推送
git push --force
title = "Custom Gitleaks Config"
[extend]
useDefault = true
[[rules]]
id = "moltbook-api-key"
description = "Moltbook API Key"
regex = '''moltbook_sk_[a-zA-Z0-9]{32}'''
tags = ["api-key", "moltbook"]
[allowlist]
paths = [
'''example\.txt''',
'''test/.*'''
]
版本: 1.0.0
工具: Gitleaks, TruffleHog, git-secrets
Generated Mar 1, 2026
A fintech company uses this skill to scan all git repositories for leaked API keys and tokens before each deployment, ensuring compliance with financial regulations like PCI-DSS. It integrates into CI/CD pipelines to automatically block commits containing sensitive data, preventing potential breaches and fines.
An e-commerce platform employs the scanner to monitor developer commits for exposed payment gateway keys (e.g., Stripe) and database credentials. Regular historical scans help identify and clean up past leaks, safeguarding customer data and maintaining trust.
A healthcare software provider implements pre-commit hooks with git-secrets to detect PHI-related secrets in code changes. This proactive approach helps meet HIPAA requirements by preventing accidental leaks of sensitive health information during development.
A SaaS startup uses Gitleaks to scan all git history for exposed cloud service keys (e.g., AWS, GitHub tokens) as part of their security onboarding. This reduces attack surfaces and educates developers on secure coding practices from day one.
A government agency integrates TruffleHog into their version control system to verify and scan for verified secrets in all projects. This ensures adherence to data protection laws and prevents unauthorized access to sensitive government infrastructure.
Offer a cloud-based service that integrates this scanning skill into developer workflows, providing dashboards and alerts for leaked secrets. Revenue comes from subscription tiers based on repository count and scanning frequency, targeting enterprises.
Provide professional services to help organizations set up and customize the scanner, including configuring rules and CI/CD pipelines. Revenue is generated through project-based fees and ongoing support contracts for maintenance.
Monetize by offering premium support, training workshops, and custom rule development for the open-source tools like Gitleaks. Revenue streams include training sessions, certification programs, and paid community access.
💬 Integration Tip
Start by adding a pre-commit hook with Gitleaks for immediate feedback, then integrate into CI/CD using the provided GitHub Actions example to automate scans on every push.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Query the DeepWiki MCP server for GitHub repository documentation, wiki structure, and AI-powered questions.
Automated GitHub PR code review with diff analysis, lint integration, and structured reports. Use when reviewing pull requests, checking for security issues,...
Essential Git commands and workflows for version control, branching, and collaboration.
Advanced git operations beyond add/commit/push. Use when rebasing, bisecting bugs, using worktrees for parallel development, recovering with reflog, managing subtrees/submodules, resolving merge conflicts, cherry-picking across branches, or working with monorepos.
Format commit messages using the Conventional Commits specification. Use when creating commits, writing commit messages, or when the user mentions commits, git commits, or commit messages. Ensures commits follow the standard format for automated tooling, changelog generation, and semantic versioning.