shield-llm 0.7.6 → 0.8.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
@@ -52,11 +52,13 @@ import {
52
52
  getObligationProfile,
53
53
  getStructuredRemediation,
54
54
  isExpired,
55
+ isFloorConfirmed,
55
56
  loadConfig,
56
57
  loadSystemPrompt,
57
58
  mayStampFixed,
58
59
  missingForContract,
59
60
  normalizeTargetUrl,
61
+ parseMaxUnjudgedPercent,
60
62
  parseSegmentKey,
61
63
  parseSnapshot,
62
64
  recordVerification,
@@ -68,7 +70,7 @@ import {
68
70
  sha256Hex,
69
71
  summarizeAttackErrors,
70
72
  version
71
- } from "./chunk-4OIZTQGA.js";
73
+ } from "./chunk-YYKI3IS7.js";
72
74
 
73
75
  // src/load-env.ts
74
76
  try {
@@ -1505,25 +1507,9 @@ function handleEvent(event) {
1505
1507
  `[${event.index + 1}/${event.total}] ${event.attack.name} (${severityColor(event.attack.severity)})`
1506
1508
  );
1507
1509
  break;
1508
- case "attack:complete": {
1509
- const { result } = event;
1510
- const prefix = `[${event.index + 1}/${event.total}]`;
1511
- if (result.error) {
1512
- spinner.warn(
1513
- `${prefix} ${result.name} \u2014 ${c.yellow("error")}: ${result.error}`
1514
- );
1515
- } else if (result.vulnerable) {
1516
- spinner.fail(
1517
- `${prefix} ${result.name} \u2014 ${c.red("VULNERABLE")} (${severityColor(result.severity)})`
1518
- );
1519
- } else {
1520
- spinner.succeed(`${prefix} ${result.name} \u2014 ${c.green("secure")}`);
1521
- }
1522
- if (event.index < event.total - 1) {
1523
- spinner.start();
1524
- }
1510
+ case "attack:complete":
1511
+ printAttackComplete(event);
1525
1512
  break;
1526
- }
1527
1513
  case "crescendo:turn":
1528
1514
  spinner.text = c.cyan(
1529
1515
  `${currentAttackName} \u2014 turn ${event.turn}/${event.totalTurns}`
@@ -1547,11 +1533,41 @@ function handleEvent(event) {
1547
1533
  );
1548
1534
  spinner.start();
1549
1535
  break;
1536
+ case "scan:rejudge":
1537
+ spinner.info(
1538
+ c.yellow(
1539
+ `Judge unavailable for ${event.pending} answer(s) \u2014 judging them again in ${(event.delayMs / 1e3).toFixed(0)}s (the target is not contacted again)`
1540
+ )
1541
+ );
1542
+ spinner.start();
1543
+ break;
1550
1544
  case "scan:complete":
1551
1545
  spinner.stop();
1552
1546
  break;
1553
1547
  }
1554
1548
  }
1549
+ function printAttackComplete(event) {
1550
+ const { result } = event;
1551
+ const prefix = `[${event.index + 1}/${event.total}]`;
1552
+ if (result.error) {
1553
+ spinner.warn(
1554
+ `${prefix} ${result.name} \u2014 ${c.yellow("error")}: ${result.error}`
1555
+ );
1556
+ } else if (result.llmEvaluation?.judgeError && !isFloorConfirmed(result.llmEvaluation)) {
1557
+ spinner.warn(
1558
+ `${prefix} ${result.name} \u2014 ${c.yellow("judge unavailable")}, judged again at the end of the scan`
1559
+ );
1560
+ } else if (result.vulnerable) {
1561
+ spinner.fail(
1562
+ `${prefix} ${result.name} \u2014 ${c.red("VULNERABLE")} (${severityColor(result.severity)})`
1563
+ );
1564
+ } else {
1565
+ spinner.succeed(`${prefix} ${result.name} \u2014 ${c.green("secure")}`);
1566
+ }
1567
+ if (event.index < event.total - 1) {
1568
+ spinner.start();
1569
+ }
1570
+ }
1555
1571
  function printSummary(report, thresholds) {
1556
1572
  console.log("");
1557
1573
  console.log(c.bold("\u2550\u2550\u2550 Shield LLM Scan Results \u2550\u2550\u2550"));
@@ -1563,16 +1579,17 @@ function printSummary(report, thresholds) {
1563
1579
  console.log("");
1564
1580
  const vulnerable = report.attacks.filter((a) => a.vulnerable);
1565
1581
  const secure = report.attacks.filter((a) => !a.vulnerable && !a.error);
1566
- const errors = report.attacks.filter((a) => a.error);
1582
+ const errors = report.attacks.filter((a) => a.error && !a.judgeUnavailable);
1583
+ const notJudged = report.attacks.filter((a) => a.judgeUnavailable);
1567
1584
  console.log(
1568
- ` ${c.red(`${vulnerable.length} vulnerable`)} \xB7 ${c.green(`${secure.length} secure`)} \xB7 ${c.yellow(`${errors.length} errors`)}`
1585
+ ` ${c.red(`${vulnerable.length} vulnerable`)} \xB7 ${c.green(`${secure.length} secure`)} \xB7 ${c.yellow(`${errors.length} errors`)}` + (notJudged.length > 0 ? ` \xB7 ${c.yellow(`${notJudged.length} not judged`)}` : "")
1569
1586
  );
1570
1587
  const evaluated = vulnerable.length + secure.length;
1571
1588
  const total = report.attacks.length;
1572
1589
  if (evaluated < total) {
1573
1590
  console.log(
1574
1591
  c.yellow(
1575
- ` Coverage: ${evaluated}/${total} evaluated \u2014 grade reflects only these; re-run to cover the ${total - evaluated} rate-limited/errored.`
1592
+ ` Coverage: ${evaluated}/${total} evaluated \u2014 grade reflects only these; re-run to cover the ${total - evaluated} rate-limited/errored/not judged.`
1576
1593
  )
1577
1594
  );
1578
1595
  } else {
@@ -1593,12 +1610,19 @@ function printSummary(report, thresholds) {
1593
1610
  console.log("");
1594
1611
  console.log(
1595
1612
  c.bgYellowBlackBold(" JUDGE DEGRADED ") + c.yellow(
1596
- ` ${judge.degradedCount}/${judge.totalEvaluated} verdicts fell back to regex (${judge.errorSummary}).`
1613
+ ` ${judge.degradedCount}/${judge.totalEvaluated} answers could not be judged (${judge.errorSummary}) and were left out of the score.`
1597
1614
  )
1598
1615
  );
1599
1616
  console.log(
1600
1617
  c.yellow(
1601
- " Regex-only verdicts are less reliable than LLM-assisted ones. False positives likely. Fix the LLM provider config and re-run."
1618
+ " Fix the LLM provider, or wait for it to recover, and re-run the scan to cover them."
1619
+ )
1620
+ );
1621
+ } else if (judge.rejudged > 0) {
1622
+ console.log("");
1623
+ console.log(
1624
+ c.yellow(
1625
+ ` Judge: ${judge.rejudged} answer(s) judged on a second try after a judge failure.`
1602
1626
  )
1603
1627
  );
1604
1628
  }
@@ -1925,6 +1949,7 @@ async function retestCommand(scanId, opts) {
1925
1949
  maxRateLimitRetries: config.maxRateLimitRetries,
1926
1950
  rateLimitBackoffMs: config.rateLimitBackoffMs,
1927
1951
  rateLimitMaxBackoffMs: config.rateLimitMaxBackoffMs,
1952
+ maxUnjudgedPercent: config.maxUnjudgedPercent,
1928
1953
  evaluator
1929
1954
  };
1930
1955
  const onEvent = opts.progress !== false ? handleEvent : void 0;
@@ -2549,6 +2574,16 @@ function incompleteScan(report, judged, total) {
2549
2574
  reason: `The scan stopped after repeated failed requests to the target, ${judged}/${total} attacks judged \u2014 the target is failing or unreachable. ${resume}`,
2550
2575
  exitCode: 3
2551
2576
  };
2577
+ case "judge_unavailable": {
2578
+ const notJudged = report.judgeRecovery?.notJudged ?? 0;
2579
+ const max = report.judgeRecovery?.maxUnjudgedPercent;
2580
+ const answered = judged + notJudged;
2581
+ const share = answered > 0 ? Math.round(notJudged / answered * 100) : 0;
2582
+ return {
2583
+ reason: `The judge was unavailable 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.`,
2584
+ exitCode: 3
2585
+ };
2586
+ }
2552
2587
  default:
2553
2588
  return null;
2554
2589
  }
@@ -2579,9 +2614,28 @@ function buildUploadVulnerabilities(attacks) {
2579
2614
  judgeId: a.llmEvaluation?.judgeId,
2580
2615
  confidence: a.llmEvaluation?.confidence,
2581
2616
  reasoning: a.llmEvaluation?.reasoning,
2582
- captureStatus: a.captureStatus ?? "captured"
2617
+ captureStatus: a.captureStatus ?? "captured",
2618
+ // Problems outside this attack's target, as the server's judge bounded
2619
+ // them. Absent when there are none (and from an older server).
2620
+ ...a.llmEvaluation?.incidental?.length && {
2621
+ incidentalFindings: a.llmEvaluation.incidental
2622
+ }
2583
2623
  }));
2584
2624
  }
2625
+ function judgeOutageRejection(status, body) {
2626
+ if (status !== 422) return null;
2627
+ try {
2628
+ const parsed = JSON.parse(body);
2629
+ return parsed.code === "judge_unavailable" && typeof parsed.error === "string" ? printableServerText(parsed.error) : null;
2630
+ } catch {
2631
+ return null;
2632
+ }
2633
+ }
2634
+ function printableServerText(text) {
2635
+ return text.replace(/[\r\n\t]+/g, " ").replace(/[\u0000-\u001f\u007f-\u009f]/g, "").slice(0, 300);
2636
+ }
2637
+ var JudgeOutageRejection = class extends Error {
2638
+ };
2585
2639
  async function uploadReportToBackend(report, credentials, scanId, attackPackVersion) {
2586
2640
  const vulnerabilities = buildUploadVulnerabilities(report.attacks);
2587
2641
  const testsRun = scoredAttacks(report.attacks).length;
@@ -2611,6 +2665,8 @@ async function uploadReportToBackend(report, credentials, scanId, attackPackVers
2611
2665
  });
2612
2666
  if (!res.ok) {
2613
2667
  const body = await res.text().catch(() => "");
2668
+ const outage = judgeOutageRejection(res.status, body);
2669
+ if (outage) throw new JudgeOutageRejection(outage);
2614
2670
  throw new Error(`HTTP ${res.status}: ${body.slice(0, 200)}`);
2615
2671
  }
2616
2672
  const data = await res.json().catch(() => ({}));
@@ -2717,6 +2773,8 @@ function buildCliOverrides(opts) {
2717
2773
  cliOverrides.maxRateLimitRetries = opts.retries;
2718
2774
  if (opts.maxFloorThrottles !== void 0)
2719
2775
  cliOverrides.maxFloorThrottles = opts.maxFloorThrottles;
2776
+ if (opts.maxUnjudged !== void 0)
2777
+ cliOverrides.maxUnjudgedPercent = opts.maxUnjudged;
2720
2778
  return cliOverrides;
2721
2779
  }
2722
2780
  async function scanCommand(opts) {
@@ -2902,6 +2960,7 @@ async function scanCommand(opts) {
2902
2960
  rateLimitMaxBackoffMs: config.rateLimitMaxBackoffMs,
2903
2961
  maxDelayMs: config.maxDelayMs,
2904
2962
  maxFloorThrottles: config.maxFloorThrottles,
2963
+ maxUnjudgedPercent: config.maxUnjudgedPercent,
2905
2964
  checkpoint: checkpointStore,
2906
2965
  evaluator
2907
2966
  };
@@ -2962,6 +3021,12 @@ async function scanCommand(opts) {
2962
3021
  );
2963
3022
  }
2964
3023
  } catch (err) {
3024
+ if (err instanceof JudgeOutageRejection) {
3025
+ scanFinalized = true;
3026
+ console.error(`Scan stopped: ${err.message}`);
3027
+ setExitCode(3);
3028
+ return;
3029
+ }
2965
3030
  const msg = err instanceof Error ? err.message : String(err);
2966
3031
  console.warn(`Warning: Could not save scan to dashboard: ${msg}`);
2967
3032
  console.warn(
@@ -4573,7 +4638,7 @@ function passDetail(baseline, cases, report, judged, afterRun) {
4573
4638
  const splitNote = split ? `, ${split} split vote(s) read against the patch` : "";
4574
4639
  return `${cases.length} cases judged, ${report.flips.length} flip(s)${excluded}${splitNote}`;
4575
4640
  }
4576
- async function replayFamily(contract, target, catalogue, evaluator) {
4641
+ async function replayFamily(contract, target, catalogue, evaluator, judgeRetryDelayMs) {
4577
4642
  const attacks = attacksForContract(contract, catalogue);
4578
4643
  const report = await new Scanner({
4579
4644
  target,
@@ -4584,7 +4649,9 @@ async function replayFamily(contract, target, catalogue, evaluator) {
4584
4649
  attacks,
4585
4650
  evaluator,
4586
4651
  concurrency: 1,
4587
- delayMs: 0
4652
+ delayMs: 0,
4653
+ // Undefined keeps the scanner's default pause before its re-judge pass.
4654
+ judgeRetryDelayMs
4588
4655
  }).run();
4589
4656
  const verdicts = /* @__PURE__ */ new Map();
4590
4657
  for (const a of report.attacks) {
@@ -4599,7 +4666,8 @@ async function verifyLive(input2) {
4599
4666
  contract,
4600
4667
  input2.target,
4601
4668
  input2.catalogue,
4602
- input2.evaluator
4669
+ input2.evaluator,
4670
+ input2.judgeRetryDelayMs
4603
4671
  );
4604
4672
  const cleared = (id) => verdicts.get(id) === false;
4605
4673
  const executed = (id) => verdicts.has(id);
@@ -5888,6 +5956,13 @@ function parseIntArg(value) {
5888
5956
  }
5889
5957
  return n;
5890
5958
  }
5959
+ function parsePercentArg(value) {
5960
+ const n = parseMaxUnjudgedPercent(value);
5961
+ if (n === null) {
5962
+ throw new InvalidArgumentError("Expected a percentage from 0 to 100.");
5963
+ }
5964
+ return n;
5965
+ }
5891
5966
  function parseFloatArg(value) {
5892
5967
  const n = Number.parseFloat(value);
5893
5968
  if (Number.isNaN(n)) {
@@ -5958,6 +6033,10 @@ program.command("scan").description("Run a security scan against a target chatbo
5958
6033
  "--max-floor-throttles <n>",
5959
6034
  "Consecutive throttles at the pacing floor before hard-stopping (default 3)",
5960
6035
  parseIntArg
6036
+ ).option(
6037
+ "--max-unjudged <percent>",
6038
+ "Share of answered attacks the judge may fail to rule on before the scan is incomplete (default 10)",
6039
+ parsePercentArg
5961
6040
  ).option("--min-score <n>", "Minimum score threshold", parseFloat).option("--fail-on-critical", "Fail if any CRITICAL vulnerability found").option(
5962
6041
  "--no-fail-on-critical",
5963
6042
  "Report CRITICAL findings without failing the run"
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  generatePdf,
10
10
  loadConfig,
11
11
  loadSystemPrompt
12
- } from "./chunk-4OIZTQGA.js";
12
+ } from "./chunk-YYKI3IS7.js";
13
13
  export {
14
14
  ConfigError,
15
15
  ConfigSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shield-llm",
3
- "version": "0.7.6",
3
+ "version": "0.8.0",
4
4
  "description": "AI chatbot security scanner — automated red teaming for LLMs",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "scripts": {
44
44
  "lint": "eslint src --ext .ts",
45
- "build": "tsc --noEmit && tsup && node scripts/check-bundle-ip.mjs && cp src/reporters/assets/logo.png dist/",
45
+ "build": "tsc --noEmit && tsup && node scripts/check-bundle-ip.mjs && node scripts/check-bundle-deps.mjs && cp src/reporters/assets/logo.png dist/",
46
46
  "dev": "tsx src/cli.ts",
47
47
  "test": "vitest run",
48
48
  "mock-server": "tsx test-server/server.ts",