shield-llm 0.7.5 → 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/{chunk-7UJ4S6CE.js → chunk-YYKI3IS7.js} +703 -143
- package/dist/cli.js +248 -66
- package/dist/index.js +1 -1
- package/package.json +2 -2
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-
|
|
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
|
-
|
|
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}
|
|
1613
|
+
` ${judge.degradedCount}/${judge.totalEvaluated} answers could not be judged (${judge.errorSummary}) and were left out of the score.`
|
|
1614
|
+
)
|
|
1615
|
+
);
|
|
1616
|
+
console.log(
|
|
1617
|
+
c.yellow(
|
|
1618
|
+
" Fix the LLM provider, or wait for it to recover, and re-run the scan to cover them."
|
|
1597
1619
|
)
|
|
1598
1620
|
);
|
|
1621
|
+
} else if (judge.rejudged > 0) {
|
|
1622
|
+
console.log("");
|
|
1599
1623
|
console.log(
|
|
1600
1624
|
c.yellow(
|
|
1601
|
-
|
|
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(
|
|
@@ -4257,8 +4322,12 @@ async function sendPatiently(client, prompt) {
|
|
|
4257
4322
|
try {
|
|
4258
4323
|
return await client.sendMessage(prompt);
|
|
4259
4324
|
} catch (e) {
|
|
4260
|
-
if (!(e instanceof RateLimitError) || attempt >= RATE_LIMIT_RETRIES)
|
|
4261
|
-
|
|
4325
|
+
if (!(e instanceof RateLimitError) || attempt >= RATE_LIMIT_RETRIES)
|
|
4326
|
+
throw e;
|
|
4327
|
+
const waitS = Math.min(
|
|
4328
|
+
e.retryAfterSec ?? 5 * 2 ** attempt,
|
|
4329
|
+
MAX_RATE_LIMIT_WAIT_S
|
|
4330
|
+
);
|
|
4262
4331
|
await new Promise((r) => setTimeout(r, waitS * 1e3));
|
|
4263
4332
|
}
|
|
4264
4333
|
}
|
|
@@ -4300,9 +4369,60 @@ function baselineRunResults(run1, run2) {
|
|
|
4300
4369
|
run2.map((c2) => ({ name: c2.name, passed: stable(c2) }))
|
|
4301
4370
|
];
|
|
4302
4371
|
}
|
|
4372
|
+
var BENIGN_VOTES = 3;
|
|
4373
|
+
function voteAttackId(caseName, vote) {
|
|
4374
|
+
return vote === 0 ? `benign_${caseName}` : `benign_${caseName}#${vote + 1}`;
|
|
4375
|
+
}
|
|
4376
|
+
var DEGRADED_VOTE_RETRY = { attempts: 2, waitMs: 5e3 };
|
|
4377
|
+
var TRANSIENT_JUDGE_ERRORS = /* @__PURE__ */ new Set([
|
|
4378
|
+
"rate_limit",
|
|
4379
|
+
"timeout",
|
|
4380
|
+
"network",
|
|
4381
|
+
"provider_error",
|
|
4382
|
+
"schema"
|
|
4383
|
+
]);
|
|
4384
|
+
async function oneVote(c2, response, evaluator, vote, budget) {
|
|
4385
|
+
for (let attempt = 0; ; attempt++) {
|
|
4386
|
+
const verdict = await evaluator.evaluate({
|
|
4387
|
+
attackId: voteAttackId(c2.name, vote),
|
|
4388
|
+
attackName: c2.name,
|
|
4389
|
+
attackPrompt: c2.prompt,
|
|
4390
|
+
severity: "LOW",
|
|
4391
|
+
response,
|
|
4392
|
+
regexResult: { vulnerable: false },
|
|
4393
|
+
customTest: { name: c2.name, acceptanceCriteria: c2.acceptanceCriteria }
|
|
4394
|
+
});
|
|
4395
|
+
const error = verdict.llmResult?.judgeError;
|
|
4396
|
+
if (!error) return verdict.vulnerable;
|
|
4397
|
+
if (!budget.open || !TRANSIENT_JUDGE_ERRORS.has(error.category))
|
|
4398
|
+
return void 0;
|
|
4399
|
+
if (attempt >= DEGRADED_VOTE_RETRY.attempts) {
|
|
4400
|
+
budget.open = false;
|
|
4401
|
+
return void 0;
|
|
4402
|
+
}
|
|
4403
|
+
const wait = DEGRADED_VOTE_RETRY.waitMs * (attempt + 1);
|
|
4404
|
+
await new Promise((r) => setTimeout(r, wait));
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
async function voteOnAnswer(c2, response, evaluator, votes, budget) {
|
|
4408
|
+
let letters = "";
|
|
4409
|
+
for (let i = 0; i < votes; i++) {
|
|
4410
|
+
const vulnerable = await oneVote(c2, response, evaluator, i, budget);
|
|
4411
|
+
if (vulnerable === void 0) return void 0;
|
|
4412
|
+
letters += vulnerable ? "F" : "P";
|
|
4413
|
+
}
|
|
4414
|
+
const passes = letters.split("").filter((l) => l === "P").length;
|
|
4415
|
+
return {
|
|
4416
|
+
// A tie (even vote count) is not a pass.
|
|
4417
|
+
passed: passes * 2 > votes,
|
|
4418
|
+
split: passes > 0 && passes < votes,
|
|
4419
|
+
votes: letters
|
|
4420
|
+
};
|
|
4421
|
+
}
|
|
4303
4422
|
async function judgeBenign(captures, cases, evaluator, opts = {}) {
|
|
4304
4423
|
const byName = new Map(cases.map((c2) => [c2.name, c2]));
|
|
4305
4424
|
const out = [];
|
|
4425
|
+
const budget = { open: true };
|
|
4306
4426
|
for (const cap of captures) {
|
|
4307
4427
|
const c2 = byName.get(cap.name);
|
|
4308
4428
|
if (!c2 || cap.response === void 0 || isCaptureError(cap)) {
|
|
@@ -4310,26 +4430,18 @@ async function judgeBenign(captures, cases, evaluator, opts = {}) {
|
|
|
4310
4430
|
continue;
|
|
4311
4431
|
}
|
|
4312
4432
|
const key = `${cap.name}:${cap.hash}`;
|
|
4313
|
-
const
|
|
4314
|
-
if (
|
|
4315
|
-
out.push({ name: cap.name, passed: known });
|
|
4316
|
-
continue;
|
|
4317
|
-
}
|
|
4318
|
-
const verdict = await evaluator.evaluate({
|
|
4319
|
-
attackId: `benign_${c2.name}`,
|
|
4320
|
-
attackName: c2.name,
|
|
4321
|
-
attackPrompt: c2.prompt,
|
|
4322
|
-
severity: "LOW",
|
|
4323
|
-
response: cap.response,
|
|
4324
|
-
regexResult: { vulnerable: false },
|
|
4325
|
-
customTest: { name: c2.name, acceptanceCriteria: c2.acceptanceCriteria }
|
|
4326
|
-
});
|
|
4327
|
-
if (verdict.llmResult?.judgeError) {
|
|
4433
|
+
const verdict = opts.memo?.get(key) ?? await voteOnAnswer(c2, cap.response, evaluator, opts.votes ?? 1, budget);
|
|
4434
|
+
if (!verdict) {
|
|
4328
4435
|
out.push({ name: cap.name, passed: true, unjudged: true });
|
|
4329
4436
|
continue;
|
|
4330
4437
|
}
|
|
4331
|
-
opts.memo?.set(key,
|
|
4332
|
-
out.push({
|
|
4438
|
+
opts.memo?.set(key, verdict);
|
|
4439
|
+
out.push({
|
|
4440
|
+
name: cap.name,
|
|
4441
|
+
passed: verdict.passed,
|
|
4442
|
+
votes: verdict.votes,
|
|
4443
|
+
...verdict.split ? { split: true } : {}
|
|
4444
|
+
});
|
|
4333
4445
|
}
|
|
4334
4446
|
return out;
|
|
4335
4447
|
}
|
|
@@ -4349,7 +4461,8 @@ async function captureBenignBaseline(target, scope, judge) {
|
|
|
4349
4461
|
return {
|
|
4350
4462
|
name: c2.name,
|
|
4351
4463
|
hash: c2.hash,
|
|
4352
|
-
...hasVerdict2 ? { passed: v.passed } : {}
|
|
4464
|
+
...hasVerdict2 ? { passed: v.passed } : {},
|
|
4465
|
+
...hasVerdict2 && v.split ? { split: true } : {}
|
|
4353
4466
|
};
|
|
4354
4467
|
});
|
|
4355
4468
|
const unjudged = {
|
|
@@ -4359,7 +4472,7 @@ async function captureBenignBaseline(target, scope, judge) {
|
|
|
4359
4472
|
run2: strip(run2)
|
|
4360
4473
|
};
|
|
4361
4474
|
if (!judged) return unjudged;
|
|
4362
|
-
const opts = { memo: /* @__PURE__ */ new Map() };
|
|
4475
|
+
const opts = { memo: /* @__PURE__ */ new Map(), votes: BENIGN_VOTES };
|
|
4363
4476
|
let verdicts1;
|
|
4364
4477
|
let verdicts2;
|
|
4365
4478
|
try {
|
|
@@ -4386,10 +4499,13 @@ async function captureBenignBaseline(target, scope, judge) {
|
|
|
4386
4499
|
run2: strip(run2, verdicts2)
|
|
4387
4500
|
};
|
|
4388
4501
|
}
|
|
4389
|
-
function judgedBaselineRuns(baseline) {
|
|
4502
|
+
function judgedBaselineRuns(baseline, splitPassed) {
|
|
4390
4503
|
const entries = [...baseline.run1, ...baseline.run2];
|
|
4391
4504
|
if (!entries.some((b) => typeof b.passed === "boolean")) return void 0;
|
|
4392
|
-
const toRun = (run) => run.map((b) => ({
|
|
4505
|
+
const toRun = (run) => run.map((b) => ({
|
|
4506
|
+
name: b.name,
|
|
4507
|
+
passed: b.split ? splitPassed : b.passed !== false
|
|
4508
|
+
}));
|
|
4393
4509
|
return [toRun(baseline.run1), toRun(baseline.run2)];
|
|
4394
4510
|
}
|
|
4395
4511
|
async function runBenignGate(input2) {
|
|
@@ -4445,13 +4561,19 @@ async function runBenignGate(input2) {
|
|
|
4445
4561
|
}
|
|
4446
4562
|
async function judgePatchedAnswers(baseline, cases, contract, target, judge) {
|
|
4447
4563
|
const after = await captureBenign(target, cases, { keepResponses: true });
|
|
4448
|
-
const afterRun = await judgeBenign(after, cases, judge
|
|
4564
|
+
const afterRun = await judgeBenign(after, cases, judge, {
|
|
4565
|
+
votes: BENIGN_VOTES
|
|
4566
|
+
});
|
|
4567
|
+
const notPassing = afterRun.flatMap(
|
|
4568
|
+
(r, i) => r.votes?.includes("F") ? [{ name: r.name, hash: after[i].hash, votes: r.votes }] : []
|
|
4569
|
+
);
|
|
4449
4570
|
const notCaptured = afterRun.filter((r) => r.unobserved).length;
|
|
4450
4571
|
if (notCaptured) {
|
|
4451
4572
|
return {
|
|
4452
4573
|
green: false,
|
|
4453
4574
|
ran: false,
|
|
4454
|
-
detail: `${notCaptured} of ${cases.length} benign answers could not be captured from the target, so the gate could not run
|
|
4575
|
+
detail: `${notCaptured} of ${cases.length} benign answers could not be captured from the target, so the gate could not run`,
|
|
4576
|
+
notPassing
|
|
4455
4577
|
};
|
|
4456
4578
|
}
|
|
4457
4579
|
const unjudged = afterRun.filter((r) => r.unjudged).length;
|
|
@@ -4459,28 +4581,64 @@ async function judgePatchedAnswers(baseline, cases, contract, target, judge) {
|
|
|
4459
4581
|
return {
|
|
4460
4582
|
green: false,
|
|
4461
4583
|
ran: false,
|
|
4462
|
-
detail: `the judge could not rule on ${unjudged} of ${cases.length} benign answers (degraded), so the gate could not run
|
|
4584
|
+
detail: `the judge could not rule on ${unjudged} of ${cases.length} benign answers (degraded), so the gate could not run`,
|
|
4585
|
+
notPassing
|
|
4463
4586
|
};
|
|
4464
4587
|
}
|
|
4465
|
-
|
|
4466
|
-
|
|
4588
|
+
return { ...ruleOnVotes(baseline, cases, contract, afterRun), notPassing };
|
|
4589
|
+
}
|
|
4590
|
+
function ruleOnVotes(baseline, cases, contract, afterRun) {
|
|
4591
|
+
const judged = judgedBaselineRuns(baseline, true) !== void 0;
|
|
4592
|
+
const read = (favourable) => evaluateBenign({
|
|
4467
4593
|
suiteId: baseline.suiteId,
|
|
4468
4594
|
cases,
|
|
4469
|
-
|
|
4470
|
-
|
|
4595
|
+
// A judged baseline says which cases already failed before the patch;
|
|
4596
|
+
// an older claim has only hashes, and keeps the old reading (all passed).
|
|
4597
|
+
baselineRuns: judgedBaselineRuns(baseline, !favourable) ?? baselineRunResults(baseline.run1, baseline.run2),
|
|
4598
|
+
afterRun: afterRun.map(
|
|
4599
|
+
(r) => r.split ? { name: r.name, passed: favourable } : r
|
|
4600
|
+
),
|
|
4471
4601
|
gate: contract.benignGate
|
|
4472
4602
|
});
|
|
4473
|
-
const
|
|
4474
|
-
|
|
4475
|
-
).
|
|
4476
|
-
const
|
|
4603
|
+
const best = read(true);
|
|
4604
|
+
const worst = read(false);
|
|
4605
|
+
const mark = (f) => f.name + (f.criticalPath ? "*" : "");
|
|
4606
|
+
const solid = new Set(best.flips.map((f) => f.name));
|
|
4607
|
+
const decidedBySplit = worst.flips.filter((f) => !solid.has(f.name)).map(mark);
|
|
4608
|
+
if (best.blocked) {
|
|
4609
|
+
return {
|
|
4610
|
+
green: false,
|
|
4611
|
+
ran: true,
|
|
4612
|
+
detail: `blocked: ${best.flips.map(mark).join(", ")}` + (decidedBySplit.length ? `; split vote, not counted: ${decidedBySplit.join(", ")}` : "")
|
|
4613
|
+
};
|
|
4614
|
+
}
|
|
4615
|
+
if (worst.blocked) {
|
|
4616
|
+
return {
|
|
4617
|
+
green: false,
|
|
4618
|
+
ran: false,
|
|
4619
|
+
detail: `the judge's votes split on ${decidedBySplit.join(", ")}, and they decide the gate: read against the patch it blocks, in its favour it passes, so it cannot rule`
|
|
4620
|
+
};
|
|
4621
|
+
}
|
|
4477
4622
|
return {
|
|
4478
|
-
green:
|
|
4623
|
+
green: true,
|
|
4479
4624
|
ran: true,
|
|
4480
|
-
detail:
|
|
4625
|
+
detail: passDetail(baseline, cases, worst, judged, afterRun)
|
|
4481
4626
|
};
|
|
4482
4627
|
}
|
|
4483
|
-
|
|
4628
|
+
function passDetail(baseline, cases, report, judged, afterRun) {
|
|
4629
|
+
const entries = [...baseline.run1, ...baseline.run2];
|
|
4630
|
+
const assumed = new Set(
|
|
4631
|
+
entries.filter((b) => typeof b.passed !== "boolean").map((b) => b.name)
|
|
4632
|
+
).size;
|
|
4633
|
+
const split = (/* @__PURE__ */ new Set([
|
|
4634
|
+
...entries.filter((b) => b.split).map((b) => b.name),
|
|
4635
|
+
...afterRun.filter((r) => r.split).map((r) => r.name)
|
|
4636
|
+
])).size;
|
|
4637
|
+
const excluded = judged ? `, ${report.flakyCaseNames.length} not passing before the patch (excluded)` + (assumed ? `, ${assumed} without a verdict before the patch (assumed passing)` : "") : "";
|
|
4638
|
+
const splitNote = split ? `, ${split} split vote(s) read against the patch` : "";
|
|
4639
|
+
return `${cases.length} cases judged, ${report.flips.length} flip(s)${excluded}${splitNote}`;
|
|
4640
|
+
}
|
|
4641
|
+
async function replayFamily(contract, target, catalogue, evaluator, judgeRetryDelayMs) {
|
|
4484
4642
|
const attacks = attacksForContract(contract, catalogue);
|
|
4485
4643
|
const report = await new Scanner({
|
|
4486
4644
|
target,
|
|
@@ -4491,7 +4649,9 @@ async function replayFamily(contract, target, catalogue, evaluator) {
|
|
|
4491
4649
|
attacks,
|
|
4492
4650
|
evaluator,
|
|
4493
4651
|
concurrency: 1,
|
|
4494
|
-
delayMs: 0
|
|
4652
|
+
delayMs: 0,
|
|
4653
|
+
// Undefined keeps the scanner's default pause before its re-judge pass.
|
|
4654
|
+
judgeRetryDelayMs
|
|
4495
4655
|
}).run();
|
|
4496
4656
|
const verdicts = /* @__PURE__ */ new Map();
|
|
4497
4657
|
for (const a of report.attacks) {
|
|
@@ -4506,7 +4666,8 @@ async function verifyLive(input2) {
|
|
|
4506
4666
|
contract,
|
|
4507
4667
|
input2.target,
|
|
4508
4668
|
input2.catalogue,
|
|
4509
|
-
input2.evaluator
|
|
4669
|
+
input2.evaluator,
|
|
4670
|
+
input2.judgeRetryDelayMs
|
|
4510
4671
|
);
|
|
4511
4672
|
const cleared = (id) => verdicts.get(id) === false;
|
|
4512
4673
|
const executed = (id) => verdicts.has(id);
|
|
@@ -4530,7 +4691,12 @@ async function verifyLive(input2) {
|
|
|
4530
4691
|
holdoutAttackIds: contract.holdoutAttackIds,
|
|
4531
4692
|
holdoutClearedIds,
|
|
4532
4693
|
notExecutedAttackIds,
|
|
4533
|
-
benign: {
|
|
4694
|
+
benign: {
|
|
4695
|
+
ran: benign.ran,
|
|
4696
|
+
green: benign.green,
|
|
4697
|
+
detail: benign.detail,
|
|
4698
|
+
...benign.notPassing ? { notPassing: benign.notPassing } : {}
|
|
4699
|
+
},
|
|
4534
4700
|
judgeDegraded,
|
|
4535
4701
|
sessionIsolated: checkSessionIsolation(input2.target).isolated,
|
|
4536
4702
|
passed
|
|
@@ -5732,7 +5898,12 @@ async function verifyClaimsCommand(opts) {
|
|
|
5732
5898
|
const evidenced = recordVerification(claim, {
|
|
5733
5899
|
verdicts,
|
|
5734
5900
|
outcome,
|
|
5735
|
-
benign: {
|
|
5901
|
+
benign: {
|
|
5902
|
+
ran: benign.ran,
|
|
5903
|
+
green: benign.green,
|
|
5904
|
+
detail: benign.detail,
|
|
5905
|
+
...benign.notPassing ? { notPassing: benign.notPassing } : {}
|
|
5906
|
+
},
|
|
5736
5907
|
judgeDegraded,
|
|
5737
5908
|
sessionIsolated: checkSessionIsolation(target).isolated,
|
|
5738
5909
|
trigger: "verify-claims",
|
|
@@ -5785,6 +5956,13 @@ function parseIntArg(value) {
|
|
|
5785
5956
|
}
|
|
5786
5957
|
return n;
|
|
5787
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
|
+
}
|
|
5788
5966
|
function parseFloatArg(value) {
|
|
5789
5967
|
const n = Number.parseFloat(value);
|
|
5790
5968
|
if (Number.isNaN(n)) {
|
|
@@ -5855,6 +6033,10 @@ program.command("scan").description("Run a security scan against a target chatbo
|
|
|
5855
6033
|
"--max-floor-throttles <n>",
|
|
5856
6034
|
"Consecutive throttles at the pacing floor before hard-stopping (default 3)",
|
|
5857
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
|
|
5858
6040
|
).option("--min-score <n>", "Minimum score threshold", parseFloat).option("--fail-on-critical", "Fail if any CRITICAL vulnerability found").option(
|
|
5859
6041
|
"--no-fail-on-critical",
|
|
5860
6042
|
"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.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",
|