ondraulehla/agent-audit
GitHub: ondraulehla/agent-audit
面向 AI agent 配置的安全审计 CLI 工具,扫描 MCP server、Claude Code 设置、skills 和 hooks 中的权限、密钥、供应链与 prompt injection 风险。
Stars: 0 | Forks: 0
# agent-audit
**AI agent 配置的安全审计工具。** 只需一条命令,即可扫描你的代码仓库中的 MCP server 配置、Claude Code 设置、agent 定义、skills 和 hooks —— 并告诉你攻击者(或一次简单的 prompt injection 指令)能在哪里对你造成损害。
```
$ npx agent-audit .
agent-audit — scanned 3 config file(s) in /work/my-app
.mcp.json
✖ error [MCP003]:11
Anthropic API key committed in plain text — anyone with repo access (and
every agent reading this config) can use it. Move it to an environment reference.
↳ sk-a…234 (44 chars)
✖ error [MCP005]:17
A command pipes a network download straight into a shell — the remote host
executes arbitrary code on this machine.
▲ warning [MCP002]:5
Server "filesystem" runs npx @modelcontextprotocol/server-filesystem without
a pinned version — every launch pulls whatever was published last.
Result: 2 error(s), 1 warning(s)
```
## 为什么需要
Agentic 工具迎来了爆发式增长,随之而来的是经典 linter 和密钥扫描工具无法覆盖的新型攻击面:
- **MCP server 是你主动引入的可执行文件。** 未固定版本的 `npx some-mcp` 随时可能成为供应链攻击的目标,只等下一次 `npm publish`。
- **权限即爆炸半径。** `Bash(*)` 或 `bypassPermissions` 会将任何成功的 prompt injection 转化为任意代码执行 —— 无需人工介入(no human in the loop)。
- **指令现在也是代码。** 来自市场的 Skills 和 agent 文件可能携带 injection 载荷(“忽略之前的指令……”、隐藏的 base64、远程指令拉取)。
- **Hooks 在无人值守时运行。** 一个会将你的记录 `curl` 到某处的 hook,就是一个始终开启的数据外发渠道。
`agent-audit` 可以在几秒钟内,在本地和 CI 环境中发现这些问题。
## 安装与运行
```
npx agent-audit # audit the current directory
npx agent-audit path/to/repo
npx agent-audit --json # machine-readable output
npx agent-audit --fail-on warning # stricter CI gate (default: error)
```
零运行时依赖。Node ≥ 20。
### CI 示例 (GitHub Actions)
```
- name: Audit agent configs
run: npx agent-audit --fail-on warning
```
## 检查内容
| 规则 | 严重程度 | 捕获内容 |
| --- | --- | --- |
| `MCP001` | error | 通过纯 `http://` 连接的远程 MCP server |
| `MCP002` | warning | 未固定版本的 `npx`/`uvx`/`bunx` server (供应链风险) |
| `MCP003` | error/warning | 内联提交的 API keys 和 tokens (输出中的值会被打码) |
| `MCP004` | error/warning | 根目录设为 `/` 或整个家目录的 Filesystem server |
| `MCP005` | error | 命令中包含 `curl … \| bash` 风格的远程代码执行 |
| `CC001` | error/warning | Claude Code 设置中过于宽泛的工具权限 (`Bash(*)`, `*`) |
| `CC002` | error | `bypassPermissions` / `dangerouslySkipPermissions` |
| `CC003` | warning | Hooks 向远程主机发送数据 |
| `AG001` | warning | 结合了 shell 执行与出站网络工具的 agent |
| `SK001` | warning | skills/agents 中的 Prompt injection 标记 (覆盖短语、远程指令拉取、大型 base64 块) |
## 扫描范围
- `.mcp.json`, `mcp.json`, `claude_desktop_config.json`, `.vscode/mcp.json`
- `.claude/settings.json`, `.claude/settings.local.json` (权限 + hooks)
- `.claude/agents/*.md`, `.claude/skills/**/*.md`, `.claude/commands/*.md`
## 作为库使用
```
import { audit } from 'agent-audit';
const { findings } = audit('/path/to/repo');
```
## 路线图
- [ ] 针对可自动固定版本发现项的 `--fix`
- [ ] 配置变体支持:Cursor, Windsurf, Zed, Codex
- [ ] 用于 GitHub 代码扫描的 SARIF 输出
- [ ] 用于记录已接受风险的允许列表文件 (`.agentauditrc`)
- [ ] 规则插件
## 开发
```
npm install
npm test # vitest
npm run dev -- tests/fixtures/vulnerable # run the CLI against a fixture
```
## License
MIT © Ondřej Úlehla
标签:AI安全, Chat Copilot, DLL 劫持, MITM代理, StruQ, 云安全监控, 动态分析, 大语言模型, 文档安全, 自动化攻击, 静态分析