BarakMozesPro/secureflow-secrets
GitHub: BarakMozesPro/secureflow-secrets
基于Go的高性能机密检测引擎,支持多种编码格式和Git历史扫描,防止敏感凭证泄露到代码仓库。
Stars: 0 | Forks: 0
# SecureFlow Secrets — 高性能机密检测引擎
[](https://github.com/BarakMozesPro/secureflow-secrets/actions/workflows/ci.yml)
[](https://go.dev)
[](LICENSE)
## 架构
```
flowchart LR
A[Git Repo\nFiles\nStdin] --> B[Source Adapter]
B --> C[Detection Engine]
C --> D[Codec Decoders\nbase64 / hex / unicode]
D --> E[Rule Matcher\nAho-Corasick + Regex]
E --> F{Secret Found?}
F -->|yes| G[Finding]
F -->|no| H[Clean]
G --> I[Reporter]
I --> J[SARIF\nJSON\nCSV\nJUnit]
```
## 功能特性
- **131 条特定于服务商的规则** — AWS, GCP, Azure, GitHub, Stripe, Slack 等
- **编解码感知** — 检测以 base64、hex 或 unicode 编码的机密信息
- **Aho-Corasick 多模式匹配** — 高吞吐量扫描,CPU 开销极低
- **Git 历史扫描** — 遍历每一个 commit、branch 和 tag
- **SARIF 输出** — 集成 GitHub Code Scanning 和 IDE 工具
- **允许列表抑制** — 通过路径、commit 或正则表达式允许列表抑制误报
- **Pre-commit hook 支持** — 在机密信息推送到远程仓库之前进行拦截
- **多种输入模式** — `detect` (文件/git), `protect` (stdin), `git` (git log)
## 快速开始
```
# 扫描当前 git repo
secureflow-secrets detect
# 扫描特定目录
secureflow-secrets detect --source ./src
# 扫描 stdin (pre-commit / pipe)
git diff --staged | secureflow-secrets protect
# 为 GitHub Code Scanning 输出 SARIF
secureflow-secrets detect --report-format sarif --report-path results.sarif
```
## 安装说明
```
go install github.com/BarakMozesPro/secureflow-secrets@latest
```
或者从源码构建:
```
git clone https://github.com/BarakMozesPro/secureflow-secrets
cd secureflow-secrets
go build -o secureflow-secrets .
```
## 配置
在你的代码库根目录下放置一个 `.gitleaks.toml` 文件(或传递 `--config` 参数):
```
[allowlist]
description = "Global allowlist"
paths = ['''go\.sum''']
regexes = ['''EXAMPLE_KEY_[A-Z0-9]+''']
```
## 我学到的内容
构建这个项目让我掌握了两种强大的 Go 并发模式:
1. **用于并发扫描的 Go channel 管道** — 检测引擎通过缓冲 channel 将文件片段分发给 worker goroutine。每个 goroutine 独立应用编解码和正则匹配,然后通过收集器 channel 回传结果。这完全消除了锁的使用,并且随 CPU 核心数线性扩展。
2. **Aho-Corasick 多模式匹配** — 引擎不再顺序运行 131 条正则规则,而是首先使用 Aho-Corasick 自动机过滤片段,该自动机能同时扫描所有关键词提示。只有匹配到关键词提示的片段才会进入开销更大的完整正则评估阶段。这能在干净的代码库上减少 90% 以上的正则处理工作。
## 项目结构
```
secureflow-secrets/
├── cmd/ # CLI commands (detect, protect, git)
│ └── generate/config/ # Rule generation utilities
│ └── rules/ # 131 provider rule definitions
├── config/ # Configuration structs, allowlists, TOML parser
├── detect/ # Core detection engine
│ └── codec/ # base64, hex, unicode decoders
├── report/ # SARIF, JSON, CSV, JUnit reporters
├── sources/ # Git, file, stdin source adapters
└── testdata/ # Test fixtures and configs
```
## 致谢
本项目基于 Zachary Rice 开发的 **[Gitleaks](https://github.com/gitleaks/gitleaks)** 构建,采用 [MIT License](LICENSE) 发布。Gitleaks 是业界标准的机密检测工具,受数千个安全团队信赖,并集成于主流 CI/CD 平台。
*SecureFlow Secrets — 让你的凭证留在该留的地方:而不是在 git 里。*
标签:Aho-Corasick算法, API密钥检测, AWS密钥, Base64解码, DevSecOps, EVTX分析, Go, Golang, Python安全, Ruby工具, SARIF, StruQ, 上游代理, 云计算, 信息防止, 安全助手, 安全编程, 日志审计, 秘密检测, 网络安全研究, 聊天机器人, 规则引擎, 输入验证, 错误基检测, 静态代码分析, 高并发