@guardbee/mcp-prompt-injection-scanner 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +5 -5
  2. package/TR.md +5 -5
  3. package/ZH.md +118 -0
  4. package/package.json +4 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @guardbee/mcp-prompt-injection-scanner
2
2
 
3
- **🇬🇧 English** | [🇹🇷 Türkçe](TR.md)
3
+ **🇬🇧 English** | [🇹🇷 Türkçe](TR.md) | [🇨🇳 中文](ZH.md)
4
4
 
5
5
  An MCP (Model Context Protocol) server that scans **content** — a RAG chunk, a scraped web page, a document — for indirect prompt injection payloads.
6
6
 
@@ -11,9 +11,9 @@ An MCP (Model Context Protocol) server that scans **content** — a RAG chunk, a
11
11
  ```
12
12
  Web page/RAG document ──► prompt-injection-scanner ──► LLM context
13
13
  │
14
- ├─ Instruction override ("ignore all previous instructions")
15
- ├─ Role spoofing ("System:", <|im_start|>, [INST])
16
- ├─ Hidden text (zero-width characters, display:none + instruction, HTML comment)
14
+ ├─ Instruction override ("ignore all previous instructions", "önceki talimatları yok say")
15
+ ├─ Role spoofing ("System:", <|im_start|>, [INST], <system>)
16
+ ├─ Hidden text (zero-width, Unicode tag and bidi characters, display:none + instruction, HTML comment)
17
17
  ├─ Direct address ("Dear AI, ...")
18
18
  └─ Exfiltration (system prompt extraction request, data → URL instruction, templated img beacon)
19
19
  ```
@@ -108,7 +108,7 @@ prompt-injection-scanner:
108
108
 
109
109
  ```bash
110
110
  npm run build
111
- npm test # 30 unit tests
111
+ npm test # 45 unit tests
112
112
  ```
113
113
 
114
114
  ---
package/TR.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @guardbee/mcp-prompt-injection-scanner
2
2
 
3
- [🇬🇧 English](README.md) | **🇹🇷 Türkçe**
3
+ [🇬🇧 English](README.md) | **🇹🇷 Türkçe** | [🇨🇳 中文](ZH.md)
4
4
 
5
5
  MCP (Model Context Protocol) sunucusu — **içeriği** (RAG chunk'ı, scrape edilmiş bir web sayfası, bir doküman) dolaylı (indirect) prompt injection payload'ları için tarar.
6
6
 
@@ -11,9 +11,9 @@ MCP (Model Context Protocol) sunucusu — **içeriği** (RAG chunk'ı, scrape ed
11
11
  ```
12
12
  Web sayfası/RAG dokümanı ──► prompt-injection-scanner ──► LLM context'i
13
13
  │
14
- ├─ Instruction override ("ignore all previous instructions")
15
- ├─ Role spoofing ("System:", <|im_start|>, [INST])
16
- ├─ Hidden text (zero-width karakter, display:none + talimat, HTML yorumu)
14
+ ├─ Instruction override ("ignore all previous instructions", "önceki talimatları yok say")
15
+ ├─ Role spoofing ("System:", <|im_start|>, [INST], <system>)
16
+ ├─ Hidden text (zero-width, Unicode tag ve bidi karakterleri, display:none + talimat, HTML yorumu)
17
17
  ├─ Direct address ("Dear AI, ...")
18
18
  └─ Exfiltration (system prompt sızdırma isteği, data → URL talimatı, template'li img beacon)
19
19
  ```
@@ -108,7 +108,7 @@ prompt-injection-scanner:
108
108
 
109
109
  ```bash
110
110
  npm run build
111
- npm test # 30 unit test
111
+ npm test # 45 unit test
112
112
  ```
113
113
 
114
114
  ---
package/ZH.md ADDED
@@ -0,0 +1,118 @@
1
+ # @guardbee/mcp-prompt-injection-scanner
2
+
3
+ [🇬🇧 English](README.md) | [🇹🇷 Türkçe](TR.md) | **🇨🇳 中文**
4
+
5
+ 一个 MCP(Model Context Protocol)服务器,用于扫描**内容**——RAG 文本块、抓取的网页、文档——中的间接 prompt 注入载荷。
6
+
7
+ `ai-code-scanner` 和 `mcp-server-auditor` 扫描的是代码;本包扫描的是**数据**。在经典的 prompt 注入中,攻击者自己编写恶意 prompt;而在间接 prompt 注入中,攻击者根本不与模型对话——而是把指令嵌入模型之后会读取的文档、网页或工具结果中。一旦模型通过 RAG 检索或网页抓取把这些内容拉入上下文,嵌入的指令看起来就拥有与用户自己的指令相同的权威。
8
+
9
+ > 本包默认发送使用遥测(工具名 + 较短的参数,绝不包含被扫描的内容——见 [`@guardbee/mcp-telemetry`](../telemetry/README.md))。设置 `GUARDBEE_TELEMETRY=0` 即可关闭。
10
+
11
+ ```
12
+ 网页 / RAG 文档 ──► prompt-injection-scanner ──► LLM 上下文
13
+ │
14
+ ├─ 指令覆盖 ("ignore all previous instructions"、"önceki talimatları yok say")
15
+ ├─ 角色伪造 ("System:"、<|im_start|>、[INST]、<system>)
16
+ ├─ 隐藏文本 (零宽字符、Unicode tag 字符、bidi 控制符、display:none + 指令、HTML 注释)
17
+ ├─ 直接称呼 ("Dear AI, ...")
18
+ └─ 数据外泄 (索要系统提示词、数据 → URL 指令、带模板的图片信标)
19
+ ```
20
+
21
+ ---
22
+
23
+ ## 功能
24
+
25
+ - **17 个模式,5 个类别** —— instruction-override、role-spoofing、hidden-text、direct-address、exfiltration。支持英文和土耳其语表述
26
+ - 规则位于 [`@guardbee/guard-core`](../guard-core/README.md),与 `@guardbee/mcp-security-proxy` 共用,因此本扫描器报告的短语,正是代理在运行时拦截的短语
27
+ - 每个发现都包含**为什么有风险以及该怎么做**(`recommendation`)——而不只是"发现了"
28
+ - SARIF 2.1.0 输出 —— 便于 CI/CD 集成(例如在每个 PR 上自动扫描知识库仓库)
29
+ - 支持通过 `guardbee.yml` 进行配置
30
+ - 45 个单元测试 —— 每个模式都有一个正例和一个反例(误报)场景;emoji ZWJ 序列、普通的 `display:none` 弹窗、旗帜 emoji 等已知误报来源都有专门测试
31
+
32
+ ---
33
+
34
+ ## 快速开始
35
+
36
+ ### Claude Desktop / MCP 客户端
37
+
38
+ ```json
39
+ {
40
+ "mcpServers": {
41
+ "guardbee-prompt-injection-scanner": {
42
+ "command": "npx",
43
+ "args": ["-y", "@guardbee/mcp-prompt-injection-scanner"]
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### CLI(CI/CD —— 例如在每个 PR 上扫描 RAG 知识库仓库)
50
+
51
+ ```bash
52
+ npx @guardbee/mcp-prompt-injection-scanner scan ./knowledge-base --fail-on=high --format=sarif > results.sarif
53
+ ```
54
+
55
+ ---
56
+
57
+ ## MCP 工具
58
+
59
+ | 工具 | 说明 |
60
+ |------|----------|
61
+ | `scan_text` | 扫描给定的文本/文档片段 |
62
+ | `scan_file` | 扫描单个文件 |
63
+ | `scan_directory` | 递归扫描目录(例如 RAG 知识库)(自动跳过 `node_modules`、`.git`、`dist`) |
64
+ | `list_patterns` | 按类别列出所有支持的模式 |
65
+
66
+ ---
67
+
68
+ ## 检测的模式
69
+
70
+ | 类别 | 模式 | 严重度 | 含义 |
71
+ |---|---|---|---|
72
+ | instruction-override | `instruction_override_phrase` | high | 经典的覆盖短语,如 "ignore/disregard/forget previous instructions" |
73
+ | instruction-override | `instruction_override_tr` | high | 土耳其语形式:"önceki talimatları yok say / unut / görmezden gel" |
74
+ | instruction-override | `dan_mode` | high | 要求进入 "DAN mode" 越狱人格 |
75
+ | instruction-override | `bypass_safety` | high | 让模型绕过或关闭其安全措施 / guardrails |
76
+ | role-spoofing | `system_role_spoof` | medium | 内容中位于行首的伪造 "System:" 角色标签 |
77
+ | role-spoofing | `chat_template_marker_injection` | high | 内容中出现的原始聊天模板控制标记(`<\|im_start\|>`、`[INST]`) |
78
+ | role-spoofing | `system_tag` | high | 试图把数据伪装成系统消息的 `<system>` 标签 |
79
+ | hidden-text | `hidden_zero_width_chars` | medium | 零宽空格/零宽连接符(U+200B/U+2060)——对人工审阅者隐藏的文本 |
80
+ | hidden-text | `unicode_tag_smuggling` | critical | 携带隐藏文本的不可见 Unicode tag 字符(U+E0000–E007F);🏴󠁧󠁢󠁥󠁮󠁧󠁿 等旗帜 emoji 除外 |
81
+ | hidden-text | `bidi_control_chars` | medium | 使文本显示顺序与读取顺序不同的双向(bidi)覆盖/隔离字符 |
82
+ | hidden-text | `css_hidden_text_with_instruction` | high | `display:none`/白底白字元素中包含类似指令的语言 |
83
+ | hidden-text | `html_comment_instruction` | high | HTML 注释中包含类似指令的语言 |
84
+ | direct-address | `direct_address_to_ai` | medium | 内容直接称呼 "the AI"/"the assistant" |
85
+ | exfiltration | `exfiltration_url_template_in_image` | high | 带 `{{...}}`/`${...}` 模板的 markdown 图片 URL——数据外泄信标 |
86
+ | exfiltration | `reveal_system_prompt_request` | high | 要求模型透露其系统提示词的句子 |
87
+ | exfiltration | `reveal_system_prompt_tr` | high | 土耳其语形式:"sistem istemini göster" |
88
+ | exfiltration | `send_data_to_url_instruction` | critical | 明确命令模型把数据发送到外部 URL 的指令 |
89
+
90
+ 这些都是**启发式**发现——静态的文本模式扫描,而不是语义/意图分析。设计目标是低误报率(例如 emoji ZWJ 序列和普通的 `display:none` 弹窗已被专门排除),但每个发现仍应人工复核。
91
+
92
+ ---
93
+
94
+ ## 配置(`guardbee.yml`)
95
+
96
+ ```yaml
97
+ prompt-injection-scanner:
98
+ fail-on: high # any | critical | high | medium | low | none
99
+ max-files: 5000
100
+ exclude:
101
+ - ".test.ts"
102
+ - "fixtures/"
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 开发
108
+
109
+ ```bash
110
+ npm run build
111
+ npm test # 45 个单元测试
112
+ ```
113
+
114
+ ---
115
+
116
+ ## 许可证
117
+
118
+ MIT — [GuardBee](https://guardbee.ai)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardbee/mcp-prompt-injection-scanner",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "mcpName": "io.github.4hmetuyar/prompt-injection-scanner",
5
5
  "description": "MCP server that scans documents, scraped pages, and RAG content for indirect prompt injection payloads — instruction-override phrases, spoofed chat-template roles, hidden/invisible text, content addressing the AI directly, and data-exfiltration attempts",
6
6
  "type": "module",
@@ -18,12 +18,13 @@
18
18
  "files": [
19
19
  "dist",
20
20
  "README.md",
21
- "TR.md"
21
+ "TR.md",
22
+ "ZH.md"
22
23
  ],
23
24
  "dependencies": {
24
25
  "@modelcontextprotocol/sdk": "^1.0.0",
25
26
  "zod": "^4.5.4",
26
- "@guardbee/guard-core": "^0.2.0",
27
+ "@guardbee/guard-core": "^0.3.0",
27
28
  "@guardbee/mcp-telemetry": "^0.1.3"
28
29
  },
29
30
  "keywords": [