shield-llm 0.16.0 → 0.16.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.
@@ -9536,7 +9536,7 @@ function parseImportFile(textContent, format) {
9536
9536
  }
9537
9537
 
9538
9538
  // package.json
9539
- var version = "0.16.0";
9539
+ var version = "0.16.1";
9540
9540
 
9541
9541
  // src/config/schema.ts
9542
9542
  import { z as z3 } from "zod";
@@ -12537,7 +12537,9 @@ var CONFIG_FILENAMES = ["shield.config.json"];
12537
12537
  function loadConfig(options) {
12538
12538
  const { configPath, cliOverrides } = options;
12539
12539
  let fileConfig = {};
12540
+ let fileFound = false;
12540
12541
  if (configPath) {
12542
+ fileFound = true;
12541
12543
  const fullPath = resolve(configPath);
12542
12544
  if (!existsSync(fullPath)) {
12543
12545
  throw new ConfigError(`Config file not found: ${fullPath}`);
@@ -12548,10 +12550,17 @@ function loadConfig(options) {
12548
12550
  const fullPath = resolve(filename);
12549
12551
  if (existsSync(fullPath)) {
12550
12552
  fileConfig = readJsonFile(fullPath);
12553
+ fileFound = true;
12551
12554
  break;
12552
12555
  }
12553
12556
  }
12554
12557
  }
12558
+ if (!fileFound && !cliOverrides?.endpoint?.url) {
12559
+ throw new ConfigError(
12560
+ `No ${CONFIG_FILENAMES[0]} in ${process.cwd()}.
12561
+ Run \`shield-llm init\` to create one, or pass --config <path>.`
12562
+ );
12563
+ }
12555
12564
  const merged = deepMerge(fileConfig, cliOverrides ?? {});
12556
12565
  const result = ConfigSchema.safeParse(merged);
12557
12566
  if (!result.success) {
@@ -12887,8 +12896,36 @@ var CATEGORY_LABELS = {
12887
12896
  provider_error: "LLM provider returned a server error",
12888
12897
  unknown: "LLM judge failed (see backend logs)"
12889
12898
  };
12899
+ var SHIELD_BUDGET_LABELS = {
12900
+ shield_daily_user_budget: "your daily judge budget on this Shield instance is spent; it resets at 00:00 UTC, or ask your Shield administrator to raise it",
12901
+ shield_daily_total_budget: "this Shield instance's daily judge budget is spent; it resets at 00:00 UTC"
12902
+ };
12903
+ function summaryFor(category, codes) {
12904
+ const seen = codes.get(category);
12905
+ if (seen?.size === 1) {
12906
+ const label = budgetLabel(Array.from(seen)[0]);
12907
+ if (label) return label;
12908
+ }
12909
+ return CATEGORY_LABELS[category];
12910
+ }
12911
+ function shieldBudgetReason(report) {
12912
+ const codes = /* @__PURE__ */ new Set();
12913
+ for (const a of report.attacks) {
12914
+ if (!a.llmEvaluation) continue;
12915
+ const judgeError = extractJudgeError(a.llmEvaluation);
12916
+ if (judgeError && !isFloorConfirmed(a.llmEvaluation)) {
12917
+ codes.add(judgeError.providerCode);
12918
+ }
12919
+ }
12920
+ if (codes.size !== 1) return null;
12921
+ return budgetLabel(Array.from(codes)[0]);
12922
+ }
12923
+ function budgetLabel(code) {
12924
+ return code && Object.prototype.hasOwnProperty.call(SHIELD_BUDGET_LABELS, code) ? SHIELD_BUDGET_LABELS[code] : null;
12925
+ }
12890
12926
  function analyzeJudgeHealth(report) {
12891
12927
  const counts = /* @__PURE__ */ new Map();
12928
+ const codes = /* @__PURE__ */ new Map();
12892
12929
  let degradedCount = 0;
12893
12930
  let totalEvaluated = 0;
12894
12931
  for (const a of report.attacks) {
@@ -12897,7 +12934,13 @@ function analyzeJudgeHealth(report) {
12897
12934
  const judgeError = extractJudgeError(a.llmEvaluation);
12898
12935
  if (judgeError && !isFloorConfirmed(a.llmEvaluation)) {
12899
12936
  degradedCount += 1;
12900
- counts.set(judgeError.category, (counts.get(judgeError.category) ?? 0) + 1);
12937
+ counts.set(
12938
+ judgeError.category,
12939
+ (counts.get(judgeError.category) ?? 0) + 1
12940
+ );
12941
+ const seen = codes.get(judgeError.category) ?? /* @__PURE__ */ new Set();
12942
+ seen.add(judgeError.providerCode);
12943
+ codes.set(judgeError.category, seen);
12901
12944
  }
12902
12945
  }
12903
12946
  const rejudged = report.judgeRecovery?.rejudged ?? 0;
@@ -12920,7 +12963,7 @@ function analyzeJudgeHealth(report) {
12920
12963
  degradedCount,
12921
12964
  totalEvaluated,
12922
12965
  category,
12923
- errorSummary: CATEGORY_LABELS[category],
12966
+ errorSummary: summaryFor(category, codes),
12924
12967
  rejudged,
12925
12968
  notJudged: notJudged2
12926
12969
  };
@@ -13271,6 +13314,8 @@ export {
13271
13314
  parseImportFile,
13272
13315
  version,
13273
13316
  RateLimitError,
13317
+ isPrivateUrl,
13318
+ assertPublicHost,
13274
13319
  checkConversationContext,
13275
13320
  checkSessionIsolation,
13276
13321
  createTargetClient,
@@ -13291,6 +13336,7 @@ export {
13291
13336
  buildEndpointOverride,
13292
13337
  ConfigError,
13293
13338
  c2 as c,
13339
+ shieldBudgetReason,
13294
13340
  analyzeJudgeHealth,
13295
13341
  evaluateThresholds,
13296
13342
  formatComplianceTerminal,
package/dist/cli.js CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  analyzeJudgeHealth,
34
34
  articleNumberEn,
35
35
  aspectArticleLabel,
36
+ assertPublicHost,
36
37
  attacksForContract,
37
38
  baseAttackId,
38
39
  buildEndpointOverride,
@@ -69,6 +70,7 @@ import {
69
70
  isExpired,
70
71
  isFloorConfirmed,
71
72
  isHardFailBreach,
73
+ isPrivateUrl,
72
74
  loadConfig,
73
75
  loadSystemPrompt,
74
76
  mayStampFixed,
@@ -84,11 +86,12 @@ import {
84
86
  retestDedupKey,
85
87
  serializeAttack,
86
88
  sha256Hex,
89
+ shieldBudgetReason,
87
90
  summarizeAttackErrors,
88
91
  summarizeObfuscationVariants,
89
92
  version,
90
93
  withoutScoredApartVariants
91
- } from "./chunk-O2K6SD5X.js";
94
+ } from "./chunk-SLKNCJV5.js";
92
95
 
93
96
  // src/load-env.ts
94
97
  var PROTECTED_ENV_KEYS = [
@@ -463,6 +466,20 @@ var PRESET_CHOICES = [
463
466
  name: "full \u2014 Everything, multi-turn attacks included"
464
467
  }
465
468
  ];
469
+ function buildInitEndpoint(answers) {
470
+ const { url, method, auth, body, responseField, customHeaders } = answers;
471
+ return {
472
+ url,
473
+ ...isPrivateUrl(url) && { allowPrivateUrls: true },
474
+ request: {
475
+ method,
476
+ ...Object.keys(customHeaders).length > 0 && { headers: customHeaders },
477
+ body
478
+ },
479
+ response: { field: responseField },
480
+ auth: auth.type !== "none" ? auth : { type: "none" }
481
+ };
482
+ }
466
483
  async function initCommand() {
467
484
  console.log("\nShield LLM \u2014 Configuration wizard\n");
468
485
  if (!process.stdin.isTTY) {
@@ -507,19 +524,18 @@ async function initCommand() {
507
524
  choices: PRESET_CHOICES,
508
525
  default: "standard"
509
526
  });
510
- const endpoint = {
527
+ const endpoint = buildInitEndpoint({
511
528
  url,
512
- request: {
513
- method,
514
- ...Object.keys(customHeaders).length > 0 && { headers: customHeaders },
515
- body
516
- },
517
- response: { field: responseField }
518
- };
519
- if (auth.type !== "none") {
520
- endpoint.auth = auth;
521
- } else {
522
- endpoint.auth = { type: "none" };
529
+ method,
530
+ auth,
531
+ body,
532
+ responseField,
533
+ customHeaders
534
+ });
535
+ if (endpoint.allowPrivateUrls) {
536
+ console.log(
537
+ '\nThis is a local or private address: the config sets "allowPrivateUrls": true so the scan accepts it.'
538
+ );
523
539
  }
524
540
  const config = { endpoint, preset };
525
541
  const result = ConfigSchema.safeParse(config);
@@ -855,6 +871,16 @@ var ClaimStore = class _ClaimStore {
855
871
  }
856
872
  };
857
873
 
874
+ // src/lib/scan-not-found.ts
875
+ var SHORT_LABEL_MAX = 12;
876
+ function shortIdHint(scanId) {
877
+ if (scanId.length > SHORT_LABEL_MAX) return "";
878
+ return "\n This looks like the short label shown on the dashboard. Use the full scan id:\n it is in the scan page's address and in its Scan Info panel (copy button).";
879
+ }
880
+ function scanNotFoundMessage(scanId) {
881
+ return `Scan "${scanId}" not found.${shortIdHint(scanId)}`;
882
+ }
883
+
858
884
  // src/lib/format.ts
859
885
  function truncate(str, max) {
860
886
  const oneLine = str.replace(/\n/g, " ").trim();
@@ -1171,7 +1197,7 @@ async function reportCommand(scanId, opts) {
1171
1197
  }
1172
1198
  if (res.status === 404) {
1173
1199
  await res.text().catch(() => void 0);
1174
- console.error(`Scan "${scanId}" not found.`);
1200
+ console.error(scanNotFoundMessage(scanId));
1175
1201
  process.exitCode = 2;
1176
1202
  return;
1177
1203
  }
@@ -1693,6 +1719,28 @@ function gradeColor(grade) {
1693
1719
  }
1694
1720
  }
1695
1721
 
1722
+ // src/lib/private-target.ts
1723
+ function refusal(url) {
1724
+ return `${redactTargetUrl(url)} is a local or private address. Shield refuses those unless you allow it:
1725
+ - add "allowPrivateUrls": true to the "endpoint" block of shield.config.json, or
1726
+ - pass --allow-private-urls to \`shield-llm scan\` or \`shield-llm retest\` for one run.`;
1727
+ }
1728
+ function privateTargetProblem(endpoint) {
1729
+ if (endpoint.allowPrivateUrls || !isPrivateUrl(endpoint.url)) return null;
1730
+ return refusal(endpoint.url);
1731
+ }
1732
+ async function resolvedPrivateTargetProblem(endpoint, assertPublic = assertPublicHost) {
1733
+ if (endpoint.allowPrivateUrls) return null;
1734
+ if (isPrivateUrl(endpoint.url)) return refusal(endpoint.url);
1735
+ try {
1736
+ await assertPublic(endpoint.url);
1737
+ return null;
1738
+ } catch (error) {
1739
+ const message = error instanceof Error ? error.message : "";
1740
+ return /private\/internal address/.test(message) ? refusal(endpoint.url) : null;
1741
+ }
1742
+ }
1743
+
1696
1744
  // src/commands/retest.ts
1697
1745
  function findingLabel(finding) {
1698
1746
  return `${finding.name} (${finding.severity})`;
@@ -1734,7 +1782,7 @@ async function retestCommand(scanId, opts) {
1734
1782
  }
1735
1783
  if (res.status === 404) {
1736
1784
  await res.text().catch(() => void 0);
1737
- console.error(`Scan "${scanId}" not found.`);
1785
+ console.error(scanNotFoundMessage(scanId));
1738
1786
  setExitCode(2);
1739
1787
  return;
1740
1788
  }
@@ -1780,6 +1828,12 @@ async function retestCommand(scanId, opts) {
1780
1828
  const endpoint = buildEndpointOverride(opts);
1781
1829
  if (endpoint) cliOverrides.endpoint = endpoint;
1782
1830
  const config = loadConfig({ configPath: opts.config, cliOverrides });
1831
+ const privateProblem = await resolvedPrivateTargetProblem(config.endpoint);
1832
+ if (privateProblem) {
1833
+ console.error(privateProblem);
1834
+ setExitCode(2);
1835
+ return;
1836
+ }
1783
1837
  const systemPrompt = loadSystemPrompt(config);
1784
1838
  const endpointHost = safeHostname(config.endpoint?.url);
1785
1839
  const shownTarget = config.endpoint?.url ? redactTargetUrl(config.endpoint.url) : void 0;
@@ -2101,7 +2155,7 @@ async function postSupplementBatch(credentials, scanId, body) {
2101
2155
  if (res.status === 401) {
2102
2156
  message = "API key is invalid or revoked. Run `shield-llm login` to re-authenticate.";
2103
2157
  } else if (res.status === 404) {
2104
- message = `Scan "${scanId}" not found, or not completed, in your account.`;
2158
+ message = `Scan "${scanId}" not found, or not completed, in your account.${shortIdHint(scanId)}`;
2105
2159
  }
2106
2160
  throw new SupplementUploadError(
2107
2161
  `HTTP ${res.status}: ${message}`,
@@ -3010,7 +3064,15 @@ function alignOutputExtension(file, format) {
3010
3064
  }
3011
3065
 
3012
3066
  // src/lib/incomplete-scan.ts
3013
- function incompleteScan(report, judged, total) {
3067
+ function judgeUnavailableReason(report, judged, budgetReason) {
3068
+ const notJudged = report.judgeRecovery?.notJudged ?? 0;
3069
+ const max = report.judgeRecovery?.maxUnjudgedPercent;
3070
+ const answered = judged + notJudged;
3071
+ const share = answered > 0 ? Math.round(notJudged / answered * 100) : 0;
3072
+ const head = `${JUDGE_OUTAGE_REASON_PREFIX} for ${notJudged} of ${answered} answered attacks (${share}%), above the ${max}% limit (--max-unjudged), so nothing was scored`;
3073
+ return budgetReason ? `${head}: ${budgetReason}. Re-run the same command after 00:00 UTC or once the budget is raised: the ${judged} judged attack(s) resume from the checkpoint.` : `${head}. Re-run the same command later: the ${judged} judged attack(s) resume from the checkpoint.`;
3074
+ }
3075
+ function incompleteScan(report, judged, total, budgetReason = null) {
3014
3076
  const resume = `Re-run the same command: the ${judged} judged attack(s) resume from the checkpoint.`;
3015
3077
  switch (report.stopReason) {
3016
3078
  case "auth":
@@ -3028,16 +3090,11 @@ function incompleteScan(report, judged, total) {
3028
3090
  reason: `The scan stopped after repeated failed requests to the target, ${judged}/${total} attacks judged \u2014 the target is failing or unreachable. ${resume}`,
3029
3091
  exitCode: 3
3030
3092
  };
3031
- case "judge_unavailable": {
3032
- const notJudged = report.judgeRecovery?.notJudged ?? 0;
3033
- const max = report.judgeRecovery?.maxUnjudgedPercent;
3034
- const answered = judged + notJudged;
3035
- const share = answered > 0 ? Math.round(notJudged / answered * 100) : 0;
3093
+ case "judge_unavailable":
3036
3094
  return {
3037
- reason: `${JUDGE_OUTAGE_REASON_PREFIX} for ${notJudged} of ${answered} answered attacks (${share}%), above the ${max}% limit (--max-unjudged), so nothing was scored. Re-run the same command later: the ${judged} judged attack(s) resume from the checkpoint.`,
3095
+ reason: judgeUnavailableReason(report, judged, budgetReason),
3038
3096
  exitCode: 3
3039
3097
  };
3040
- }
3041
3098
  case "not_executed": {
3042
3099
  const coverage = report.runCoverage;
3043
3100
  const notExecuted = coverage?.notExecuted ?? 0;
@@ -3103,12 +3160,12 @@ function serverRefusal(status, body) {
3103
3160
  }
3104
3161
  }
3105
3162
  function incompleteRejection(status, body) {
3106
- const refusal = serverRefusal(status, body);
3107
- return refusal && INCOMPLETE_CODES.has(refusal.code) ? refusal.reason : null;
3163
+ const refusal2 = serverRefusal(status, body);
3164
+ return refusal2 && INCOMPLETE_CODES.has(refusal2.code) ? refusal2.reason : null;
3108
3165
  }
3109
3166
  function notStoredRejection(status, body) {
3110
- const refusal = serverRefusal(status, body);
3111
- return refusal?.code === NOT_STORED_CODE ? refusal.reason : null;
3167
+ const refusal2 = serverRefusal(status, body);
3168
+ return refusal2?.code === NOT_STORED_CODE ? refusal2.reason : null;
3112
3169
  }
3113
3170
  function printableServerText(text) {
3114
3171
  return text.replace(/[\r\n\t]+/g, " ").replace(/[\u0000-\u001f\u007f-\u009f]/g, "").slice(0, 300);
@@ -3404,6 +3461,12 @@ async function scanCommand(opts) {
3404
3461
  }
3405
3462
  }
3406
3463
  const target = buildTargetConfig(config);
3464
+ const privateProblem = await resolvedPrivateTargetProblem(target);
3465
+ if (privateProblem) {
3466
+ console.error(privateProblem);
3467
+ setExitCode(2);
3468
+ return;
3469
+ }
3407
3470
  const isolation = checkSessionIsolation(target);
3408
3471
  if (!isolation.isolated) console.warn(`
3409
3472
  \u26A0\uFE0F ${isolation.warning}
@@ -3486,7 +3549,12 @@ async function scanCommand(opts) {
3486
3549
  const attempted = report.attacks.length;
3487
3550
  const evaluated = scoredAttacks(report.attacks).length;
3488
3551
  const nothingRan = report.stopReason === "not_executed" && evaluated === 0;
3489
- const incomplete = nothingRan ? null : incompleteScan(report, evaluated, attempted);
3552
+ const incomplete = nothingRan ? null : incompleteScan(
3553
+ report,
3554
+ evaluated,
3555
+ attempted,
3556
+ shieldBudgetReason(report)
3557
+ );
3490
3558
  if (incomplete) {
3491
3559
  await reportScanFailure(credentials, reservedScanId, incomplete.reason);
3492
3560
  scanFinalized = true;
@@ -3726,6 +3794,12 @@ async function testConnectionCommand(opts) {
3726
3794
  return;
3727
3795
  }
3728
3796
  const target = buildTargetConfig(config);
3797
+ const privateProblem = await resolvedPrivateTargetProblem(target);
3798
+ if (privateProblem) {
3799
+ console.error(privateProblem);
3800
+ setExitCode(2);
3801
+ return;
3802
+ }
3729
3803
  const systemPrompt = loadSystemPrompt(config);
3730
3804
  const message = opts.message ?? DEFAULT_MESSAGE;
3731
3805
  console.log(`Target: ${redactTargetUrl(target.url)}`);
@@ -3931,7 +4005,9 @@ async function testsCommand(opts) {
3931
4005
  if (opts.remote) {
3932
4006
  const stored = loadCredentials();
3933
4007
  if (!stored) {
3934
- console.error("Not logged in. Run: shield-llm login --key <your-key>\n");
4008
+ console.error(
4009
+ "Not logged in. Run: shield-llm login --key <api-key> --api-url <your-instance-url>\n"
4010
+ );
3935
4011
  setExitCode(2);
3936
4012
  return;
3937
4013
  }
@@ -4003,6 +4079,9 @@ function validateCommand(opts) {
4003
4079
  if (config.customTests?.length) {
4004
4080
  console.log(` Custom tests: ${config.customTests.length}`);
4005
4081
  }
4082
+ const privateProblem = privateTargetProblem(config.endpoint);
4083
+ if (privateProblem) console.warn(`
4084
+ \u26A0\uFE0F ${privateProblem}`);
4006
4085
  setExitCode(0);
4007
4086
  return;
4008
4087
  } catch (error) {
@@ -6063,7 +6142,7 @@ async function fetchStoredScan(apiUrl, apiKey, scanId) {
6063
6142
  "API key invalid or revoked. Run `shield-llm login` to re-authenticate."
6064
6143
  );
6065
6144
  }
6066
- if (res.status === 404) throw new Error(`Scan "${scanId}" not found.`);
6145
+ if (res.status === 404) throw new Error(scanNotFoundMessage(scanId));
6067
6146
  throw new Error(`The dashboard returned HTTP ${res.status} for the scan.`);
6068
6147
  }
6069
6148
  const scan = await res.json();
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  formatSarif,
9
9
  loadConfig,
10
10
  loadSystemPrompt
11
- } from "./chunk-O2K6SD5X.js";
11
+ } from "./chunk-SLKNCJV5.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.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "AI chatbot security scanner — automated red teaming for LLMs",
5
5
  "type": "module",
6
6
  "publishConfig": {