agentshield-sdk 7.1.0 → 7.2.1
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 +28 -0
- package/README.md +48 -13
- package/package.json +5 -3
- package/src/circuit-breaker.js +321 -321
- package/src/detector-core.js +3 -3
- package/src/distributed.js +402 -359
- package/src/fuzzer.js +764 -764
- package/src/index.js +23 -7
- package/src/ipia-detector.js +821 -0
- package/src/main.js +20 -2
- package/src/mcp-security-runtime.js +30 -5
- package/src/mcp-server.js +12 -8
- package/src/middleware.js +303 -208
- package/src/multi-agent.js +421 -404
- package/src/pii.js +401 -390
- package/src/stream-scanner.js +34 -4
- package/src/testing.js +505 -505
- package/src/utils.js +199 -83
- package/types/index.d.ts +443 -0
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
|
-
[](https://www.npmjs.com/package/agentshield-sdk)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](#)
|
|
6
6
|
[](#)
|
|
7
7
|
[](#benchmark-results)
|
|
8
8
|
[](#benchmark-results)
|
|
9
|
-
[](#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
|
-
-
|
|
126
|
-
-
|
|
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
|
|
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** |
|
|
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 —
|
|
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 |
|
|
@@ -356,7 +388,7 @@ validator.validate(plugin); // Safety & quality validation
|
|
|
356
388
|
|
|
357
389
|
### VS Code Extension (v2.0)
|
|
358
390
|
|
|
359
|
-
The `vscode-extension/` directory contains a VS Code extension that provides inline diagnostics and real-time scanning for JS/TS/Python/Markdown files with
|
|
391
|
+
The `vscode-extension/` directory contains a VS Code extension that provides inline diagnostics and real-time scanning for JS/TS/Python/Markdown files with 141 detection patterns.
|
|
360
392
|
|
|
361
393
|
### Enterprise Features (v2.1)
|
|
362
394
|
|
|
@@ -801,8 +833,9 @@ Automatically scan PRs for injection threats with Check Run annotations:
|
|
|
801
833
|
### Real-Time Dashboard (v5.0)
|
|
802
834
|
|
|
803
835
|
```javascript
|
|
804
|
-
|
|
805
|
-
const {
|
|
836
|
+
// Dashboard is a standalone sub-project - import directly:
|
|
837
|
+
const { ThreatStreamServer } = require('./dashboard-live/server');
|
|
838
|
+
const { DashboardIntegration } = require('./dashboard-live/integration');
|
|
806
839
|
|
|
807
840
|
const server = new ThreatStreamServer({ port: 3001 });
|
|
808
841
|
server.start();
|
|
@@ -869,6 +902,7 @@ npx agent-shield dashboard # Security dashboard
|
|
|
869
902
|
```bash
|
|
870
903
|
npm test # Core + module tests (248 assertions)
|
|
871
904
|
npm run test:all # Full 40-feature suite (149 assertions)
|
|
905
|
+
npm run test:ipia # IPIA detector tests (117 assertions)
|
|
872
906
|
node test/test-v6-modules.js # v6.0 compliance & standards (122 assertions)
|
|
873
907
|
node test/test-confused-deputy.js # Confused deputy prevention (85 assertions)
|
|
874
908
|
npm run redteam # Attack simulation (100% detection)
|
|
@@ -885,13 +919,13 @@ node vscode-extension/test/extension.test.js # VS Code (167 tests)
|
|
|
885
919
|
cd python-sdk && python -m unittest tests/test_detector.py # Python (23 tests)
|
|
886
920
|
```
|
|
887
921
|
|
|
888
|
-
Total: **
|
|
922
|
+
Total: **1,282 test assertions** across 15 test suites.
|
|
889
923
|
|
|
890
924
|
## Project Structure
|
|
891
925
|
|
|
892
926
|
```
|
|
893
927
|
/
|
|
894
|
-
├── src/ # Node.js SDK (
|
|
928
|
+
├── src/ # Node.js SDK (327 exports)
|
|
895
929
|
│ ├── index.js # AgentShield class — main entry point
|
|
896
930
|
│ ├── main.js # Unified re-export of all modules
|
|
897
931
|
│ ├── detector-core.js # Core detection engine (patterns, scanning)
|
|
@@ -937,6 +971,7 @@ Total: **850 test assertions** across 11 test suites.
|
|
|
937
971
|
│ ├── compliance.js # SOC2/HIPAA/GDPR reporting, audit trail
|
|
938
972
|
│ ├── enterprise.js # Multi-tenant, RBAC, debug mode
|
|
939
973
|
│ ├── redteam.js # Attack simulator, payload fuzzer
|
|
974
|
+
│ ├── ipia-detector.js # v7.2 — Indirect prompt injection detector (IPIA pipeline)
|
|
940
975
|
│ └── ... # + 25 more modules
|
|
941
976
|
├── python-sdk/ # Python SDK
|
|
942
977
|
│ ├── agent_shield/ # Core package (detector, shield, middleware, CLI)
|
|
@@ -964,7 +999,7 @@ Total: **850 test assertions** across 11 test suites.
|
|
|
964
999
|
|
|
965
1000
|
## CI/CD
|
|
966
1001
|
|
|
967
|
-
A GitHub Actions workflow is included at `.github/workflows/ci.yml`. It runs all tests across Node.js
|
|
1002
|
+
A GitHub Actions workflow is included at `.github/workflows/ci.yml`. It runs all tests across Node.js 18, 20, and 22 on every push and PR.
|
|
968
1003
|
|
|
969
1004
|
## Privacy
|
|
970
1005
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentshield-sdk",
|
|
3
|
-
"version": "7.1
|
|
3
|
+
"version": "7.2.1",
|
|
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",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"test:deputy": "node test/test-confused-deputy.js",
|
|
29
29
|
"test:v6": "node test/test-v6-modules.js",
|
|
30
30
|
"test:adaptive": "node test/test-adaptive-defense.js",
|
|
31
|
-
"test:
|
|
31
|
+
"test:ipia": "node test/test-ipia-detector.js",
|
|
32
|
+
"test:production": "node test/test-production-readiness.js",
|
|
33
|
+
"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 && node test/test-production-readiness.js && npm run test:all",
|
|
32
34
|
"test:coverage": "c8 --reporter=text --reporter=lcov --reporter=json-summary npm test",
|
|
33
35
|
"lint": "node test/lint.js",
|
|
34
36
|
"lint:eslint": "eslint src/ test/ bin/",
|
|
@@ -52,7 +54,7 @@
|
|
|
52
54
|
"benchmark:generate": "node scripts/generate-dataset.js",
|
|
53
55
|
"benchmark:baseline": "node scripts/run-benchmark.js --save-baseline",
|
|
54
56
|
"benchmark:regression": "node scripts/run-benchmark.js --check-regression",
|
|
55
|
-
"prepublishOnly": "npm
|
|
57
|
+
"prepublishOnly": "npm run test:full"
|
|
56
58
|
},
|
|
57
59
|
"keywords": [
|
|
58
60
|
"ai",
|