Agent-Crafting-Table/injection-scan
GitHub: Agent-Crafting-Table/injection-scan
一个零依赖的Node.js确定性Prompt注入扫描器,用于在AI Agent处理外部内容前拦截恶意指令注入。
Stars: 0 | Forks: 0
# injection-scan — 确定性 Prompt 注入扫描器
一个零依赖的 Node.js 扫描器,用于检测外部内容(网页、电子邮件、API 响应、用户输入)中的 Prompt 注入尝试。涵盖 9 个攻击类别的 60 多个正则表达式模式,以及用于释义攻击的语义密度层。
## 开箱即用
```
# 复制到你的 agent workspace
cp injection-scan.js /your/workspace/scripts/injection-scan.js
```
然后在将任何外部内容传递给 LLM 之前调用它:
```
node scripts/injection-scan.js "content to check"
# exit 0 = clean, 1 = suspicious, 2 = blocked
```
## 为什么
任何处理外部内容的 Agent —— URL、电子邮件、API 响应 —— 都是 Prompt 注入的目标。攻击者在网页中嵌入指令覆盖文本;你的 Agent 获取该网页并盲目执行。此扫描器会在你将外部内容传递给 LLM 之前运行。
## 退出代码
| 代码 | 含义 |
|---|---|
| 0 | 干净 — 可以安全执行 |
| 1 | 可疑 — 在继续执行之前需审查 |
| 2 | 已阻止 — 请勿传递给 LLM |
## 输出
标准输出的 JSON:
```
{
"risk": "clean|suspicious|blocked",
"score": 0,
"findings": [
{
"label": "instruction-override",
"severity": "blocked",
"matches": ["ignore previous instructions"]
}
]
}
```
## 用法
```
# 扫描字符串
node injection-scan.js "ignore previous instructions and do X"
# 扫描文件
node injection-scan.js --file /path/to/fetched-page.html
# 通过管道传递 curl 的输出
curl -s https://example.com | node injection-scan.js
# 在 shell 脚本中(检查 exit code)
if node injection-scan.js --file "$CONTENT_FILE"; then
echo "safe"
elif [ $? -eq 1 ]; then
echo "suspicious — human review needed"
else
echo "blocked — not passing to LLM"
fi
```
## 要求
- Node.js 16+
- 零依赖
标签:AI Agent安全, AI安全, AI智能体, API安全, API安全, API密钥检测, Chat Copilot, DevSecOps, GNU通用公共许可证, GraphQL安全矩阵, Homebrew安装, JSONLines, JSON输出, JSON输出, MITM代理, Node.js, 上游代理, 内容安全检测, 大模型安全, 安全扫描器, 提示词注入防护, 文本分析, 模式匹配, 网络安全, 网页爬虫, 自动化资产收集, 自定义脚本, 输入验证, 防御引擎, 隐私保护, 零依赖, 零信任