agentshield-sdk 7.0.0 → 7.2.0

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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,34 @@ All notable changes to Agent Shield will be documented in this file.
4
4
 
5
5
  This project follows [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [7.2.0] — 2026-03-21
8
+
9
+ ### Added
10
+
11
+ - **Indirect Prompt Injection Attack (IPIA) Detector** — `IPIADetector` implementing the joint-context embedding + classifier pipeline from "Benchmarking and Defending Against Indirect Prompt Injection Attacks on LLMs" (2024). 4-step pipeline: context construction → feature extraction → classification → response (`src/ipia-detector.js`)
12
+ - **ContextConstructor** — builds joint context `J = [C || SEP || U]` from external content and user intent with configurable separator and length limits
13
+ - **FeatureExtractor** — computes 10-feature vector: 3 cosine similarities (intent/content/joint TF-IDF), Shannon entropy, injection lexicon density, imperative verb density, directive pattern score, vocabulary overlap, content length ratio
14
+ - **TreeClassifier** — hand-tuned decision tree classifier with O(1) inference, zero dependencies, configurable threshold
15
+ - **ExternalEmbedder** — pluggable embedding backend for power users (MiniLM, OpenAI, etc.) with async `scanAsync()` support
16
+ - **Batch RAG scanning** — `scanBatch()` scans multiple retrieved chunks against a single user intent
17
+ - **IPIA Express middleware** — `ipiaMiddleware()` with block/flag/log actions for HTTP endpoints
18
+ - **`createIPIAScanner()`** — factory function for quick RAG pipeline integration
19
+ - **117 new test assertions** — covering all pipeline stages, false positive resistance, async/external embedder, middleware, edge cases
20
+
21
+ ### Changed
22
+
23
+ - Total exports increased from 318 to 327 across 79 modules
24
+ - Test suite expanded to 1,282 assertions across 15 test suites (117 IPIA tests)
25
+ - `test:full` script now includes IPIA detector tests
26
+
27
+ ### Fixed
28
+
29
+ - `tokenize()` crashed on non-string input (number, object, boolean) — now coerces via `String()`
30
+ - `ContextConstructor.build()` crashed on non-string arguments — now coerces via `String()`
31
+ - `cosineSim()` returned `NaN` on `Infinity` input vectors — now returns 0 for non-finite values
32
+ - `ExternalEmbedder.defaultSimilarity()` same `NaN` issue — fixed with `isFinite()` guard
33
+ - `ipiaMiddleware` crashed on `null` request object — added null guard
34
+
7
35
  ## [7.0.0] — 2026-03-21
8
36
 
9
37
  ### Added
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Agent Shield
2
2
 
3
- [![npm version](https://img.shields.io/badge/npm-v7.0.0-blue)](https://www.npmjs.com/package/agent-shield)
3
+ [![npm version](https://img.shields.io/badge/npm-v7.2.0-blue)](https://www.npmjs.com/package/agentshield-sdk)
4
4
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
5
5
  [![zero deps](https://img.shields.io/badge/dependencies-0-brightgreen)](#)
6
6
  [![node](https://img.shields.io/badge/node-%3E%3D16-blue)](#)
7
7
  [![shield score](https://img.shields.io/badge/shield%20score-100%2F100%20A%2B-brightgreen)](#benchmark-results)
8
8
  [![detection](https://img.shields.io/badge/detection-100%25-brightgreen)](#benchmark-results)
9
- [![tests](https://img.shields.io/badge/tests-962%20passing-brightgreen)](#testing)
9
+ [![tests](https://img.shields.io/badge/tests-1282%20passing-brightgreen)](#testing)
10
10
 
11
11
  **The security standard for MCP and AI agents.** Protect your agents from prompt injection, confused deputy attacks, data exfiltration, privilege escalation, and 30+ other AI-specific threats.
12
12
 
@@ -22,6 +22,38 @@ Available for **Node.js**, **Python**, **Go**, **Rust**, and in-browser via **WA
22
22
  <b>Try it yourself:</b> <code>npx agent-shield demo</code>
23
23
  </p>
24
24
 
25
+ ## v7.2 — Indirect Prompt Injection Detection
26
+
27
+ **Stop attacks hidden in RAG chunks, tool outputs, emails, and documents.** The IPIA detector implements the joint-context embedding + classifier pipeline to catch injections that bypass pattern matching.
28
+
29
+ ```javascript
30
+ const { IPIADetector } = require('agentshield-sdk');
31
+
32
+ const detector = new IPIADetector({ threshold: 0.5 });
33
+
34
+ // Scan RAG chunks before feeding to your LLM
35
+ const result = detector.scan(
36
+ retrievedChunk, // External content (RAG, tool output, email, etc.)
37
+ userQuery // The user's original intent
38
+ );
39
+
40
+ if (result.isInjection) {
41
+ console.log('Blocked IPIA:', result.reason, '(confidence:', result.confidence + ')');
42
+ }
43
+
44
+ // Batch scan all RAG results at once
45
+ const batch = detector.scanBatch(allChunks, userQuery);
46
+ const safeChunks = allChunks.filter((_, i) => !batch.results[i].isInjection);
47
+
48
+ // Pluggable embeddings for power users (MiniLM, OpenAI, etc.)
49
+ const detector2 = new IPIADetector({
50
+ embeddingBackend: { embed: async (text) => myModel.encode(text) }
51
+ });
52
+ const result2 = await detector2.scanAsync(chunk, query);
53
+ ```
54
+
55
+ ---
56
+
25
57
  ## v7.0 — MCP Security Runtime
26
58
 
27
59
  **One line to secure any MCP server.** The unified security layer that connects per-user authorization, threat scanning, behavioral monitoring, and audit logging into a single runtime.
@@ -122,8 +154,8 @@ const shield = new AgentShield({ blockOnThreat: true });
122
154
  const result = shield.scanInput(userMessage); // { blocked: true, threats: [...] }
123
155
  ```
124
156
 
125
- - 310+ exports across 77+ modules
126
- - 962 test assertions across 13 test suites, 100% pass rate
157
+ - 327+ exports across 79 modules
158
+ - 1,282 test assertions across 15 test suites, 100% pass rate
127
159
  - 100% red team detection rate (A+ grade)
128
160
  - Shield Score: 100/100 — fortress-grade protection
129
161
  - AES-256-GCM encryption, HMAC-SHA256 signing throughout
@@ -144,7 +176,7 @@ const result = shield.scanInput(userMessage); // { blocked: true, threats: [...]
144
176
 
145
177
  **Node.js:**
146
178
  ```bash
147
- npm install agent-shield
179
+ npm install agentshield-sdk
148
180
  ```
149
181
 
150
182
  **Python:**
@@ -305,7 +337,7 @@ grpc.NewServer(grpc.UnaryInterceptor(shield.GRPCInterceptor(s)))
305
337
  | **Obfuscation** | Unicode homoglyphs, zero-width chars, Base64, hex, ROT13, leetspeak, reversed text |
306
338
  | **Multi-Language** | CJK (Chinese/Japanese/Korean), Arabic, Cyrillic, Hindi, + 7 European languages |
307
339
  | **PII Leakage** | SSNs, emails, phone numbers, credit cards auto-redacted |
308
- | **Indirect Injection** | Image alt-text attacks, multi-turn escalation, multimodal vectors |
340
+ | **Indirect Injection** | RAG chunk poisoning, tool output injection, email/document payloads, image alt-text attacks, multi-turn escalation |
309
341
  | **AI Phishing** | Fake AI login, voice cloning, deepfake tools, QR phishing, MFA harvesting |
310
342
  | **Jailbreaks** | 35+ templates across 6 categories: role play, encoding bypass, context manipulation, authority exploitation |
311
343
 
@@ -313,7 +345,7 @@ grpc.NewServer(grpc.UnaryInterceptor(shield.GRPCInterceptor(s)))
313
345
 
314
346
  | Platform | Location | Description |
315
347
  |----------|----------|-------------|
316
- | **Node.js** | `src/` | Core SDK — 302 exports, zero dependencies |
348
+ | **Node.js** | `src/` | Core SDK — 327 exports, zero dependencies |
317
349
  | **Python** | `python-sdk/` | Full detection, Flask/FastAPI middleware, LangChain/LlamaIndex wrappers, CLI |
318
350
  | **Go** | `go-sdk/` | Full detection engine, HTTP/gRPC middleware, CLI, zero external deps |
319
351
  | **Rust** | `rust-core/` | High-performance `RegexSet` O(n) engine, WASM/NAPI/PyO3 targets |
@@ -869,6 +901,7 @@ npx agent-shield dashboard # Security dashboard
869
901
  ```bash
870
902
  npm test # Core + module tests (248 assertions)
871
903
  npm run test:all # Full 40-feature suite (149 assertions)
904
+ npm run test:ipia # IPIA detector tests (117 assertions)
872
905
  node test/test-v6-modules.js # v6.0 compliance & standards (122 assertions)
873
906
  node test/test-confused-deputy.js # Confused deputy prevention (85 assertions)
874
907
  npm run redteam # Attack simulation (100% detection)
@@ -885,13 +918,13 @@ node vscode-extension/test/extension.test.js # VS Code (167 tests)
885
918
  cd python-sdk && python -m unittest tests/test_detector.py # Python (23 tests)
886
919
  ```
887
920
 
888
- Total: **850 test assertions** across 11 test suites.
921
+ Total: **1,282 test assertions** across 15 test suites.
889
922
 
890
923
  ## Project Structure
891
924
 
892
925
  ```
893
926
  /
894
- ├── src/ # Node.js SDK (302 exports)
927
+ ├── src/ # Node.js SDK (327 exports)
895
928
  │ ├── index.js # AgentShield class — main entry point
896
929
  │ ├── main.js # Unified re-export of all modules
897
930
  │ ├── detector-core.js # Core detection engine (patterns, scanning)
@@ -937,6 +970,7 @@ Total: **850 test assertions** across 11 test suites.
937
970
  │ ├── compliance.js # SOC2/HIPAA/GDPR reporting, audit trail
938
971
  │ ├── enterprise.js # Multi-tenant, RBAC, debug mode
939
972
  │ ├── redteam.js # Attack simulator, payload fuzzer
973
+ │ ├── ipia-detector.js # v7.2 — Indirect prompt injection detector (IPIA pipeline)
940
974
  │ └── ... # + 25 more modules
941
975
  ├── python-sdk/ # Python SDK
942
976
  │ ├── agent_shield/ # Core package (detector, shield, middleware, CLI)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentshield-sdk",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "description": "The security standard for MCP and AI agents. Protects against prompt injection, confused deputy attacks, data exfiltration, and 30+ threats. Zero dependencies, runs locally.",
5
5
  "main": "src/main.js",
6
6
  "types": "types/index.d.ts",
@@ -27,7 +27,9 @@
27
27
  "test:mcp": "node test/test-mcp-security.js",
28
28
  "test:deputy": "node test/test-confused-deputy.js",
29
29
  "test:v6": "node test/test-v6-modules.js",
30
- "test:full": "npm test && node test/test-mcp-security.js && node test/test-confused-deputy.js && node test/test-v6-modules.js && npm run test:all",
30
+ "test:adaptive": "node test/test-adaptive-defense.js",
31
+ "test:ipia": "node test/test-ipia-detector.js",
32
+ "test:full": "npm test && node test/test-mcp-security.js && node test/test-confused-deputy.js && node test/test-v6-modules.js && node test/test-adaptive-defense.js && node test/test-ipia-detector.js && npm run test:all",
31
33
  "test:coverage": "c8 --reporter=text --reporter=lcov --reporter=json-summary npm test",
32
34
  "lint": "node test/lint.js",
33
35
  "lint:eslint": "eslint src/ test/ bin/",