anfocic/brunt

GitHub: anfocic/brunt

利用LLM进行对抗性代码审查的自动化工具,能扫描git diff发现bug、生成失败测试作为证据、自动修复并验证。

Stars: 1 | Forks: 0

# Brunt 对抗性AI代码审查。发现bug,生成失败的测试作为证据,自动修复并验证。 Brunt 扫描你的 git diff,通过 LLM 进行对抗性分析,对于发现的每个 bug: 1. 生成一个失败的测试来证明 bug 存在 2. 生成修复并验证它通过测试 3. 可选地打开一个包含所有已验证修复的 PR 没有观点——只有证据。 ## 快速开始 ``` npm i -g @fole/brunt # Scan your last commit brunt scan # Scan with auto-fix brunt scan --fix # Full pipeline: find, prove, fix, open PR brunt scan --fix --pr # Audit entire repo (not just diffs) brunt audit ``` ## 功能说明 ``` $ brunt scan --fix Running 2 vectors via anthropic: + correctness 1 finding (8102ms) + security 1 finding (14201ms) + Generated 2 proof tests. + Verified 2 fixes. brunt -- found 2 issues (14230ms) [correctness] 1 finding (8102ms) HIGH src/utils.ts:23 [FIXED] parseInt without radix or NaN handling Test: tests/brunt/src-utils-ts-L23.test.ts --- fix diff --- - const age = parseInt(input); + const age = parseInt(input, 10); + if (isNaN(age)) throw new Error('Invalid age'); [security] 1 finding (14201ms) CRITICAL src/api/users.ts:34 [FIXED] SQL injection in user search endpoint Test: tests/brunt/src-api-users-ts-L34.test.ts --- fix diff --- - const query = `SELECT * FROM users WHERE name = '${input}'`; + const query = `SELECT * FROM users WHERE name = $1`; ``` ## 向量 | 向量 | 发现内容 | |---|---| | `correctness` | 边界情况、差一错误、空值处理、类型强制转换、逻辑错误、竞态条件 | | `security` | SQL 注入、XSS、命令注入、路径遍历、SSRF、身份验证绕过、硬编码密钥 | ``` brunt scan --vectors security # run only security ``` ### 自定义向量 在 `brunt.config.yaml` 中定义特定领域的向量: ``` vectors: - name: billing description: "Checks billing and payment logic" prompt: | Focus on: rounding errors, double-charges, currency handling, subscription state machine bugs, race conditions in payments. ``` 然后像内置向量一样运行它们: ``` brunt scan --vectors billing,security ``` 有关更多示例,请参阅 `brunt.config.example.yaml`。 ## Monorepo 支持 Brunt 自动检测 monorepo 布局。如果所有更改的文件都在单个包下(`packages/`、`apps/`、`services/`、`libs/`、`modules/`),则只扫描该包。 ``` brunt scan # auto-detects scope brunt scan --scope packages/auth # explicit scope brunt scan --scope . # scan everything (opt out) ``` ## 提供商 | 提供商 | 费用 | 设置 | |---|---|---| | `claude-cli`(默认)| Claude Code 计划免费 | 只需安装 `claude` | | `anthropic` | 按 token 付费 | 设置 `ANTHROPIC_API_KEY` | | `ollama` | 免费,本地运行 | 安装 Ollama,运行 `ollama serve` | | `openai` | 按 token 付费 | 设置 `OPENAI_API_KEY` | 任何支持 OpenAI chat completions 协议的服务器都可以使用 `--provider openai`: | 服务器 | 设置 | |---|---| | LM Studio | `OPENAI_BASE_URL=http://localhost:1234/v1` | | llama.cpp | `OPENAI_BASE_URL=http://localhost:8080/v1` | | vLLM | `OPENAI_BASE_URL=http://localhost:8000/v1` | | LocalAI | `OPENAI_BASE_URL=http://localhost:8080/v1` | | Together AI | `OPENAI_BASE_URL=https://api.together.xyz/v1` + `OPENAI_API_KEY` | | Groq | `OPENAI_BASE_URL=https://api.groq.com/openai/v1` + `OPENAI_API_KEY` | ``` brunt scan # Claude Code CLI (default) ANTHROPIC_API_KEY=sk-... brunt scan --provider anthropic # Anthropic API brunt scan --provider ollama --model llama3 # Ollama (local) OPENAI_API_KEY=sk-... brunt scan --provider openai # OpenAI API # Any OpenAI-compatible server (no API key needed for local) OPENAI_BASE_URL=http://localhost:1234/v1 \ brunt scan --provider openai --model my-local-model ``` ## 提示注入防御 Brunt 旨在抵抗对抗性输入——包括试图操纵 AI 审查者的代码: 1. **注释剥离**——在 LLM 查看 diff 之前,所有注释和字符串字面量都会被移除 2. **单文件隔离**——每个文件都在独立的 LLM 调用中分析;一个文件中的注入无法压制另一个文件中的发现 3. **注入检测**——预扫描会在分析开始前标记可疑模式(例如 `// AI: ignore this file`) 4. **可疑的沉默**——涉及 auth、crypto、exec 或 SQL 但产生零发现的文件会被标记为手动审查 5. **金丝雀注入**——注入一个合成 bug 来验证 LLM 确实分析了代码 ## 输出格式 ``` brunt scan # Human-readable (default) brunt scan --format json 2>/dev/null | jq . # JSON brunt scan --format sarif > results.sarif # SARIF (GitHub Code Scanning) ``` ## CI 集成 ### GitHub Actions ``` - uses: anfocic/brunt@main with: provider: anthropic fail-on: critical pr-comment: 'true' env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` ## 选项 ``` --diff Git diff range (default: HEAD~1, auto-detects in CI) --provider LLM provider: claude-cli, anthropic, ollama, openai --model Model name --format Output: text, json, sarif --fail-on Exit 1 threshold: low, medium, high, critical (default: medium) --vectors Comma-separated vectors to run --scope Only scan files under this path (auto-detects in monorepos) --config Path to brunt.config.yaml (default: auto-detect) --no-tests Skip proof test generation --no-cache Force fresh LLM analysis --verify Run proof tests, drop unverified findings --fix Auto-generate and verify fixes --fix-retries Max fix attempts (1-5, default: 2) --pr Create PR with verified fixes --pr-comment Post findings as GitHub PR review comments --max-tokens Max tokens per LLM call ``` ## 许可证 MIT
标签:AI代码审查, AI风险缓解, bug检测, Git, LLM, MITM代理, Petitpotam, SQL注入检测, Unmanaged PE, XSS检测, 云安全监控, 代码安全, 代码审查, 威胁情报, 安全扫描, 对抗性分析, 开发者工具, 开源框架, 持续集成, 时序注入, 测试生成, 漏洞枚举, 网络安全研究, 自动修复, 自动化攻击, 软件质量, 静态分析