vipulawl/vibe-audit
GitHub: vipulawl/vibe-audit
一个针对 AI 构建应用的安全扫描器,用于检测硬编码密钥、注入漏洞等问题并生成修复提示。
Stars: 2 | Forks: 0
# vibe-audit
**针对AI构建应用的安全扫描器。** 可捕获硬编码密钥、注入漏洞、缺失速率限制、暴露的API密钥等问题——随后生成一份带评分的HTML仪表板,并为您的编码助手提供一键修复提示。
[](https://www.python.org/downloads/)
[](LICENSE)
[](https://github.com/vipulawl/vibe-audit/stargazers)
## 面临的问题
- GitHub中的API密钥会在几分钟内被机器人抓取
- 缺乏速率限制意味着有人可能一夜之间烧掉您500美元的OpenAI额度
- 调试用的 `print(api_key)` 永久遗留在服务器日志中
vibe-audit可在30秒内运行,并精确告知问题所在——以通俗易懂的英文呈现,并提供可直接粘贴到Claude、Cursor或Copilot中的修复提示。
## 演示
```
$ vibe-audit ./my-app
vibe-audit scanning /Users/you/my-app
✓ Secrets: 1 issue
✓ .env Leaks: clean
✓ Frontend Exposure: clean
✓ Injection (SQL/XSS/CMD): 3 issues
✓ Sensitive Logging: 2 issues
✓ Security Headers: 1 issue
✓ Rate Limiting: 1 issue
✓ Dependencies: clean
✓ Auth Issues: clean
Score: 34/100 (Grade F)
Issues: 8 total
Severity Category Title File
──────────────────────────────────────────────────────────────────────
CRITICAL Secrets OpenAI API Key (v2) detected config.py:12
HIGH Sensitive Log Sensitive value in log statement main.py:304
HIGH Rate Limiting No rate limiting detected .
...
✓ Report saved to security-report.html
Open it in your browser for the full dashboard with fix prompts.
```
然后打开 `security-report.html`:
每项发现都包含一个可供AI代理使用的 **复制粘贴提示**:
## 检查项目
| 类别 | 检测内容 |
|---|---|
| **密钥** | 硬编码API密钥(OpenAI、AWS、Stripe、GitHub、Google、Slack、Twilio)、密码、私钥、访问令牌 |
| **.env泄露** | 已提交至git的 `.env` 文件、未添加至 `.gitignore`、缺少 `.env.example`、子目录下的 `.env` 文件 |
| **前端暴露** | `.js`/`.ts`/`.html`文件中的API密钥、包含密钥的 `NEXT_PUBLIC_`/`VITE_`/`REACT_APP_` 变量 |
| **SQL/XSS注入** | f-string SQL查询、字符串拼接查询、使用变量的 `innerHTML`、`dangerouslySetInnerHTML`、`eval()`、Flask `render_template_string` |
| **命令注入** | 字符串拼接的 `subprocess`、`os.system`、Node.js `execSync`/`execFile`、`child_process.exec` |
| **敏感日志记录** | 在 `print()`、`logger.info()`、`console.log()` 中插入API密钥/令牌 |
| **安全头** | 缺失 `flask-talisman`、`helmet.js`、Next.js头配置、FastAPI中间件、Django `SECURE_*` 设置 |
| **速率限制** | 未实施速率限制的API路由(未检测到 `flask-limiter`、`slowapi`、`express-rate-limit`) |
| **依赖项** | 通过 `pip-audit`(Python)和 `npm audit`(Node)检测的已知CVE |
| **认证问题** | 弱JWT密钥、使用MD5/SHA1进行密码哈希、`DEBUG=True`、CORS通配符、禁用SSL验证 |
## 安装
**从GitHub安装(最新版):**
```
pip install git+https://github.com/vipulawl/vibe-audit.git
```
**从源码安装:**
```
git clone https://github.com/vipulawl/vibe-audit
cd vibe-audit
python3 -m venv .venv && source .venv/bin/activate
pip install -e .
```
## 使用方法
```
# 扫描当前目录 (带有 AI 修复提示)
export OPENAI_API_KEY=sk-...
vibe-audit .
# 扫描特定项目
vibe-audit /path/to/your/project
# 免费模式 — 无需 API key,无 AI 分析
vibe-audit . --no-ai
# 保存报告到自定义路径
vibe-audit . --output ~/reports/myapp-security.html
# 安装 pre-commit hook (阻止包含 CRITICAL 发现的提交)
vibe-audit . --install-hooks
```
### 命令行参数
| 参数 | 默认值 | 描述 |
|---|---|---|
| `path` | `.` | 要扫描的项目目录 |
| `--output` | `security-report.html` | HTML报告输出路径 |
| `--no-ai` | 关闭 | 跳过GPT-4o分析(免费且更快速) |
| `--install-hooks` | 关闭 | 在目标项目中安装pre-commit钩子 |
| `--pre-commit` | 关闭 | Pre-commit模式:仅当存在CRITICAL发现时以退出码1结束 |
| `--limit` | `500` | 要扫描的最大文件数 |
## Pre-commit钩子
自动阻止引入CRITICAL发现(硬编码密钥、密钥暴露)的提交:
```
vibe-audit . --install-hooks
```
此操作会向 `.git/hooks/pre-commit` 写入一个钩子,在每次提交时运行快速扫描(无AI分析)。只有CRITICAL发现会阻止提交——HIGH/MEDIUM仅为建议性提示。
## 抑制误报
在目标行添加 `# vibe-audit-ignore` 以跳过检查:
```
PLACEHOLDER_KEY = "sk-test-example-not-real" # vibe-audit-ignore
```
## AI分析(GPT-4o)
当设置了 `OPENAI_API_KEY` 时,vibe-audit会进行**单次GPT-4o调用(而非每项发现调用)**以:
- 用通俗易懂的英文解释每项发现——无术语
- 生成可直接粘贴到AI编码助手的特定修复提示
- 过滤静态扫描器无法自行判断的误报
**成本:** 根据发现数量,每次扫描约0.01-0.05美元。运行 `--no-ai` 可进行免费的纯静态分析。
## 评分标准
| 分数 | 等级 | 含义 |
|---|---|---|
| 90–100 | A | 清洁——可发布 |
| 75–89 | B | 小问题——发布前修复 |
| 60–74 | C | 中等问题——本周内修复 |
| 40–59 | D | 重大问题——在真实用户使用前修复 |
| 0–39 | F | 严重问题——请勿发布 |
每项发现会扣分:CRITICAL −20,HIGH −12,MEDIUM −5,LOW −2。INFO类发现(如 `innerHTML` 建议)不影响评分。
## 与其他工具对比
| 工具 | 扫描完整项目 | 对Vibe开发者友好的输出 | 为AI代理提供修复提示 | Pre-commit钩子 | 免费层级 |
|---|---|---|---|---|---|
| **vibe-audit** | ✓ | ✓ | ✓ | ✓ | ✓ (--no-ai) |
| Claude `/security-review` | 仅限差异 | ✓ | ✓ | ✗ | ✓ |
| VibeCheckAudit | ✓ | ✓ | ✗ | ✗ | ✗ (人工服务,付费) |
| ship-safe | ✓ | 部分 | ✗ | ✗ | ✓ |
| GitGuardian | 仅限密钥 | ✗ | ✗ | ✓ | 有限 |
| semgrep / bandit | ✓ | ✗ | ✗ | ✓ | ✓ |
## 项目结构
```
vibe_audit/
├── cli.py # Entry point, orchestrates scan + report
├── models.py # Finding dataclass, scoring logic
├── ai_analyzer.py # GPT-4o enrichment (explanations + fix prompts)
├── scanner/
│ ├── secrets.py # Hardcoded secrets (API keys, passwords, tokens)
│ ├── dotenv_check.py # .env committed to git / missing from .gitignore
│ ├── frontend.py # API keys in JS/HTML/TS frontend files
│ ├── injection.py # SQL injection, XSS, command injection
│ ├── logging_check.py# Sensitive values in log statements
│ ├── headers.py # Security headers per framework
│ ├── ratelimit.py # Rate limiting library detection
│ ├── deps.py # pip-audit + npm audit CVE scanning
│ └── auth.py # Auth weakness patterns
├── report/
│ └── dashboard.py # Self-contained HTML report generator
└── hooks/
└── installer.py # Git pre-commit hook installer
```
## 路线图
- [ ] PyPI包(`pip install vibe-audit`)
- [ ] GitHub Action(`uses: vipulawl/vibe-audit@v1`)
- [ ] Supabase RLS错误配置检查
- [ ] Next.js / Vercel特定检查
- [ ] 隐私政策/数据处理清单
- [ ] SARIF输出以集成至GitHub安全选项卡
## 参与贡献
欢迎提交Issue和PR。添加新扫描器时:
1. 创建 `vibe_audit/scanner/your_check.py` 并返回 `list[Finding]`
2. 将其添加至 `vibe_audit/scanner/__init__.py`
3. 将其添加至 `cli.py` 中的 `SCANNERS` 列表
4. 用一个应触发该扫描器的项目进行测试
## 许可证
MIT — 详见 [LICENSE](LICENSE)
标签:AI应用安全, API密钥安全, DevSecOps, GPT, GraphQL安全矩阵, HTML仪表板, Petitpotam, Python安全工具, 上游代理, 修复提示生成, 多模态安全, 安全扫描器, 安全报告生成, 应用安全防护, 开发安全, 注入漏洞检测, 漏洞扫描工具, 漏洞管理, 硬编码秘密检测, 自动化安全扫描, 逆向工具, 速率限制检查