omegaleo/SecretSecurity

GitHub: omegaleo/SecretSecurity

一款 .NET CLI 机密扫描工具,通过 Git pre-commit hook 在提交时检测并阻止 API key、token 等敏感凭证被意外提交到代码仓库。

Stars: 0 | Forks: 0

# SecretSecurity [![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?logo=github)](https://github.com/sponsors/omegaleo) [![Ko-fi](https://img.shields.io/badge/Ko--fi-Support%20me-FF5E5B?logo=ko-fi&logoColor=white)](https://ko-fi.com/omegaleo) 一款 .NET CLI 工具,用于扫描暂存的 git 更改中的机密信息、API key、token 和敏感凭证 —— 并在检测到严重发现时阻止提交。 ## 检测内容 | 类型 | 示例 | 严重程度 | |------|----------|----------| | Provider token | AWS access key (`AKIA…`)、Stripe live key (`sk_live_…`)、GitHub PAT (`ghp_…`)、Slack token | 严重 | | 私钥 | RSA、EC、OpenSSH 私钥块 | 严重 | | Azure 连接字符串 | `DefaultEndpointsProtocol`、`AccountKey` | 严重 | | 显式机密赋值 | 带有值的 `api_key=`、`token=`、`secret:` | 高 | | 数据库连接字符串 | 常规 ADO.NET、Postgres/MySQL/MongoDB/Redis URL | 高 | | 可疑 blob | 可疑上下文中的高熵字符串 | 警告 | 开发安全的连接(localhost、127.0.0.1、集成安全)会被自动忽略。 ## 安装说明 要求 [.NET 10 SDK](https://dotnet.microsoft.com/download) 或更高版本。 ``` dotnet tool install --global SecretSecurity ``` ## 用法 ### 安装 pre-commit hook 在你的 repository 中运行一次: ``` secretsecurity install ``` 这会将一个 `pre-commit` hook 写入 `.git/hooks/`,它会在每次提交时自动运行 `secretsecurity scan`。 ### 手动扫描 ``` secretsecurity scan ``` 扫描所有当前暂存的更改(`git diff --cached`)。如果发现任何高或严重级别的结果,将以代码 `1` 退出,从而阻止提交。 ### 忽略文件 在你的 repo 根目录下创建一个 `.secretsecurityignore` 文件,每行一个 pattern: ``` tests/fixtures/ mock_secrets.json ``` 任何路径包含所列 pattern 的暂存文件都将被跳过。 ## 工作原理 1. 运行 `git diff --cached -U0` 以仅获取你即将提交的行。 2. 根据按置信度排序的一组已编译 regex pattern 检查每个新增的行。 3. 匹配到的值在输出中会被部分掩码处理(例如 `ghp_****Ab`)。 4. 如果任何发现的结果为高或严重级别,扫描将以代码 `1` 退出,从而阻止提交。 ## 从源码构建 ``` git clone https://github.com/omegaleo/SecretSecurity.git cd SecretSecurity dotnet build dotnet run --project SecretSecurity -- scan ``` ## 许可证 MIT — 详情请参阅 [LICENSE.md](LICENSE)。
标签:Git钩子, StruQ, 多人体追踪