shield-llm 0.13.0 → 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,
@@ -68,6 +72,7 @@ import {
68
72
  normalizeTargetUrl,
69
73
  parseMaxUnjudgedPercent,
70
74
  recordVerification,
75
+ redactTargetUrl,
71
76
  replaceLoneSurrogates,
72
77
  resolveClaim,
73
78
  retestDedupKey,
@@ -77,13 +82,37 @@ import {
77
82
  summarizeObfuscationVariants,
78
83
  version,
79
84
  withoutScoredApartVariants
80
- } from "./chunk-S3XEHIPB.js";
85
+ } from "./chunk-EIO2SQEC.js";
81
86
 
82
87
  // src/load-env.ts
83
- try {
84
- process.loadEnvFile();
85
- } 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;
86
114
  }
115
+ loadProjectEnv();
87
116
 
88
117
  // src/cli.ts
89
118
  import { Command, CommanderError, InvalidArgumentError } from "commander";
@@ -212,6 +241,9 @@ async function reportIfSuspended(res, apiUrl) {
212
241
  async function fetchAttacks(args) {
213
242
  const params = new URLSearchParams({ preset: args.preset });
214
243
  if (args.includeMultiTurn) params.set("includeMultiTurn", "true");
244
+ if (args.capabilities?.length) {
245
+ params.set("capabilities", args.capabilities.join(","));
246
+ }
215
247
  const url = `${args.apiUrl}/api/cli/attacks?${params.toString()}`;
216
248
  let res;
217
249
  try {
@@ -962,6 +994,9 @@ function verificationLabel(v, open) {
962
994
  function withClaimStatus(scan, claims = []) {
963
995
  return {
964
996
  ...scan,
997
+ // A row stored before 2026-11-08 keeps the raw URL: redact on read
998
+ // (MCP get_findings reads this JSON too).
999
+ targetUrl: redactTargetUrl(scan.targetUrl),
965
1000
  vulns: scan.vulns.map((v) => {
966
1001
  const claimStatus = contradiction(scan, v, claims);
967
1002
  return claimStatus ? { ...v, claimStatus } : v;
@@ -981,7 +1016,7 @@ function renderScanMarkdown(scan, claims = []) {
981
1016
  const lines = [
982
1017
  `# Shield LLM scan ${scan.id}`,
983
1018
  "",
984
- `- Target: \`${scan.targetUrl}\``,
1019
+ `- Target: \`${redactTargetUrl(scan.targetUrl)}\``,
985
1020
  `- Score: **${scan.score}** (${scan.grade})`,
986
1021
  `- Date: ${scan.createdAt}`,
987
1022
  `- Tests: ${scan.testsRun}/${scan.testsTotal} run, ${detected.length} vulnerable, ${passed} secure`,
@@ -1111,8 +1146,10 @@ function truncateResponse(text) {
1111
1146
  ${text.slice(-TAIL_CHARS)}`;
1112
1147
  }
1113
1148
  function truncateInput(input2) {
1149
+ const observations = input2.observations && ObservationsSchema.safeParse(input2.observations).success ? input2.observations : void 0;
1114
1150
  return {
1115
1151
  ...input2,
1152
+ observations,
1116
1153
  attackPrompt: replaceLoneSurrogates(input2.attackPrompt),
1117
1154
  response: replaceLoneSurrogates(truncateResponse(input2.response)),
1118
1155
  turns: input2.turns?.map((t) => ({
@@ -1650,6 +1687,7 @@ async function retestCommand(scanId, opts) {
1650
1687
  const config = loadConfig({ configPath: opts.config, cliOverrides });
1651
1688
  const systemPrompt = loadSystemPrompt(config);
1652
1689
  const endpointHost = safeHostname(config.endpoint?.url);
1690
+ const shownTarget = config.endpoint?.url ? redactTargetUrl(config.endpoint.url) : void 0;
1653
1691
  const targetMismatch = scan.targetDomain && endpointHost && endpointHost !== scan.targetDomain ? { retestedHost: endpointHost, scannedDomain: scan.targetDomain } : null;
1654
1692
  if (targetMismatch) {
1655
1693
  console.error(
@@ -1692,7 +1730,7 @@ async function retestCommand(scanId, opts) {
1692
1730
  return;
1693
1731
  }
1694
1732
  info(
1695
- `Retesting ${runnable} finding(s) from scan ${scanId} against ${config.endpoint?.url ?? "target"}\u2026`
1733
+ `Retesting ${runnable} finding(s) from scan ${scanId} against ${shownTarget ?? "target"}\u2026`
1696
1734
  );
1697
1735
  const evaluator = new BackendEvaluator(
1698
1736
  credentials.apiUrl,
@@ -1743,7 +1781,7 @@ async function retestCommand(scanId, opts) {
1743
1781
  Authorization: `Bearer ${credentials.apiKey}`
1744
1782
  },
1745
1783
  body: JSON.stringify({
1746
- targetUrl: config.endpoint?.url,
1784
+ targetUrl: shownTarget,
1747
1785
  results: outcome.verifications
1748
1786
  })
1749
1787
  }
@@ -1769,7 +1807,7 @@ async function retestCommand(scanId, opts) {
1769
1807
  JSON.stringify(
1770
1808
  {
1771
1809
  scanId,
1772
- targetUrl: config.endpoint?.url,
1810
+ targetUrl: shownTarget,
1773
1811
  ...targetMismatch ? { targetMismatch } : {},
1774
1812
  retested: outcome.verifications.length,
1775
1813
  fixed: fixed.length,
@@ -1871,6 +1909,59 @@ function safeHostname(url) {
1871
1909
  // src/commands/scan.ts
1872
1910
  import { resolve as resolve5 } from "path";
1873
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
+
1874
1965
  // src/reporters/evidence.ts
1875
1966
  import { writeFileSync as writeFileSync5 } from "fs";
1876
1967
  import { resolve as resolve3 } from "path";
@@ -2022,7 +2113,7 @@ function bundleLimitations(classification, noScoredEvidence = false) {
2022
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.",
2023
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.",
2024
2115
  "Article 50(2) machine-readable marking of synthetic content is out of scope for this scan.",
2025
- "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).",
2026
2117
  "Organizational answers in the structural assessment are self-declared and carry no attached artefact.",
2027
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."
2028
2119
  ];
@@ -2300,6 +2391,24 @@ function sanitizeReportForDisk(report, opts = {}) {
2300
2391
  if (attack.error) {
2301
2392
  sanitized.error = truncateString(attack.error, cfg.errorMaxChars);
2302
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
+ }
2303
2412
  if (attack.llmEvaluation) {
2304
2413
  const ev = attack.llmEvaluation;
2305
2414
  sanitized.llmEvaluation = {
@@ -2604,6 +2713,7 @@ async function scanCommand(opts) {
2604
2713
  let reservedScanId = null;
2605
2714
  let scanFinalized = false;
2606
2715
  let failTarget = null;
2716
+ let harness;
2607
2717
  try {
2608
2718
  if (opts.ci) {
2609
2719
  opts.output = opts.output ?? "json";
@@ -2693,11 +2803,13 @@ async function scanCommand(opts) {
2693
2803
  `Custom-only mode: ${config.customTests.length} custom test(s), no preset attacks sent.`
2694
2804
  );
2695
2805
  } else {
2806
+ harness = await startHarnessIfAsked(opts, info);
2696
2807
  const fetched = await fetchAttacks({
2697
2808
  apiUrl: credentials.apiUrl,
2698
2809
  apiKey: credentials.apiKey,
2699
2810
  preset: presetForScan,
2700
- includeMultiTurn: includeCrescendo
2811
+ includeMultiTurn: includeCrescendo,
2812
+ ...harness && { capabilities: ["mcp-harness"] }
2701
2813
  });
2702
2814
  attacks = fetched.attacks;
2703
2815
  multiTurnAttacks = fetched.multiTurnAttacks;
@@ -2727,7 +2839,8 @@ async function scanCommand(opts) {
2727
2839
  if (!isolation.isolated) console.warn(`
2728
2840
  \u26A0\uFE0F ${isolation.warning}
2729
2841
  `);
2730
- if (includeCrescendo && (multiTurnAttacks?.length ?? 0) > 0) {
2842
+ const runMultiTurn = includeCrescendo || Boolean(harness) && (multiTurnAttacks?.length ?? 0) > 0;
2843
+ if (runMultiTurn && (multiTurnAttacks?.length ?? 0) > 0) {
2731
2844
  const conversation = checkConversationContext(target);
2732
2845
  if (!conversation.carried) {
2733
2846
  console.warn(`
@@ -2764,7 +2877,7 @@ async function scanCommand(opts) {
2764
2877
  preset: presetForScan,
2765
2878
  attacks,
2766
2879
  multiTurnAttacks,
2767
- includeCrescendo,
2880
+ includeCrescendo: runMultiTurn,
2768
2881
  customTests: config.customTests,
2769
2882
  // Adaptive concurrency: 4-way by default (AIMD backs off on 429s),
2770
2883
  // overridable via config.concurrency. Set 1 for strictly sequential.
@@ -2780,14 +2893,22 @@ async function scanCommand(opts) {
2780
2893
  maxUnjudgedPercent: config.maxUnjudgedPercent,
2781
2894
  maxNotExecutedPercent: config.maxNotExecutedPercent,
2782
2895
  checkpoint: checkpointStore,
2783
- evaluator
2896
+ evaluator,
2897
+ ...harness && { mcpHarness: harness }
2784
2898
  };
2785
2899
  const onEvent = opts.progress !== false ? handleEvent : void 0;
2786
- reservedScanId = await reserveScanSlot(credentials, target.url);
2900
+ reservedScanId = await reserveScanSlot(
2901
+ credentials,
2902
+ redactTargetUrl(target.url)
2903
+ );
2787
2904
  if (!reservedScanId) return;
2788
2905
  info("Scan started");
2789
2906
  const scanner = new Scanner(scanOptions, onEvent);
2790
2907
  const report = await scanner.run();
2908
+ const harnessWarning = harnessSkipWarning(report.attacks, harness);
2909
+ if (harnessWarning) console.warn(`
2910
+ \u26A0\uFE0F ${harnessWarning}
2911
+ `);
2791
2912
  if (evaluator.accountSuspended) {
2792
2913
  console.error(accountSuspendedMessage(credentials.apiUrl));
2793
2914
  setExitCode(2);
@@ -3005,6 +3126,8 @@ async function scanCommand(opts) {
3005
3126
  console.error(`Runtime error: ${msg}`);
3006
3127
  setExitCode(3);
3007
3128
  return;
3129
+ } finally {
3130
+ await harness?.stop();
3008
3131
  }
3009
3132
  }
3010
3133
 
@@ -3024,7 +3147,7 @@ async function testConnectionCommand(opts) {
3024
3147
  const target = buildTargetConfig(config);
3025
3148
  const systemPrompt = loadSystemPrompt(config);
3026
3149
  const message = opts.message ?? DEFAULT_MESSAGE;
3027
- console.log(`Target: ${target.url}`);
3150
+ console.log(`Target: ${redactTargetUrl(target.url)}`);
3028
3151
  if (target.request.encoding) {
3029
3152
  console.log(`Encoding: ${target.request.encoding}`);
3030
3153
  }
@@ -3141,7 +3264,7 @@ async function probeCarriersCommand(opts) {
3141
3264
  const log = (msg) => {
3142
3265
  if (!opts.ci) console.log(msg);
3143
3266
  };
3144
- log(`Target: ${target.url}`);
3267
+ log(`Target: ${redactTargetUrl(target.url)}`);
3145
3268
  log(`Canary: ${canary}`);
3146
3269
  log(
3147
3270
  "Probing invisible-carrier survival (transport half \u2014 no judge, no upload)\n"
@@ -3183,7 +3306,7 @@ async function probeCarriersCommand(opts) {
3183
3306
  console.log(
3184
3307
  JSON.stringify(
3185
3308
  {
3186
- target: target.url,
3309
+ target: redactTargetUrl(target.url),
3187
3310
  canary,
3188
3311
  controlEchoed: controlOk,
3189
3312
  survivedCount,
@@ -3292,7 +3415,7 @@ function validateCommand(opts) {
3292
3415
  try {
3293
3416
  const config = loadConfig({ configPath: opts.config });
3294
3417
  console.log("Configuration is valid.");
3295
- console.log(` Target: ${config.endpoint.url}`);
3418
+ console.log(` Target: ${redactTargetUrl(config.endpoint.url)}`);
3296
3419
  console.log(` Auth: ${config.endpoint.auth?.type ?? "none"}`);
3297
3420
  console.log(` Response field: ${config.endpoint.response.field}`);
3298
3421
  console.log(` Preset: ${config.preset ?? "standard"}`);
@@ -6329,6 +6452,12 @@ program.command("scan").description("Run a security scan against a target chatbo
6329
6452
  "--preset <name>",
6330
6453
  "Scan preset (dev, quick, owasp, frontier, standard, full)"
6331
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(
6332
6461
  "--mutate [ids]",
6333
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."
6334
6463
  ).option(
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  formatSarif,
9
9
  loadConfig,
10
10
  loadSystemPrompt
11
- } from "./chunk-S3XEHIPB.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.0",
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",