shield-llm 0.13.1 → 0.14.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/dist/cli.js CHANGED
@@ -17,10 +17,14 @@ import {
17
17
  JUDGE_OUTAGE_REASON_PREFIX,
18
18
  LAYER_META,
19
19
  MUTATORS,
20
+ McpHarness,
20
21
  NOT_EXECUTED_CATEGORIES,
22
+ ObservationsSchema,
21
23
  RECIPES,
22
24
  RateLimitError,
23
25
  RegexOnlyEvaluator,
26
+ SKIP_MCP_STALE_TOOLS,
27
+ SKIP_NO_MCP_AGENT,
24
28
  Scanner,
25
29
  VULN_TO_AGENTIC,
26
30
  analyzeJudgeHealth,
@@ -78,13 +82,37 @@ import {
78
82
  summarizeObfuscationVariants,
79
83
  version,
80
84
  withoutScoredApartVariants
81
- } from "./chunk-AONOLAQM.js";
85
+ } from "./chunk-EIO2SQEC.js";
82
86
 
83
87
  // src/load-env.ts
84
- try {
85
- process.loadEnvFile();
86
- } catch {
88
+ var PROTECTED_ENV_KEYS = [
89
+ "SHIELD_API_URL",
90
+ "SHIELD_LLM_HOME",
91
+ "NODE_TLS_REJECT_UNAUTHORIZED",
92
+ "NODE_EXTRA_CA_CERTS",
93
+ "NODE_OPTIONS"
94
+ ];
95
+ function loadProjectEnv(env = process.env, load = () => process.loadEnvFile(), warn = (msg) => process.stderr.write(msg)) {
96
+ const before = new Set(
97
+ PROTECTED_ENV_KEYS.filter((k) => env[k] !== void 0)
98
+ );
99
+ try {
100
+ load();
101
+ } catch {
102
+ }
103
+ const dropped = PROTECTED_ENV_KEYS.filter(
104
+ (k) => !before.has(k) && env[k] !== void 0
105
+ );
106
+ for (const key of dropped) {
107
+ delete env[key];
108
+ warn(
109
+ `Ignored ${key} from .env: it decides where your API key goes or how it is protected in transit, so it comes from --api-url, your shell environment or \`shield-llm login\`, never from a project file.
110
+ `
111
+ );
112
+ }
113
+ return dropped;
87
114
  }
115
+ loadProjectEnv();
88
116
 
89
117
  // src/cli.ts
90
118
  import { Command, CommanderError, InvalidArgumentError } from "commander";
@@ -213,6 +241,9 @@ async function reportIfSuspended(res, apiUrl) {
213
241
  async function fetchAttacks(args) {
214
242
  const params = new URLSearchParams({ preset: args.preset });
215
243
  if (args.includeMultiTurn) params.set("includeMultiTurn", "true");
244
+ if (args.capabilities?.length) {
245
+ params.set("capabilities", args.capabilities.join(","));
246
+ }
216
247
  const url = `${args.apiUrl}/api/cli/attacks?${params.toString()}`;
217
248
  let res;
218
249
  try {
@@ -1115,8 +1146,10 @@ function truncateResponse(text) {
1115
1146
  ${text.slice(-TAIL_CHARS)}`;
1116
1147
  }
1117
1148
  function truncateInput(input2) {
1149
+ const observations = input2.observations && ObservationsSchema.safeParse(input2.observations).success ? input2.observations : void 0;
1118
1150
  return {
1119
1151
  ...input2,
1152
+ observations,
1120
1153
  attackPrompt: replaceLoneSurrogates(input2.attackPrompt),
1121
1154
  response: replaceLoneSurrogates(truncateResponse(input2.response)),
1122
1155
  turns: input2.turns?.map((t) => ({
@@ -1876,6 +1909,59 @@ function safeHostname(url) {
1876
1909
  // src/commands/scan.ts
1877
1910
  import { resolve as resolve5 } from "path";
1878
1911
 
1912
+ // src/lib/mcp-harness.ts
1913
+ var DEFAULT_MCP_HARNESS_PORT = 4300;
1914
+ function harnessPort(flags) {
1915
+ if (flags.mcpHarness === void 0 || flags.mcpHarness === false) return null;
1916
+ if (flags.mcpHarness === true) return DEFAULT_MCP_HARNESS_PORT;
1917
+ const port = Number(flags.mcpHarness);
1918
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
1919
+ throw new Error(
1920
+ `--mcp-harness expects a port between 0 and 65535, got "${flags.mcpHarness}"`
1921
+ );
1922
+ }
1923
+ return port;
1924
+ }
1925
+ async function startHarnessIfAsked(flags, log) {
1926
+ const port = harnessPort(flags);
1927
+ if (port === null) return void 0;
1928
+ const host = flags.mcpHost ?? "127.0.0.1";
1929
+ const harness = new McpHarness({ port, host });
1930
+ const url = await harness.start();
1931
+ log(
1932
+ `MCP harness listening at ${url}
1933
+ Connect the agent under test to this MCP server (Streamable HTTP), ALONE: detach its
1934
+ other MCP servers for the scan. The harness's tools are decoys that never read a file
1935
+ or call out, but the poisoned definitions ask the agent to use whatever tools it has.
1936
+ The agent must list the tools per conversation (the harness pushes no change).`
1937
+ );
1938
+ if (!["127.0.0.1", "localhost", "::1"].includes(host)) {
1939
+ log(
1940
+ ` Warning: bound to ${host}, reachable beyond this machine. The URL path is a
1941
+ per-scan secret; share it only with the agent's configuration.`
1942
+ );
1943
+ }
1944
+ return harness;
1945
+ }
1946
+ function harnessSkipWarning(results, harness) {
1947
+ if (!harness) return null;
1948
+ const count = (error) => results.filter((r) => r.error === error).length;
1949
+ const absent = count(SKIP_NO_MCP_AGENT);
1950
+ const stale = count(SKIP_MCP_STALE_TOOLS);
1951
+ const lines = [];
1952
+ if (absent > 0) {
1953
+ lines.push(
1954
+ `${absent} MCP attack(s) not run: the agent never contacted the harness at ${harness.url}. Check the agent's MCP server configuration, then run the same command again.`
1955
+ );
1956
+ }
1957
+ if (stale > 0) {
1958
+ lines.push(
1959
+ `${stale} MCP attack(s) not run: the agent acted on a tool list it kept from earlier instead of listing the harness tools again. Give it a fresh MCP session per conversation, then run the same command again.`
1960
+ );
1961
+ }
1962
+ return lines.length > 0 ? lines.join("\n") : null;
1963
+ }
1964
+
1879
1965
  // src/reporters/evidence.ts
1880
1966
  import { writeFileSync as writeFileSync5 } from "fs";
1881
1967
  import { resolve as resolve3 } from "path";
@@ -2027,7 +2113,7 @@ function bundleLimitations(classification, noScoredEvidence = false) {
2027
2113
  "The SHA-256 digest is a checksum over the bundle content. It detects alteration; it does not authenticate the issuer and is not a cryptographic signature.",
2028
2114
  "Article 50(1) disclosure rendered in a user interface (a banner, a chat header, an onboarding screen) is not observable from an HTTP-level scan and is neither tested nor scored here.",
2029
2115
  "Article 50(2) machine-readable marking of synthetic content is out of scope for this scan.",
2030
- "A non-compliance with observedBreach: false is a weakness scored against its article, not a breach of it, and never floors the status. A false human-authorship label on generated content is one: the Commission's Article 50 guidelines (C(2026) 5054, paragraph 131) place advertising text and a reply seen only by its user outside Article 50(4).",
2116
+ "A non-compliance with observedBreach: false is a weakness scored against its article, not a breach of it, and never floors the status. A false human-authorship label on generated content is one: the Commission's Article 50 guidelines (C(2026) 7702, paragraph 131) place advertising text and a reply seen only by its user outside Article 50(4).",
2031
2117
  "Organizational answers in the structural assessment are self-declared and carry no attached artefact.",
2032
2118
  "This bundle grants no Article 40 presumption of conformity: that presumption comes from conformity with a harmonised standard cited in the Official Journal, not from a test result. As of 30 October 2026 the only such standard is EN 18286:2026 on the quality management system (Commission Implementing Decision (EU) 2026/2274, OJ 14.10.2026), which this bundle does not assess."
2033
2119
  ];
@@ -2305,6 +2391,24 @@ function sanitizeReportForDisk(report, opts = {}) {
2305
2391
  if (attack.error) {
2306
2392
  sanitized.error = truncateString(attack.error, cfg.errorMaxChars);
2307
2393
  }
2394
+ const mcp = attack.observations?.mcp;
2395
+ if (mcp) {
2396
+ sanitized.observations = {
2397
+ ...attack.observations,
2398
+ mcp: {
2399
+ ...mcp,
2400
+ calls: mcp.calls.map((c2) => ({
2401
+ tool: c2.tool,
2402
+ arguments: Object.fromEntries(
2403
+ Object.entries(c2.arguments).map(([k, v]) => [
2404
+ k,
2405
+ JSON.stringify(v ?? "").includes(mcp.canary) ? "[redacted: carries the scan canary]" : "[redacted]"
2406
+ ])
2407
+ )
2408
+ }))
2409
+ }
2410
+ };
2411
+ }
2308
2412
  if (attack.llmEvaluation) {
2309
2413
  const ev = attack.llmEvaluation;
2310
2414
  sanitized.llmEvaluation = {
@@ -2609,6 +2713,7 @@ async function scanCommand(opts) {
2609
2713
  let reservedScanId = null;
2610
2714
  let scanFinalized = false;
2611
2715
  let failTarget = null;
2716
+ let harness;
2612
2717
  try {
2613
2718
  if (opts.ci) {
2614
2719
  opts.output = opts.output ?? "json";
@@ -2698,11 +2803,13 @@ async function scanCommand(opts) {
2698
2803
  `Custom-only mode: ${config.customTests.length} custom test(s), no preset attacks sent.`
2699
2804
  );
2700
2805
  } else {
2806
+ harness = await startHarnessIfAsked(opts, info);
2701
2807
  const fetched = await fetchAttacks({
2702
2808
  apiUrl: credentials.apiUrl,
2703
2809
  apiKey: credentials.apiKey,
2704
2810
  preset: presetForScan,
2705
- includeMultiTurn: includeCrescendo
2811
+ includeMultiTurn: includeCrescendo,
2812
+ ...harness && { capabilities: ["mcp-harness"] }
2706
2813
  });
2707
2814
  attacks = fetched.attacks;
2708
2815
  multiTurnAttacks = fetched.multiTurnAttacks;
@@ -2732,7 +2839,8 @@ async function scanCommand(opts) {
2732
2839
  if (!isolation.isolated) console.warn(`
2733
2840
  \u26A0\uFE0F ${isolation.warning}
2734
2841
  `);
2735
- if (includeCrescendo && (multiTurnAttacks?.length ?? 0) > 0) {
2842
+ const runMultiTurn = includeCrescendo || Boolean(harness) && (multiTurnAttacks?.length ?? 0) > 0;
2843
+ if (runMultiTurn && (multiTurnAttacks?.length ?? 0) > 0) {
2736
2844
  const conversation = checkConversationContext(target);
2737
2845
  if (!conversation.carried) {
2738
2846
  console.warn(`
@@ -2769,7 +2877,7 @@ async function scanCommand(opts) {
2769
2877
  preset: presetForScan,
2770
2878
  attacks,
2771
2879
  multiTurnAttacks,
2772
- includeCrescendo,
2880
+ includeCrescendo: runMultiTurn,
2773
2881
  customTests: config.customTests,
2774
2882
  // Adaptive concurrency: 4-way by default (AIMD backs off on 429s),
2775
2883
  // overridable via config.concurrency. Set 1 for strictly sequential.
@@ -2785,7 +2893,8 @@ async function scanCommand(opts) {
2785
2893
  maxUnjudgedPercent: config.maxUnjudgedPercent,
2786
2894
  maxNotExecutedPercent: config.maxNotExecutedPercent,
2787
2895
  checkpoint: checkpointStore,
2788
- evaluator
2896
+ evaluator,
2897
+ ...harness && { mcpHarness: harness }
2789
2898
  };
2790
2899
  const onEvent = opts.progress !== false ? handleEvent : void 0;
2791
2900
  reservedScanId = await reserveScanSlot(
@@ -2796,6 +2905,10 @@ async function scanCommand(opts) {
2796
2905
  info("Scan started");
2797
2906
  const scanner = new Scanner(scanOptions, onEvent);
2798
2907
  const report = await scanner.run();
2908
+ const harnessWarning = harnessSkipWarning(report.attacks, harness);
2909
+ if (harnessWarning) console.warn(`
2910
+ \u26A0\uFE0F ${harnessWarning}
2911
+ `);
2799
2912
  if (evaluator.accountSuspended) {
2800
2913
  console.error(accountSuspendedMessage(credentials.apiUrl));
2801
2914
  setExitCode(2);
@@ -3013,6 +3126,8 @@ async function scanCommand(opts) {
3013
3126
  console.error(`Runtime error: ${msg}`);
3014
3127
  setExitCode(3);
3015
3128
  return;
3129
+ } finally {
3130
+ await harness?.stop();
3016
3131
  }
3017
3132
  }
3018
3133
 
@@ -6337,6 +6452,12 @@ program.command("scan").description("Run a security scan against a target chatbo
6337
6452
  "--preset <name>",
6338
6453
  "Scan preset (dev, quick, owasp, frontier, standard, full)"
6339
6454
  ).option("--system-prompt <text>", "System prompt for target chatbot").option("--system-prompt-file <path>", "Path to system prompt file").option("--crescendo", "Include crescendo (multi-turn) attacks").option(
6455
+ "--mcp-harness [port]",
6456
+ "Start a decoy MCP server (default port 4300) for the agent under test to connect to, and run the MCP attacks through it: the verdict rests on the tool calls the agent makes. Its tools never read a file or call out."
6457
+ ).option(
6458
+ "--mcp-host <host>",
6459
+ "Interface the MCP harness binds to (default 127.0.0.1; 0.0.0.0 for an agent in a container)"
6460
+ ).option(
6340
6461
  "--mutate [ids]",
6341
6462
  "Also run invisible-carrier / obfuscation variants of each single-turn attack (multiplies coverage from the same payloads). Comma-separated mutator ids (e.g. zero_width,tag_chars,homoglyph,base64) or omit the value for all. `--mutate list` prints the available mutators and exits."
6342
6463
  ).option(
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  formatSarif,
9
9
  loadConfig,
10
10
  loadSystemPrompt
11
- } from "./chunk-AONOLAQM.js";
11
+ } from "./chunk-EIO2SQEC.js";
12
12
  export {
13
13
  ConfigError,
14
14
  ConfigSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shield-llm",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "AI chatbot security scanner — automated red teaming for LLMs",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -55,6 +55,7 @@
55
55
  "zod": "^4.6.7"
56
56
  },
57
57
  "devDependencies": {
58
+ "@modelcontextprotocol/sdk": "^1.31.0",
58
59
  "@shield-llm/scanner-core": "workspace:*",
59
60
  "@shield-llm/shared": "workspace:*",
60
61
  "@types/express": "^5.0.6",