shield-llm 0.7.6 → 0.9.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/{chunk-4OIZTQGA.js → chunk-LWHD2TWF.js} +759 -156
- package/dist/cli.js +117 -33
- package/dist/index.js +1 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
createClaim,
|
|
37
37
|
createTargetClient,
|
|
38
38
|
crosswalkControls,
|
|
39
|
+
declaredCustomTestSeverity,
|
|
39
40
|
deserializeAttack,
|
|
40
41
|
deserializeMultiTurnAttack,
|
|
41
42
|
evaluateBenign,
|
|
@@ -52,11 +53,13 @@ import {
|
|
|
52
53
|
getObligationProfile,
|
|
53
54
|
getStructuredRemediation,
|
|
54
55
|
isExpired,
|
|
56
|
+
isFloorConfirmed,
|
|
55
57
|
loadConfig,
|
|
56
58
|
loadSystemPrompt,
|
|
57
59
|
mayStampFixed,
|
|
58
60
|
missingForContract,
|
|
59
61
|
normalizeTargetUrl,
|
|
62
|
+
parseMaxUnjudgedPercent,
|
|
60
63
|
parseSegmentKey,
|
|
61
64
|
parseSnapshot,
|
|
62
65
|
recordVerification,
|
|
@@ -68,7 +71,7 @@ import {
|
|
|
68
71
|
sha256Hex,
|
|
69
72
|
summarizeAttackErrors,
|
|
70
73
|
version
|
|
71
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-LWHD2TWF.js";
|
|
72
75
|
|
|
73
76
|
// src/load-env.ts
|
|
74
77
|
try {
|
|
@@ -1250,11 +1253,15 @@ async function fetchCustomTests(apiUrl, apiKey) {
|
|
|
1250
1253
|
}
|
|
1251
1254
|
const scans = await res.json();
|
|
1252
1255
|
return scans.filter((scan) => scan.isActive).flatMap(
|
|
1253
|
-
(scan) => scan.tests.map((test) =>
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1256
|
+
(scan) => scan.tests.map((test) => {
|
|
1257
|
+
const severity = declaredCustomTestSeverity(test.severity);
|
|
1258
|
+
return {
|
|
1259
|
+
name: test.name,
|
|
1260
|
+
prompt: test.prompt,
|
|
1261
|
+
acceptanceCriteria: test.acceptanceCriteria,
|
|
1262
|
+
...severity ? { severity } : {}
|
|
1263
|
+
};
|
|
1264
|
+
})
|
|
1258
1265
|
);
|
|
1259
1266
|
}
|
|
1260
1267
|
|
|
@@ -1505,25 +1512,9 @@ function handleEvent(event) {
|
|
|
1505
1512
|
`[${event.index + 1}/${event.total}] ${event.attack.name} (${severityColor(event.attack.severity)})`
|
|
1506
1513
|
);
|
|
1507
1514
|
break;
|
|
1508
|
-
case "attack:complete":
|
|
1509
|
-
|
|
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
|
-
}
|
|
1515
|
+
case "attack:complete":
|
|
1516
|
+
printAttackComplete(event);
|
|
1525
1517
|
break;
|
|
1526
|
-
}
|
|
1527
1518
|
case "crescendo:turn":
|
|
1528
1519
|
spinner.text = c.cyan(
|
|
1529
1520
|
`${currentAttackName} \u2014 turn ${event.turn}/${event.totalTurns}`
|
|
@@ -1547,11 +1538,41 @@ function handleEvent(event) {
|
|
|
1547
1538
|
);
|
|
1548
1539
|
spinner.start();
|
|
1549
1540
|
break;
|
|
1541
|
+
case "scan:rejudge":
|
|
1542
|
+
spinner.info(
|
|
1543
|
+
c.yellow(
|
|
1544
|
+
`Judge unavailable for ${event.pending} answer(s) \u2014 judging them again in ${(event.delayMs / 1e3).toFixed(0)}s (the target is not contacted again)`
|
|
1545
|
+
)
|
|
1546
|
+
);
|
|
1547
|
+
spinner.start();
|
|
1548
|
+
break;
|
|
1550
1549
|
case "scan:complete":
|
|
1551
1550
|
spinner.stop();
|
|
1552
1551
|
break;
|
|
1553
1552
|
}
|
|
1554
1553
|
}
|
|
1554
|
+
function printAttackComplete(event) {
|
|
1555
|
+
const { result } = event;
|
|
1556
|
+
const prefix = `[${event.index + 1}/${event.total}]`;
|
|
1557
|
+
if (result.error) {
|
|
1558
|
+
spinner.warn(
|
|
1559
|
+
`${prefix} ${result.name} \u2014 ${c.yellow("error")}: ${result.error}`
|
|
1560
|
+
);
|
|
1561
|
+
} else if (result.llmEvaluation?.judgeError && !isFloorConfirmed(result.llmEvaluation)) {
|
|
1562
|
+
spinner.warn(
|
|
1563
|
+
`${prefix} ${result.name} \u2014 ${c.yellow("judge unavailable")}, judged again at the end of the scan`
|
|
1564
|
+
);
|
|
1565
|
+
} else if (result.vulnerable) {
|
|
1566
|
+
spinner.fail(
|
|
1567
|
+
`${prefix} ${result.name} \u2014 ${c.red("VULNERABLE")} (${severityColor(result.severity)})`
|
|
1568
|
+
);
|
|
1569
|
+
} else {
|
|
1570
|
+
spinner.succeed(`${prefix} ${result.name} \u2014 ${c.green("secure")}`);
|
|
1571
|
+
}
|
|
1572
|
+
if (event.index < event.total - 1) {
|
|
1573
|
+
spinner.start();
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1555
1576
|
function printSummary(report, thresholds) {
|
|
1556
1577
|
console.log("");
|
|
1557
1578
|
console.log(c.bold("\u2550\u2550\u2550 Shield LLM Scan Results \u2550\u2550\u2550"));
|
|
@@ -1563,16 +1584,17 @@ function printSummary(report, thresholds) {
|
|
|
1563
1584
|
console.log("");
|
|
1564
1585
|
const vulnerable = report.attacks.filter((a) => a.vulnerable);
|
|
1565
1586
|
const secure = report.attacks.filter((a) => !a.vulnerable && !a.error);
|
|
1566
|
-
const errors = report.attacks.filter((a) => a.error);
|
|
1587
|
+
const errors = report.attacks.filter((a) => a.error && !a.judgeUnavailable);
|
|
1588
|
+
const notJudged = report.attacks.filter((a) => a.judgeUnavailable);
|
|
1567
1589
|
console.log(
|
|
1568
|
-
` ${c.red(`${vulnerable.length} vulnerable`)} \xB7 ${c.green(`${secure.length} secure`)} \xB7 ${c.yellow(`${errors.length} errors`)}`
|
|
1590
|
+
` ${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
1591
|
);
|
|
1570
1592
|
const evaluated = vulnerable.length + secure.length;
|
|
1571
1593
|
const total = report.attacks.length;
|
|
1572
1594
|
if (evaluated < total) {
|
|
1573
1595
|
console.log(
|
|
1574
1596
|
c.yellow(
|
|
1575
|
-
` Coverage: ${evaluated}/${total} evaluated \u2014 grade reflects only these; re-run to cover the ${total - evaluated} rate-limited/errored.`
|
|
1597
|
+
` Coverage: ${evaluated}/${total} evaluated \u2014 grade reflects only these; re-run to cover the ${total - evaluated} rate-limited/errored/not judged.`
|
|
1576
1598
|
)
|
|
1577
1599
|
);
|
|
1578
1600
|
} else {
|
|
@@ -1593,12 +1615,19 @@ function printSummary(report, thresholds) {
|
|
|
1593
1615
|
console.log("");
|
|
1594
1616
|
console.log(
|
|
1595
1617
|
c.bgYellowBlackBold(" JUDGE DEGRADED ") + c.yellow(
|
|
1596
|
-
` ${judge.degradedCount}/${judge.totalEvaluated}
|
|
1618
|
+
` ${judge.degradedCount}/${judge.totalEvaluated} answers could not be judged (${judge.errorSummary}) and were left out of the score.`
|
|
1597
1619
|
)
|
|
1598
1620
|
);
|
|
1599
1621
|
console.log(
|
|
1600
1622
|
c.yellow(
|
|
1601
|
-
"
|
|
1623
|
+
" Fix the LLM provider, or wait for it to recover, and re-run the scan to cover them."
|
|
1624
|
+
)
|
|
1625
|
+
);
|
|
1626
|
+
} else if (judge.rejudged > 0) {
|
|
1627
|
+
console.log("");
|
|
1628
|
+
console.log(
|
|
1629
|
+
c.yellow(
|
|
1630
|
+
` Judge: ${judge.rejudged} answer(s) judged on a second try after a judge failure.`
|
|
1602
1631
|
)
|
|
1603
1632
|
);
|
|
1604
1633
|
}
|
|
@@ -1925,6 +1954,7 @@ async function retestCommand(scanId, opts) {
|
|
|
1925
1954
|
maxRateLimitRetries: config.maxRateLimitRetries,
|
|
1926
1955
|
rateLimitBackoffMs: config.rateLimitBackoffMs,
|
|
1927
1956
|
rateLimitMaxBackoffMs: config.rateLimitMaxBackoffMs,
|
|
1957
|
+
maxUnjudgedPercent: config.maxUnjudgedPercent,
|
|
1928
1958
|
evaluator
|
|
1929
1959
|
};
|
|
1930
1960
|
const onEvent = opts.progress !== false ? handleEvent : void 0;
|
|
@@ -2549,6 +2579,16 @@ function incompleteScan(report, judged, total) {
|
|
|
2549
2579
|
reason: `The scan stopped after repeated failed requests to the target, ${judged}/${total} attacks judged \u2014 the target is failing or unreachable. ${resume}`,
|
|
2550
2580
|
exitCode: 3
|
|
2551
2581
|
};
|
|
2582
|
+
case "judge_unavailable": {
|
|
2583
|
+
const notJudged = report.judgeRecovery?.notJudged ?? 0;
|
|
2584
|
+
const max = report.judgeRecovery?.maxUnjudgedPercent;
|
|
2585
|
+
const answered = judged + notJudged;
|
|
2586
|
+
const share = answered > 0 ? Math.round(notJudged / answered * 100) : 0;
|
|
2587
|
+
return {
|
|
2588
|
+
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.`,
|
|
2589
|
+
exitCode: 3
|
|
2590
|
+
};
|
|
2591
|
+
}
|
|
2552
2592
|
default:
|
|
2553
2593
|
return null;
|
|
2554
2594
|
}
|
|
@@ -2579,9 +2619,28 @@ function buildUploadVulnerabilities(attacks) {
|
|
|
2579
2619
|
judgeId: a.llmEvaluation?.judgeId,
|
|
2580
2620
|
confidence: a.llmEvaluation?.confidence,
|
|
2581
2621
|
reasoning: a.llmEvaluation?.reasoning,
|
|
2582
|
-
captureStatus: a.captureStatus ?? "captured"
|
|
2622
|
+
captureStatus: a.captureStatus ?? "captured",
|
|
2623
|
+
// Problems outside this attack's target, as the server's judge bounded
|
|
2624
|
+
// them. Absent when there are none (and from an older server).
|
|
2625
|
+
...a.llmEvaluation?.incidental?.length && {
|
|
2626
|
+
incidentalFindings: a.llmEvaluation.incidental
|
|
2627
|
+
}
|
|
2583
2628
|
}));
|
|
2584
2629
|
}
|
|
2630
|
+
function judgeOutageRejection(status, body) {
|
|
2631
|
+
if (status !== 422) return null;
|
|
2632
|
+
try {
|
|
2633
|
+
const parsed = JSON.parse(body);
|
|
2634
|
+
return parsed.code === "judge_unavailable" && typeof parsed.error === "string" ? printableServerText(parsed.error) : null;
|
|
2635
|
+
} catch {
|
|
2636
|
+
return null;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
function printableServerText(text) {
|
|
2640
|
+
return text.replace(/[\r\n\t]+/g, " ").replace(/[\u0000-\u001f\u007f-\u009f]/g, "").slice(0, 300);
|
|
2641
|
+
}
|
|
2642
|
+
var JudgeOutageRejection = class extends Error {
|
|
2643
|
+
};
|
|
2585
2644
|
async function uploadReportToBackend(report, credentials, scanId, attackPackVersion) {
|
|
2586
2645
|
const vulnerabilities = buildUploadVulnerabilities(report.attacks);
|
|
2587
2646
|
const testsRun = scoredAttacks(report.attacks).length;
|
|
@@ -2611,6 +2670,8 @@ async function uploadReportToBackend(report, credentials, scanId, attackPackVers
|
|
|
2611
2670
|
});
|
|
2612
2671
|
if (!res.ok) {
|
|
2613
2672
|
const body = await res.text().catch(() => "");
|
|
2673
|
+
const outage = judgeOutageRejection(res.status, body);
|
|
2674
|
+
if (outage) throw new JudgeOutageRejection(outage);
|
|
2614
2675
|
throw new Error(`HTTP ${res.status}: ${body.slice(0, 200)}`);
|
|
2615
2676
|
}
|
|
2616
2677
|
const data = await res.json().catch(() => ({}));
|
|
@@ -2717,6 +2778,8 @@ function buildCliOverrides(opts) {
|
|
|
2717
2778
|
cliOverrides.maxRateLimitRetries = opts.retries;
|
|
2718
2779
|
if (opts.maxFloorThrottles !== void 0)
|
|
2719
2780
|
cliOverrides.maxFloorThrottles = opts.maxFloorThrottles;
|
|
2781
|
+
if (opts.maxUnjudged !== void 0)
|
|
2782
|
+
cliOverrides.maxUnjudgedPercent = opts.maxUnjudged;
|
|
2720
2783
|
return cliOverrides;
|
|
2721
2784
|
}
|
|
2722
2785
|
async function scanCommand(opts) {
|
|
@@ -2902,6 +2965,7 @@ async function scanCommand(opts) {
|
|
|
2902
2965
|
rateLimitMaxBackoffMs: config.rateLimitMaxBackoffMs,
|
|
2903
2966
|
maxDelayMs: config.maxDelayMs,
|
|
2904
2967
|
maxFloorThrottles: config.maxFloorThrottles,
|
|
2968
|
+
maxUnjudgedPercent: config.maxUnjudgedPercent,
|
|
2905
2969
|
checkpoint: checkpointStore,
|
|
2906
2970
|
evaluator
|
|
2907
2971
|
};
|
|
@@ -2962,6 +3026,12 @@ async function scanCommand(opts) {
|
|
|
2962
3026
|
);
|
|
2963
3027
|
}
|
|
2964
3028
|
} catch (err) {
|
|
3029
|
+
if (err instanceof JudgeOutageRejection) {
|
|
3030
|
+
scanFinalized = true;
|
|
3031
|
+
console.error(`Scan stopped: ${err.message}`);
|
|
3032
|
+
setExitCode(3);
|
|
3033
|
+
return;
|
|
3034
|
+
}
|
|
2965
3035
|
const msg = err instanceof Error ? err.message : String(err);
|
|
2966
3036
|
console.warn(`Warning: Could not save scan to dashboard: ${msg}`);
|
|
2967
3037
|
console.warn(
|
|
@@ -4573,7 +4643,7 @@ function passDetail(baseline, cases, report, judged, afterRun) {
|
|
|
4573
4643
|
const splitNote = split ? `, ${split} split vote(s) read against the patch` : "";
|
|
4574
4644
|
return `${cases.length} cases judged, ${report.flips.length} flip(s)${excluded}${splitNote}`;
|
|
4575
4645
|
}
|
|
4576
|
-
async function replayFamily(contract, target, catalogue, evaluator) {
|
|
4646
|
+
async function replayFamily(contract, target, catalogue, evaluator, judgeRetryDelayMs) {
|
|
4577
4647
|
const attacks = attacksForContract(contract, catalogue);
|
|
4578
4648
|
const report = await new Scanner({
|
|
4579
4649
|
target,
|
|
@@ -4584,7 +4654,9 @@ async function replayFamily(contract, target, catalogue, evaluator) {
|
|
|
4584
4654
|
attacks,
|
|
4585
4655
|
evaluator,
|
|
4586
4656
|
concurrency: 1,
|
|
4587
|
-
delayMs: 0
|
|
4657
|
+
delayMs: 0,
|
|
4658
|
+
// Undefined keeps the scanner's default pause before its re-judge pass.
|
|
4659
|
+
judgeRetryDelayMs
|
|
4588
4660
|
}).run();
|
|
4589
4661
|
const verdicts = /* @__PURE__ */ new Map();
|
|
4590
4662
|
for (const a of report.attacks) {
|
|
@@ -4599,7 +4671,8 @@ async function verifyLive(input2) {
|
|
|
4599
4671
|
contract,
|
|
4600
4672
|
input2.target,
|
|
4601
4673
|
input2.catalogue,
|
|
4602
|
-
input2.evaluator
|
|
4674
|
+
input2.evaluator,
|
|
4675
|
+
input2.judgeRetryDelayMs
|
|
4603
4676
|
);
|
|
4604
4677
|
const cleared = (id) => verdicts.get(id) === false;
|
|
4605
4678
|
const executed = (id) => verdicts.has(id);
|
|
@@ -5888,6 +5961,13 @@ function parseIntArg(value) {
|
|
|
5888
5961
|
}
|
|
5889
5962
|
return n;
|
|
5890
5963
|
}
|
|
5964
|
+
function parsePercentArg(value) {
|
|
5965
|
+
const n = parseMaxUnjudgedPercent(value);
|
|
5966
|
+
if (n === null) {
|
|
5967
|
+
throw new InvalidArgumentError("Expected a percentage from 0 to 100.");
|
|
5968
|
+
}
|
|
5969
|
+
return n;
|
|
5970
|
+
}
|
|
5891
5971
|
function parseFloatArg(value) {
|
|
5892
5972
|
const n = Number.parseFloat(value);
|
|
5893
5973
|
if (Number.isNaN(n)) {
|
|
@@ -5958,6 +6038,10 @@ program.command("scan").description("Run a security scan against a target chatbo
|
|
|
5958
6038
|
"--max-floor-throttles <n>",
|
|
5959
6039
|
"Consecutive throttles at the pacing floor before hard-stopping (default 3)",
|
|
5960
6040
|
parseIntArg
|
|
6041
|
+
).option(
|
|
6042
|
+
"--max-unjudged <percent>",
|
|
6043
|
+
"Share of answered attacks the judge may fail to rule on before the scan is incomplete (default 10)",
|
|
6044
|
+
parsePercentArg
|
|
5961
6045
|
).option("--min-score <n>", "Minimum score threshold", parseFloat).option("--fail-on-critical", "Fail if any CRITICAL vulnerability found").option(
|
|
5962
6046
|
"--no-fail-on-critical",
|
|
5963
6047
|
"Report CRITICAL findings without failing the run"
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shield-llm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"commander": "^12.0.0",
|
|
54
|
-
"zod": "^
|
|
54
|
+
"zod": "^4.6.7"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@shield-llm/scanner-core": "workspace:*",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@types/express": "^5.0.6",
|
|
60
60
|
"@types/node": "^20.19.30",
|
|
61
61
|
"express": "^5.2.1",
|
|
62
|
-
"puppeteer": "^25.
|
|
62
|
+
"puppeteer": "^25.14.0",
|
|
63
63
|
"tsup": "^8.0.0",
|
|
64
64
|
"tsx": "^4.0.0",
|
|
65
65
|
"typescript": "^5.0.0",
|