DevenderSEO/leaklatch

GitHub: DevenderSEO/leaklatch

一款面向 TypeScript/Node 的 Git pre-commit 密钥泄露防护工具,通过扫描暂存差异在提交前拦截敏感信息。

Stars: 23 | Forks: 5

# 🔒 leaklatch [![npm version](https://img.shields.io/npm/v/leaklatch.svg)](https://www.npmjs.com/package/leaklatch) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/DevenderSEO/leaklatch/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE) [![Node](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg)](https://nodejs.org) [![Website](https://img.shields.io/badge/website-leaklatch.click-4f46e5.svg)](https://leaklatch.click) leaklatch 可以防止 API key、token 和 `.env` 文件进入你的 git 历史记录。它只在每次提交时扫描**已暂存的 diff**,因此速度足够快,完全 不会碍事——而且其分层检测机制意味着它不会对代码库中的 每一个 base64 字符串大惊小怪。 ``` $ git commit -m "add billing" ✖ leaklatch: 1 potential secret detected src/stripe.ts CRITICAL stripe-secret-key src/stripe.ts:12 match: sk************34 fix: Roll the key in the Stripe dashboard immediately. commit aborted. ``` ## 30秒快速入门 ``` # 在你的 repo 中安装 pre-commit hook(无需全局安装) npx leaklatch install # 就是这样。现在每次 commit 都会扫描 staged changes。 # 随时运行一次性扫描: npx leaklatch scan ``` 想作为开发依赖安装? ``` npm install --save-dev leaklatch npx leaklatch install ``` ## 为什么选择 leaklatch?(与现有工具的对比) 老牌的扫描器都是非常优秀且广泛的工具——但它们是为另一种 环境编写的(Go/Python 二进制文件、全库扫描、配置繁重)。leaklatch 专为 **TypeScript 开发者的核心开发流程**打造:零配置、原生支持 `npx`, 并经过调优,除非真的出了问题,否则它会保持安静。 | | **leaklatch** | gitleaks | detect-secrets | trufflehog | |---|:---:|:---:|:---:|:---:| | 原生支持 TS/Node,`npx` 安装 | ✅ | ❌ (Go) | ❌ (Python) | ❌ (Go) | | 零配置默认值 | ✅ | ⚠️ | ⚠️ (需要基线) | ⚠️ | | 扫描**已暂存的 diff** 以实现快速 pre-commit | ✅ | ✅ | ⚠️ | ⚠️ | | 分层误报过滤 | ✅ | ⚠️ (正则表达式+熵值) | ✅ (插件) | ⚠️ | | 内联 `# leaklatch-ignore` 指令 | ✅ | ✅ | ⚠️ | ❌ | | 用于逐步采用的指纹基线 | ✅ | ✅ | ✅ | ❌ | | 在输出中脱敏 secret 值 | ✅ | ⚠️ | ✅ | ⚠️ | | 编程 API (`import { scan }`) | ✅ | ❌ | ⚠️ | ❌ | ## 为什么误报率低? 仅靠正则表达式的扫描器会标记任何_看起来_像 secret 的内容。在成为 最终的发现之前,leaklatch 会通过**分层验证**运行每个候选项: 1. **严格的前缀锚定规则。** 当凭证具有特定前缀(`ghp_`, `sk-ant-`, `AKIA…`, `sk_live_`)时,规则会强制要求——绝不 仅凭形式来猜测。 2. **基于规则的香农熵阈值。** 通用赋值(`API_KEY=…`)必须 越过熵值阈值,因此 `API_KEY=changeme` 永远不会触发警报。 3. **占位符与上下文过滤器。** 已知的占位符(`xxxx`, `changeme`, `your-key-here`, ``, `${VAR}`)、示例值以及测试/fixture 路径 都会被识别并跳过。 4. **字符类检查。** 一个长的小写单词并不会仅仅因为它 很长就被认为是 secret;真正的凭证材料会混合使用不同的字符类。 5. **去重。** 匹配多个规则的单个泄露值仅会 报告**一次**,且归在最具体的规则下。 结果就是:对真实凭证具有高召回率,对其他一切保持低噪音。 ## 命令 ### `leaklatch scan` 扫描 secret。默认为**已暂存的更改**(pre-commit 路径)。 ``` leaklatch scan # scan staged diff (default) leaklatch scan --all # scan all tracked files (CI mode) leaklatch scan --json # machine-readable output for CI leaklatch scan --verbose # show line preview, entropy, fingerprints leaklatch scan --quiet # print nothing when clean leaklatch scan --no-color # disable ANSI colors leaklatch scan --no-baseline # ignore the baseline file for this run leaklatch scan --update-baseline # accept current findings into the baseline ``` 退出代码:`0` 干净 · `1` 发现问题 · `2` 不是 git 仓库。 ### `leaklatch install` / `leaklatch uninstall` 安装(或移除)git 的 `pre-commit` 钩子。安装是**追加安全的**: 如果你已经有一个 `pre-commit` 钩子(包括 husky),leaklatch 会插入一个 明确分隔的区块,并保持其余部分原封不动。卸载只会移除 该区块。 ``` leaklatch install leaklatch uninstall ``` ## 配置(可选——leaklatch 默认为零配置) 在你的仓库根目录放置一个 `leaklatch.config.json`(或 `.leaklatchrc`): ``` { "ignorePaths": ["test/fixtures", "docs/**"], "disabledRules": ["jwt"], "entropyOverrides": { "generic-assignment": 4.0 }, "genericEntropyThreshold": 4.0, "disableGenericEntropy": false, "customRules": [ { "id": "acme-internal-token", "regex": "ACME-[A-Z0-9]{20}", "severity": "high", "remediation": "Rotate the ACME token in the internal console." } ] } ``` | 字段 | 用途 | |---|---| | `ignorePaths` | 要完全跳过的路径子字符串或 globs (`*`, `**`)。 | | `disabledRules` | 要关闭的规则 ID。 | | `entropyOverrides` | 按规则 ID 索引的每规则熵值阈值。 | | `genericEntropyThreshold` | 通用高熵检测器的下限。 | | `disableGenericEntropy` | 关闭通用熵检测器。 | | `customRules` | 你自己的正则表达式规则(必须包含 `id` + `regex`)。 | ### 内联忽略 ``` const token = process.env.LEGACY_TOKEN ?? 'sk_live_...'; // leaklatch-ignore // leaklatch-ignore-next-line const anotherKnownSafeValue = '...'; ``` ### 基线(在现有仓库中采用) 已经有今天无法修复的发现?将它们接受到基线中,这样它们就 不再阻止提交,同时任何**新**的 secret 依然会被捕获: ``` leaklatch scan --all --update-baseline # writes .leaklatch-baseline.json git add .leaklatch-baseline.json ``` ## CI:GitHub Actions leaklatch 提供了对自我扫描友好的 JSON 模式。将以下内容放入 `.github/workflows/secrets.yml`: ``` name: secret-scan on: [push, pull_request] jobs: leaklatch: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 20 - run: npx leaklatch scan --all --no-color ``` 发现 secret 时,退出代码 `1` 会导致任务失败。 ## 编程 API ``` import { scan, detectLines } from 'leaklatch'; const result = scan({ all: true }); if (result.findings.length > 0) { for (const f of result.findings) { console.log(`${f.file}:${f.line} ${f.ruleId} ${f.match}`); } } // Or run the pure detector over your own lines: const findings = detectLines([{ file: 'a.ts', line: 1, content: 'API_KEY=...' }]); ``` ## 检测内容 AWS 访问密钥和秘密密钥 · GitHub token(`ghp_`, `gho_`, `github_pat_`)· OpenAI (`sk-`) · Anthropic (`sk-ant-`) · Google API key · Stripe 实时密钥 · Slack token 和 webhook · 私钥区块 · JWT · npm token · 通用的 `KEY`/`SECRET`/`TOKEN`/`PASSWORD` 赋值 · 提交的 `.env` 文件 · 通用高熵字符串。 查看 [`ROADMAP.md`](./ROADMAP.md) 了解接下来的计划,以及 查看 [`ISSUES.md`](./ISSUES.md) 寻找适合新手的简单问题。 ## 许可证 [MIT](./LICENSE) © Deven Aggarwal
标签:MITM代理, Redis利用, 暗色界面, 自动化攻击