agentshield-sdk 7.2.0 → 7.3.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,7 +4,96 @@ 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
7
+ ## [7.3.0] - 2026-03-21
8
+
9
+ ### Added - CORTEX Autonomous Defense Platform
10
+
11
+ - **Attack Genome Sequencing** (`src/attack-genome.js`) - Decompose attacks into intent/technique/evasion/target genome. Detect unseen variants by recognizing the genome, not the surface text. GenomeDatabase clusters attack families.
12
+ - **Adversarial Evolution Simulator** (`src/evolution-simulator.js`) - GAN-style mutation engine generates attack variants across generations. Tests against defenses automatically. hardenFromEvolution() generates new patterns from evasive survivors.
13
+ - **Intent Firewall** (`src/intent-firewall.js`) - Classifies user INTENT, not just content. Same words blocked or allowed based on context. "Help me write a phishing email" = BLOCKED. "Help me write about phishing training" = ALLOWED. ContextAnalyzer detects multi-turn manipulation.
14
+ - **Cross-Agent Herd Immunity** (`src/herd-immunity.js`) - When one agent detects an attack, all connected agents receive the pattern. ImmuneMemory provides collective memory that new agents inherit from day one.
15
+ - **Federated Threat Intelligence** (`src/threat-intel-federation.js`) - CrowdStrike model: anonymous attack pattern sharing with differential privacy. Consensus-based promotion. createFederationMesh() connects nodes.
16
+ - **Agent Behavioral DNA** (`src/behavioral-dna.js`) - Learn per-agent behavioral baselines (tool usage, response patterns, timing). Detect anomalies when agent is compromised. Portable fingerprints.
17
+
18
+ ### Added - Enterprise & Production
19
+
20
+ - **Pre-Deployment Security Audit** (`src/audit.js`) - Run 617+ attacks with mutation engine in under 100ms. SecurityAudit generates category breakdown, findings, fix recommendations, and production-readiness verdict.
21
+ - **Agent Flight Recorder** (`src/flight-recorder.js`) - Forensic conversation replay. Records every interaction, detects incidents, reconstructs attack timeline and escalation path. Auto-generates fix patterns.
22
+ - **Supply Chain Verification** (`src/supply-chain.js`) - ToolChainValidator scans tool arguments and responses for injection. ResponseScanner deep-scans JSON/nested data for hidden instructions. DomainAllowlist for URL validation.
23
+ - **Visual HTML Security Report** (`src/report-generator.js`) - Lighthouse-style HTML report with SVG gauge, category bar charts, severity breakdown, fix recommendations. Self-contained, print-friendly.
24
+ - **Enterprise SOC Dashboard** (`src/soc-dashboard.js`) - Real-time event aggregation from multiple agents. Query by agent/category/severity/time. Alert channels: Slack, PagerDuty, Microsoft Teams.
25
+ - **Attack Replay Platform** (`src/attack-replay.js`) - Record real attacks, replay against updated defenses. Track improvements vs regressions. Export/import attack corpora.
26
+ - **Compliance Certification Authority** (`src/compliance-authority.js`) - HMAC-signed compliance certificates against OWASP, NIST, EU AI Act, SOC 2. Platinum/Gold/Silver/Bronze levels. Verify and revoke certificates.
27
+ - **Real Attack Dataset Testing** (`src/real-attack-datasets.js`) - 48 samples from HackAPrompt, TensorTrust, and security research. DatasetRunner with precision/recall/F1 metrics.
28
+
29
+ ### Added - Developer Experience
30
+
31
+ - **Web Playground** (`playground/index.html`) - Paste text, see threats. 47 embedded patterns, dark mode, preset examples. Zero install.
32
+ - **Claude SDK 3-Line Demo** (`examples/claude-3-lines.js`) - Simplest possible Claude integration.
33
+ - **MCP Attack Demo** (`examples/mcp-attack-demo.js`) - 5 real MCP attacks all blocked in real-time.
34
+ - **Competitive Benchmark Page** (`benchmark/competitive.html`) - Agent Shield vs Rebuff, LLM Guard, Lakera, Prompt Armor.
35
+ - **CLI pentest command** - `npx agentshield-sdk security-audit` runs full audit with HTML report.
36
+
37
+ ### Changed
38
+
39
+ - Total exports: 390 across 93 modules (was 331 across 79)
40
+ - Total test assertions: 2,220 across 13 test suites + Python + VSCode
41
+ - 14 new source modules in this release
42
+
43
+ ## [7.2.1] - 2026-03-21
44
+
45
+ ### Added
46
+
47
+ - **Rate limiting middleware** - `rateLimitMiddleware()` and `shieldMiddleware()` for Express with 429 responses, `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `Retry-After` headers
48
+ - **Graceful shutdown** - `createGracefulShutdown()` utility with configurable timeout enforcement, ordered cleanup, and idempotent execution
49
+ - **Inline .env file loader** - `loadEnvFile()` zero-dependency alternative to dotenv with quote stripping and no-overwrite semantics
50
+ - **Queue depth monitoring** - `DistributedShield.getQueueDepth()` returns pending, peak, and totalQueued metrics
51
+ - **Production readiness test suite** - 24 new assertions covering config shapes, result shapes, shutdown, rate limiting, streaming errors, .env loading
52
+ - **Migration guide** - `instructions/17-migration-v6-to-v7.md` covering v6.0 to v7.x upgrade path
53
+ - **Troubleshooting guide** - `instructions/18-troubleshooting.md` with 10 common issues and solutions
54
+ - **141-pattern sync across all SDKs** - Python, Go, Rust, and VSCode now have full parity with Node.js detection engine (was 22/29/31/31)
55
+ - **Standardized API return shapes** - Python, Go, and Rust SDKs now return Node.js-compatible `status`, `stats`, and `timestamp` fields alongside legacy fields
56
+ - **Pattern sync build script** - `npm run sync:patterns` exports canonical patterns to JSON for cross-SDK consumption
57
+ - **Python PyPI packaging** - `pyproject.toml` and proper `__init__.py` for `pip install agentshield`
58
+ - **Structured error codes** - All public API throws now use `createShieldError()` with machine-readable codes (AS-DET-002, AS-AUT-004, etc.)
59
+ - **Performance regression gate in CI** - Automated benchmark check that fails if 10k scans exceed threshold
60
+
61
+ ### Fixed
62
+
63
+ - **Short input bypass** - detector-core.js was skipping inputs under 10 characters; `rm -rf /` (9 chars) was unscanned
64
+ - **Role hijack pattern** - "you are now unrestricted" (no article) was not caught; tightened pattern with identity-related word requirement
65
+ - **ReDoS risk** - Simplified credential listing pattern's nested alternation to prevent potential catastrophic backtracking
66
+ - **Zero-value config bug** - `RateLimiter({ windowMs: 0 })` and `CircuitBreaker({ threshold: 0 })` silently defaulted via `||` operator; now uses explicit null checks
67
+ - **scanToolCall inconsistency** - Previously returned `{ status: 'safe' }` on invalid input while `scan()` threw TypeError; now throws TypeError for consistency
68
+ - **Shadow mode error swallowing** - Logger errors in shadow mode were silently caught; now logged to console.error
69
+ - **DLP regex validation** - `DLPEngine.addRule()` with invalid regex string now catches and logs gracefully instead of throwing uncaught error
70
+ - **Unbounded _localThreats** - `DistributedShield._localThreats` array now capped at 1000 entries (was unbounded, grew forever)
71
+ - **Timer GC leak** - `DistributedShield` sync timer now uses `.unref()` to prevent blocking process exit
72
+ - **SharedThreatState cleanup** - Added `pruneStaleSubscribers()` method for cleaning up dead subscriber callbacks
73
+ - **MCP runtime shutdown** - `MCPSecurityRuntime.shutdown()` is now async with configurable timeout and drain handling
74
+ - **MCP server shutdown** - Uses `createGracefulShutdown()` with `SHIELD_SHUTDOWN_TIMEOUT_MS` env var support
75
+ - **Dashboard DoS** - POST /api/ingest now enforces 1MB body size limit (was unlimited)
76
+ - **GitHub App markdown** - PR comment category values now escape pipe characters to prevent table breakage
77
+ - **k8s Dockerfile** - USER directive moved before COPY with `--chown` for proper file ownership
78
+ - **k8s fallback patterns** - Embedded patterns expanded from 10 to 15, synced with core engine fixes
79
+ - **Benchmark percentile** - Fixed off-by-one in percentile calculation; now uses linear interpolation
80
+ - **Category name consistency** - `role_hijacking` renamed to `role_hijack` across Python, Go, Rust, VSCode, benchmark-registry, testing.js, fuzzer.js, and all docs
81
+ - **TypeScript declarations** - Added 39 missing type declarations for exported symbols
82
+ - **VSCode debouncing** - Per-document debounce timers (was single global), scan result caching, 500KB file size limit, cache cleanup on close
83
+
84
+ ### Changed
85
+
86
+ - `prepublishOnly` now runs `test:full` (all 16 test suites) instead of just 3
87
+ - CI workflow runs test:adaptive, test:ipia, test:production, test:adversarial
88
+ - CI coverage job expanded from 3 to 7 test files
89
+ - CI verifies all 10 example files (was only 2)
90
+ - `DEFAULT_CONFIG` in index.js now includes `maxInputSize`, `maxScanHistory`, `maxArgDepth`
91
+ - Total exports increased to 331 across 79 modules
92
+ - Total test assertions: 1,755 across 16 test suites
93
+ - All SDK READMEs updated with 141 pattern count and 8 threat categories
94
+ - README.md Node.js CI claim corrected to 18/20/22 (was incorrectly claiming 16)
95
+
96
+ ## [7.2.0] - 2026-03-21
8
97
 
9
98
  ### Added
10
99
 
package/README.md CHANGED
@@ -154,7 +154,7 @@ const shield = new AgentShield({ blockOnThreat: true });
154
154
  const result = shield.scanInput(userMessage); // { blocked: true, threats: [...] }
155
155
  ```
156
156
 
157
- - 327+ exports across 79 modules
157
+ - 390+ exports across 93 modules
158
158
  - 1,282 test assertions across 15 test suites, 100% pass rate
159
159
  - 100% red team detection rate (A+ grade)
160
160
  - Shield Score: 100/100 — fortress-grade protection
@@ -388,7 +388,7 @@ validator.validate(plugin); // Safety & quality validation
388
388
 
389
389
  ### VS Code Extension (v2.0)
390
390
 
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 31 detection patterns.
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.
392
392
 
393
393
  ### Enterprise Features (v2.1)
394
394
 
@@ -833,8 +833,9 @@ Automatically scan PRs for injection threats with Check Run annotations:
833
833
  ### Real-Time Dashboard (v5.0)
834
834
 
835
835
  ```javascript
836
- const { ThreatStreamServer } = require('agent-shield/dashboard-live/server');
837
- const { DashboardIntegration } = require('agent-shield/dashboard-live/integration');
836
+ // Dashboard is a standalone sub-project - import directly:
837
+ const { ThreatStreamServer } = require('./dashboard-live/server');
838
+ const { DashboardIntegration } = require('./dashboard-live/integration');
838
839
 
839
840
  const server = new ThreatStreamServer({ port: 3001 });
840
841
  server.start();
@@ -996,9 +997,41 @@ Total: **1,282 test assertions** across 15 test suites.
996
997
  └── types/ # TypeScript definitions
997
998
  ```
998
999
 
1000
+ ## CORTEX Autonomous Defense (v7.3)
1001
+
1002
+ Agent Shield CORTEX goes beyond pattern matching with autonomous threat intelligence:
1003
+
1004
+ ```javascript
1005
+ const { AttackGenome, IntentFirewall, HerdImmunity, SecurityAudit } = require('agentshield-sdk');
1006
+
1007
+ // Attack Genome: detect unseen variants by recognizing attack DNA
1008
+ const genome = new AttackGenome();
1009
+ const dna = genome.sequence('ignore all previous instructions');
1010
+ // { intent: 'override_instructions', technique: 'direct_command', target: 'system_prompt' }
1011
+
1012
+ // Intent Firewall: same words, different action
1013
+ const firewall = new IntentFirewall();
1014
+ firewall.classify('Help me write a phishing email'); // BLOCKED
1015
+ firewall.classify('Help me write about phishing training'); // ALLOWED
1016
+
1017
+ // Herd Immunity: attack on Agent A protects Agent B
1018
+ const herd = new HerdImmunity();
1019
+ herd.connect('agent-a');
1020
+ herd.connect('agent-b');
1021
+ herd.reportAttack({ text: 'DAN mode jailbreak', agentId: 'agent-a' });
1022
+ // agent-b now has the pattern
1023
+
1024
+ // Pre-Deployment Audit: 617+ attacks in under 100ms
1025
+ const audit = new SecurityAudit();
1026
+ const report = audit.run();
1027
+ console.log(report.formatReport());
1028
+ ```
1029
+
1030
+ **CORTEX modules:** Attack Genome Sequencing, Adversarial Evolution Simulator, Intent Firewall, Cross-Agent Herd Immunity, Federated Threat Intelligence, Agent Behavioral DNA, Pre-Deployment Audit, Flight Recorder, Supply Chain Verification, SOC Dashboard, Attack Replay, Compliance Certification Authority.
1031
+
999
1032
  ## CI/CD
1000
1033
 
1001
- A GitHub Actions workflow is included at `.github/workflows/ci.yml`. It runs all tests across Node.js 16, 18, 20, and 22 on every push and PR.
1034
+ 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.
1002
1035
 
1003
1036
  ## Privacy
1004
1037
 
@@ -349,6 +349,21 @@ const commandScore = () => {
349
349
  console.log(calc.formatReport());
350
350
  };
351
351
 
352
+ const commandSecurityAudit = () => {
353
+ console.log(ASCII_BANNER);
354
+ const { runAuditCLI } = require('../src/audit');
355
+ const report = runAuditCLI();
356
+
357
+ // Try to generate HTML report
358
+ try {
359
+ const { generateReportFile } = require('../src/report-generator');
360
+ generateReportFile(report, 'shield-report.html');
361
+ console.log(`\n${COLORS.green}HTML report saved to shield-report.html${COLORS.reset}`);
362
+ } catch (_) {
363
+ // report-generator not available, skip HTML
364
+ }
365
+ };
366
+
352
367
  const commandRedteam = (args) => {
353
368
  console.log(ASCII_BANNER);
354
369
  const { AttackSimulator } = require('../src/redteam');
@@ -626,6 +641,10 @@ const main = () => {
626
641
  case 'setup':
627
642
  commandInit();
628
643
  break;
644
+ case 'security-audit':
645
+ case 'pentest':
646
+ commandSecurityAudit();
647
+ break;
629
648
  case 'demo':
630
649
  case 'prove-it':
631
650
  commandDemo();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agentshield-sdk",
3
- "version": "7.2.0",
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.",
3
+ "version": "7.3.0",
4
+ "description": "The security standard for MCP and AI agents. 141 detection patterns, CORTEX threat intelligence, pre-deployment audit, intent firewall, flight recorder, and 390+ exports. Zero dependencies, runs locally.",
5
5
  "main": "src/main.js",
6
6
  "types": "types/index.d.ts",
7
7
  "exports": {
@@ -29,7 +29,8 @@
29
29
  "test:v6": "node test/test-v6-modules.js",
30
30
  "test:adaptive": "node test/test-adaptive-defense.js",
31
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",
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",
33
34
  "test:coverage": "c8 --reporter=text --reporter=lcov --reporter=json-summary npm test",
34
35
  "lint": "node test/lint.js",
35
36
  "lint:eslint": "eslint src/ test/ bin/",
@@ -43,6 +44,8 @@
43
44
  "test:adversarial": "node test/test-adversarial.js",
44
45
  "audit": "npm audit --omit=dev",
45
46
  "sbom": "node scripts/generate-sbom.js",
47
+ "audit:security": "node -e \"const {runAuditCLI}=require('./src/audit');runAuditCLI()\"",
48
+ "report": "node -e \"const {SecurityAudit}=require('./src/audit');const {generateReportFile}=require('./src/report-generator');const r=new SecurityAudit().run();generateReportFile(r,'shield-report.html');console.log('Report saved to shield-report.html')\"",
46
49
  "mcp": "node src/mcp-server.js",
47
50
  "sidecar": "node sidecar/server.js",
48
51
  "ctf": "node -e \"const {CTFEngine,CTFReporter}=require('./src/ctf');const e=new CTFEngine();console.log(new CTFReporter().formatReport(e.getScoreboard()))\"",
@@ -53,7 +56,8 @@
53
56
  "benchmark:generate": "node scripts/generate-dataset.js",
54
57
  "benchmark:baseline": "node scripts/run-benchmark.js --save-baseline",
55
58
  "benchmark:regression": "node scripts/run-benchmark.js --check-regression",
56
- "prepublishOnly": "npm test && npm run test:all && npm run test:fp"
59
+ "sync:patterns": "node scripts/sync-patterns.js",
60
+ "prepublishOnly": "npm run test:full"
57
61
  },
58
62
  "keywords": [
59
63
  "ai",