alvabillwu/ai-supply-guard
GitHub: alvabillwu/ai-supply-guard
一款针对 npm 依赖中 AI 特定供应链攻击模式(如篡改 Claude 配置、注入 MCP server、prompt injection)的风险评分审计工具,支持 CI 集成。
Stars: 0 | Forks: 1
# 🛡️ ai-supply-guard
[](https://nodejs.org/)
[](https://www.typescriptlang.org/)
[](LICENSE)
**审计 npm 依赖中特定的 AI 供应链攻击模式。**
一类新型恶意软件专门针对 AI 开发者工具:将 hook 写入 `~/.claude/settings.json` 或 `~/.codex/AGENTS.md` 的 `postinstall` 脚本、静默注册 MCP server 的依赖项、携带 prompt injection payload 的包,以及凭证窃取。`ai-supply-guard` 会扫描包的 manifest、生命周期脚本和源代码以检测这些模式,并为您提供可用于拦截 CI 的风险判定。
## 功能
- 🔍 **9 条检测规则**,涵盖 AI 供应链威胁模型
- 🧩 **声明式规则** — 每个模式都是一个数据对象;添加检测非常简单
- 🚦 **风险判定** — `block` / `review` / `pass`,并附带 0–100 的风险评分
- 📦 **Manifest + 源代码扫描** — 读取 `package.json`、生命周期脚本以及 `.js`/`.ts` 源代码
- 🎨 **人类可读 + JSON 输出** — 为用户提供终端报告,为自动化提供 `--json`
- ✅ **开箱即用的 CI** — `--fail-on` 以非零状态码退出来中断构建
## 检测到的模式
| 规则 | 严重性 | 捕获内容 |
|------|----------|---------|
| postinstall 针对 Claude 设置 | critical | 写入 `~/.claude/settings.json` / `CLAUDE.md` |
| postinstall 针对 Codex/Cursor 配置 | critical | 写入 `~/.codex/AGENTS.md`, `~/.cursor` |
| 动态注册 MCP server | high | 运行时写入 `mcp.json` / `mcpServers` |
| 通过网络窃取环境变量 | critical | `process.env` + 网络调用 |
| 嵌入的 prompt injection payload | high | “忽略之前的指令”等 |
| 混淆的动态 eval | high | `eval(atob(...))`, `Function(Buffer.from(...))` |
| 在 install hook 中执行 shell | moderate | 生命周期中使用 `child_process` / `execSync` |
| 已知 AI 包的 typosquat | moderate | `openal` 对比 `openai` 等 |
| 缺少 repository 字段 | low | 无 `repository.url`(一次性包的危险信号) |
## 快速开始
```
npm install -g ai-supply-guard
```
## 用法
### 审计本地包
```
ai-supply-guard audit ./node_modules/some-suspicious-pkg
ai-supply-guard audit ./node_modules/some-pkg --source # also scan .js/.ts
ai-supply-guard audit ./some-pkg --json # machine-readable
```
输出:
```
● some-pkg v1.2.3
scanned 4 file(s) · repository: no
risk: riskScore 70/100 · verdict: BLOCK
critical=1 high=1 moderate=0 low=1 info=0
✗ CRITICAL postinstall targets Claude Code settings [scripts (lifecycle)]
Lifecycle script references Claude Code config path
→ Remove the lifecycle script. If a build step genuinely needs it, pin it and review it in a sandbox first.
▲ HIGH dynamic MCP server registration [scripts (lifecycle)]
Registers or modifies an MCP server configuration
→ MCP servers should be added by the user, not by a dependency. Remove dynamic registration.
```
### 拦截 CI
```
ai-supply-guard audit ./pkg --fail-on # exit 1 on review OR block
ai-supply-guard audit ./pkg # exit 1 only on block
```
### 列出规则
```
ai-supply-guard rules
ai-supply-guard rules --json
```
## 编程 API
```
import { auditPackage } from "ai-supply-guard";
const result = auditPackage("./node_modules/some-pkg", { scanSource: true });
if (result.summary.verdict === "block") {
console.error(`Do not install: ${result.findings.length} critical findings`);
}
```
## 开发
```
git clone https://github.com/alvabillwu/ai-supply-guard.git
cd ai-supply-guard
npm install
npm test
npm run dev -- audit ./test-fixtures/evil
```
## License
MIT © [alvabillwu](https://github.com/alvabillwu)
标签:DNS 反向解析, GNU通用公共许可证, MITM代理, Node.js, TypeScript, 云安全监控, 安全插件, 文档安全, 自动化攻击, 静态分析