shield-llm 0.5.1 → 0.5.2
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-IB7T5OJ2.js → chunk-CWJWN44I.js} +53 -43
- package/dist/cli.js +230 -57
- package/dist/index.js +1 -1
- package/package.json +1 -13
|
@@ -5106,8 +5106,8 @@ function isIpPrivate(ip) {
|
|
|
5106
5106
|
const mapped = addr.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
|
|
5107
5107
|
if (mapped) addr = mapped[1];
|
|
5108
5108
|
if (isIP(addr) === 4) {
|
|
5109
|
-
const [a, b,
|
|
5110
|
-
if ([a, b,
|
|
5109
|
+
const [a, b, c2, d] = addr.split(".").map(Number);
|
|
5110
|
+
if ([a, b, c2, d].some((p) => Number.isNaN(p) || p < 0 || p > 255)) {
|
|
5111
5111
|
return true;
|
|
5112
5112
|
}
|
|
5113
5113
|
if (a === 0) return true;
|
|
@@ -5117,7 +5117,7 @@ function isIpPrivate(ip) {
|
|
|
5117
5117
|
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
5118
5118
|
if (a === 192 && b === 168) return true;
|
|
5119
5119
|
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
5120
|
-
if (a === 255 && b === 255 &&
|
|
5120
|
+
if (a === 255 && b === 255 && c2 === 255 && d === 255) return true;
|
|
5121
5121
|
return false;
|
|
5122
5122
|
}
|
|
5123
5123
|
const lower = addr.toLowerCase();
|
|
@@ -6669,39 +6669,50 @@ function evaluateThresholds(report, thresholds) {
|
|
|
6669
6669
|
};
|
|
6670
6670
|
}
|
|
6671
6671
|
|
|
6672
|
+
// src/display/colors.ts
|
|
6673
|
+
import { styleText } from "util";
|
|
6674
|
+
var make = (fmt) => (text) => styleText(fmt, text);
|
|
6675
|
+
var c = {
|
|
6676
|
+
cyan: make("cyan"),
|
|
6677
|
+
red: make("red"),
|
|
6678
|
+
green: make("green"),
|
|
6679
|
+
yellow: make("yellow"),
|
|
6680
|
+
blue: make("blue"),
|
|
6681
|
+
gray: make("gray"),
|
|
6682
|
+
white: make("white"),
|
|
6683
|
+
bold: make("bold"),
|
|
6684
|
+
dim: make("dim"),
|
|
6685
|
+
redBold: make(["red", "bold"]),
|
|
6686
|
+
greenBold: make(["green", "bold"]),
|
|
6687
|
+
bgYellowBlackBold: make(["bgYellow", "black", "bold"])
|
|
6688
|
+
};
|
|
6689
|
+
|
|
6672
6690
|
// src/reporters/compliance.ts
|
|
6673
|
-
import chalk from "chalk";
|
|
6674
6691
|
function formatComplianceTerminal(result, target) {
|
|
6675
6692
|
const lines = [];
|
|
6676
6693
|
lines.push("");
|
|
6677
|
-
lines.push(
|
|
6694
|
+
lines.push(c.bold("\u2550\u2550\u2550 EU AI Act Compliance \u2550\u2550\u2550"));
|
|
6678
6695
|
lines.push("");
|
|
6679
|
-
lines.push(` Target: ${
|
|
6696
|
+
lines.push(` Target: ${c.white(target)}`);
|
|
6680
6697
|
lines.push(` Score: ${complianceScoreColor(result.overallScore)}`);
|
|
6681
6698
|
lines.push(
|
|
6682
6699
|
` Status: ${statusColor(result.status, getComplianceLabel(result.status))}`
|
|
6683
6700
|
);
|
|
6684
6701
|
lines.push(` Framework: ${result.framework} (${result.frameworkVersion})`);
|
|
6685
6702
|
lines.push("");
|
|
6686
|
-
lines.push(
|
|
6703
|
+
lines.push(c.bold(" Article Coverage:"));
|
|
6687
6704
|
const sorted = [...result.aspects].filter((a) => a.totalTests > 0).sort((a, b) => a.score - b.score);
|
|
6688
6705
|
for (const aspect of sorted) {
|
|
6689
6706
|
const label = ASPECT_ARTICLE_LABELS[aspect.aspect];
|
|
6690
6707
|
const bar = makeBar(aspect.score, 20);
|
|
6691
6708
|
const scoreStr = complianceScoreColor(aspect.score);
|
|
6692
|
-
const stats =
|
|
6693
|
-
|
|
6694
|
-
);
|
|
6695
|
-
lines.push(
|
|
6696
|
-
` ${label.padEnd(16)} ${bar} ${scoreStr} ${stats}`
|
|
6697
|
-
);
|
|
6709
|
+
const stats = c.dim(`${aspect.passedTests}/${aspect.totalTests} passed`);
|
|
6710
|
+
lines.push(` ${label.padEnd(16)} ${bar} ${scoreStr} ${stats}`);
|
|
6698
6711
|
}
|
|
6699
6712
|
if (result.nonCompliances.length > 0) {
|
|
6700
6713
|
lines.push("");
|
|
6701
6714
|
lines.push(
|
|
6702
|
-
|
|
6703
|
-
` Non-Compliances (${result.nonCompliances.length}):`
|
|
6704
|
-
)
|
|
6715
|
+
c.redBold(` Non-Compliances (${result.nonCompliances.length}):`)
|
|
6705
6716
|
);
|
|
6706
6717
|
const seen = /* @__PURE__ */ new Set();
|
|
6707
6718
|
for (const nc of result.nonCompliances) {
|
|
@@ -6709,7 +6720,7 @@ function formatComplianceTerminal(result, target) {
|
|
|
6709
6720
|
if (seen.has(key)) continue;
|
|
6710
6721
|
seen.add(key);
|
|
6711
6722
|
lines.push(
|
|
6712
|
-
` ${
|
|
6723
|
+
` ${c.red("\u2717")} ${nc.testName} \u2014 ${nc.article.articleNumber} (${nc.article.complianceAspect})`
|
|
6713
6724
|
);
|
|
6714
6725
|
}
|
|
6715
6726
|
}
|
|
@@ -6719,19 +6730,17 @@ function formatComplianceTerminal(result, target) {
|
|
|
6719
6730
|
if (compliantAspects.length > 0) {
|
|
6720
6731
|
lines.push("");
|
|
6721
6732
|
lines.push(
|
|
6722
|
-
|
|
6723
|
-
` Compliant (${compliantAspects.length}/7 aspects):`
|
|
6724
|
-
)
|
|
6733
|
+
c.greenBold(` Compliant (${compliantAspects.length}/7 aspects):`)
|
|
6725
6734
|
);
|
|
6726
6735
|
for (const a of compliantAspects) {
|
|
6727
6736
|
lines.push(
|
|
6728
|
-
` ${
|
|
6737
|
+
` ${c.green("\u2713")} ${ASPECT_ARTICLE_LABELS[a.aspect]} \u2014 ${a.aspect} (${a.score}%)`
|
|
6729
6738
|
);
|
|
6730
6739
|
}
|
|
6731
6740
|
}
|
|
6732
6741
|
lines.push("");
|
|
6733
|
-
lines.push(
|
|
6734
|
-
lines.push(
|
|
6742
|
+
lines.push(c.dim(" Disclaimer: This is an automated assessment, not a"));
|
|
6743
|
+
lines.push(c.dim(" legal compliance certification."));
|
|
6735
6744
|
lines.push("");
|
|
6736
6745
|
return lines.join("\n");
|
|
6737
6746
|
}
|
|
@@ -6769,27 +6778,27 @@ function makeBar(score, width) {
|
|
|
6769
6778
|
const filledChar = "\u2588";
|
|
6770
6779
|
const emptyChar = "\u2591";
|
|
6771
6780
|
const bar = filledChar.repeat(filled) + emptyChar.repeat(empty);
|
|
6772
|
-
if (score >= 90) return
|
|
6773
|
-
if (score >= 70) return
|
|
6774
|
-
if (score >= 40) return
|
|
6775
|
-
return
|
|
6781
|
+
if (score >= 90) return c.green(bar);
|
|
6782
|
+
if (score >= 70) return c.yellow(bar);
|
|
6783
|
+
if (score >= 40) return c.red(bar);
|
|
6784
|
+
return c.redBold(bar);
|
|
6776
6785
|
}
|
|
6777
6786
|
function complianceScoreColor(score) {
|
|
6778
|
-
if (score >= 90) return
|
|
6779
|
-
if (score >= 70) return
|
|
6780
|
-
if (score >= 40) return
|
|
6781
|
-
return
|
|
6787
|
+
if (score >= 90) return c.greenBold(`${score}%`);
|
|
6788
|
+
if (score >= 70) return c.yellow(`${score}%`);
|
|
6789
|
+
if (score >= 40) return c.red(`${score}%`);
|
|
6790
|
+
return c.redBold(`${score}%`);
|
|
6782
6791
|
}
|
|
6783
6792
|
function statusColor(status, label) {
|
|
6784
6793
|
switch (status) {
|
|
6785
6794
|
case "COMPLIANT":
|
|
6786
|
-
return
|
|
6795
|
+
return c.greenBold(label);
|
|
6787
6796
|
case "PARTIALLY_COMPLIANT":
|
|
6788
|
-
return
|
|
6797
|
+
return c.yellow(label);
|
|
6789
6798
|
case "NON_COMPLIANT":
|
|
6790
|
-
return
|
|
6799
|
+
return c.red(label);
|
|
6791
6800
|
case "CRITICAL":
|
|
6792
|
-
return
|
|
6801
|
+
return c.redBold(label);
|
|
6793
6802
|
default:
|
|
6794
6803
|
return label;
|
|
6795
6804
|
}
|
|
@@ -8810,22 +8819,22 @@ ${d.passedTests.map(passedTestRow).join("")} </tbody>
|
|
|
8810
8819
|
${pageFooter(d.generatedAt)}</div>
|
|
8811
8820
|
`;
|
|
8812
8821
|
}
|
|
8813
|
-
var coverageRow = (
|
|
8822
|
+
var coverageRow = (c2) => ` <tr>
|
|
8814
8823
|
<td>
|
|
8815
8824
|
<div class="owasp-category-cell">
|
|
8816
|
-
<span class="owasp-category-id">${esc(
|
|
8817
|
-
<span class="owasp-category-name">${esc(
|
|
8825
|
+
<span class="owasp-category-id">${esc(c2.id)}</span>
|
|
8826
|
+
<span class="owasp-category-name">${esc(c2.name)}</span>
|
|
8818
8827
|
</div>
|
|
8819
8828
|
</td>
|
|
8820
|
-
<td>${esc(
|
|
8821
|
-
<td>${esc(
|
|
8822
|
-
<td${
|
|
8829
|
+
<td>${esc(c2.tests)}</td>
|
|
8830
|
+
<td>${esc(c2.passed)}</td>
|
|
8831
|
+
<td${c2.failed > 0 ? ' style="color: var(--critical-text); font-weight: 600;"' : ""}>${esc(c2.failed)}</td>
|
|
8823
8832
|
<td>
|
|
8824
8833
|
<div class="score-mini-bar">
|
|
8825
8834
|
<div class="score-mini-bar-track">
|
|
8826
|
-
<div class="score-mini-bar-fill ${
|
|
8835
|
+
<div class="score-mini-bar-fill ${c2.percentage === 100 ? "full" : c2.percentage > 0 ? "partial" : "none"}" style="width: ${esc(c2.percentage)}%"></div>
|
|
8827
8836
|
</div>
|
|
8828
|
-
<span class="score-mini-text" style="color: ${
|
|
8837
|
+
<span class="score-mini-text" style="color: ${c2.percentage === 100 ? "var(--pass-text)" : "var(--high-text)"};">${esc(c2.percentage)}%</span>
|
|
8829
8838
|
</div>
|
|
8830
8839
|
</td>
|
|
8831
8840
|
</tr>
|
|
@@ -9125,6 +9134,7 @@ export {
|
|
|
9125
9134
|
buildAuthFromFlags,
|
|
9126
9135
|
loadSystemPrompt,
|
|
9127
9136
|
ConfigError,
|
|
9137
|
+
c,
|
|
9128
9138
|
analyzeJudgeHealth,
|
|
9129
9139
|
evaluateThresholds,
|
|
9130
9140
|
formatComplianceTerminal,
|
package/dist/cli.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
analyzeJudgeHealth,
|
|
9
9
|
buildAuthFromFlags,
|
|
10
10
|
buildTargetConfig,
|
|
11
|
+
c,
|
|
11
12
|
calculateComplianceScore,
|
|
12
13
|
computeCatalogHash,
|
|
13
14
|
computeScanKey,
|
|
@@ -26,15 +27,20 @@ import {
|
|
|
26
27
|
parseSnapshot,
|
|
27
28
|
resolveOfflinePosition,
|
|
28
29
|
summarizeAttackErrors
|
|
29
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-CWJWN44I.js";
|
|
30
31
|
import "./chunk-I7M3BZK7.js";
|
|
31
32
|
|
|
33
|
+
// src/load-env.ts
|
|
34
|
+
try {
|
|
35
|
+
process.loadEnvFile();
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
// src/cli.ts
|
|
33
|
-
import "dotenv/config";
|
|
34
40
|
import { Command, CommanderError } from "commander";
|
|
35
41
|
|
|
36
42
|
// package.json
|
|
37
|
-
var version = "0.5.
|
|
43
|
+
var version = "0.5.2";
|
|
38
44
|
|
|
39
45
|
// src/credentials.ts
|
|
40
46
|
import {
|
|
@@ -230,7 +236,77 @@ Attack catalogue \u2014 ${total} attack(s)${wanted ? ` (severity: ${wanted})` :
|
|
|
230
236
|
|
|
231
237
|
// src/commands/benchmark.ts
|
|
232
238
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
233
|
-
|
|
239
|
+
|
|
240
|
+
// src/lib/prompts.ts
|
|
241
|
+
import * as readline from "readline/promises";
|
|
242
|
+
import { stdin, stdout } from "process";
|
|
243
|
+
async function withReadline(fn) {
|
|
244
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
245
|
+
rl.on("SIGINT", () => {
|
|
246
|
+
rl.close();
|
|
247
|
+
process.exit(130);
|
|
248
|
+
});
|
|
249
|
+
try {
|
|
250
|
+
return await fn(rl);
|
|
251
|
+
} finally {
|
|
252
|
+
rl.close();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async function input(opts) {
|
|
256
|
+
return withReadline(async (rl) => {
|
|
257
|
+
const suffix = opts.default !== void 0 ? ` (${opts.default})` : "";
|
|
258
|
+
for (; ; ) {
|
|
259
|
+
const answer = (await rl.question(`${opts.message}${suffix} `)).trim();
|
|
260
|
+
const value = answer === "" && opts.default !== void 0 ? opts.default : answer;
|
|
261
|
+
if (opts.validate) {
|
|
262
|
+
const result = await opts.validate(value);
|
|
263
|
+
if (result !== true) {
|
|
264
|
+
process.stderr.write(
|
|
265
|
+
`${typeof result === "string" ? result : "Invalid input"}
|
|
266
|
+
`
|
|
267
|
+
);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return value;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
async function confirm(opts) {
|
|
276
|
+
const def = opts.default ?? false;
|
|
277
|
+
const hint = def ? "(Y/n)" : "(y/N)";
|
|
278
|
+
return withReadline(async (rl) => {
|
|
279
|
+
for (; ; ) {
|
|
280
|
+
const answer = (await rl.question(`${opts.message} ${hint} `)).trim().toLowerCase();
|
|
281
|
+
if (answer === "") return def;
|
|
282
|
+
if (answer === "y" || answer === "yes") return true;
|
|
283
|
+
if (answer === "n" || answer === "no") return false;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
async function select(opts) {
|
|
288
|
+
const { choices } = opts;
|
|
289
|
+
const defaultIndex = opts.default !== void 0 ? choices.findIndex((ch) => ch.value === opts.default) : -1;
|
|
290
|
+
return withReadline(async (rl) => {
|
|
291
|
+
stdout.write(`${opts.message}
|
|
292
|
+
`);
|
|
293
|
+
choices.forEach((ch, i) => {
|
|
294
|
+
const marker = i === defaultIndex ? " (default)" : "";
|
|
295
|
+
stdout.write(` ${i + 1}) ${ch.name}${marker}
|
|
296
|
+
`);
|
|
297
|
+
});
|
|
298
|
+
const prompt = `Enter a number (1-${choices.length})${defaultIndex >= 0 ? ` [${defaultIndex + 1}]` : ""}: `;
|
|
299
|
+
for (; ; ) {
|
|
300
|
+
const answer = (await rl.question(prompt)).trim();
|
|
301
|
+
if (answer === "" && defaultIndex >= 0)
|
|
302
|
+
return choices[defaultIndex].value;
|
|
303
|
+
const n = Number(answer);
|
|
304
|
+
if (Number.isInteger(n) && n >= 1 && n <= choices.length) {
|
|
305
|
+
return choices[n - 1].value;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
234
310
|
|
|
235
311
|
// src/benchmark/api.ts
|
|
236
312
|
var BenchmarkApiError = class extends Error {
|
|
@@ -488,9 +564,9 @@ async function cohortsCommand(opts) {
|
|
|
488
564
|
);
|
|
489
565
|
return;
|
|
490
566
|
}
|
|
491
|
-
for (const
|
|
567
|
+
for (const c2 of cohorts) {
|
|
492
568
|
console.log(
|
|
493
|
-
`${
|
|
569
|
+
`${c2.id} ${c2.displayName} pack v${c2.activePackVersion} k_min=${c2.kMin} targets=${c2.targetCount} submissions=${c2.submissionCount}`
|
|
494
570
|
);
|
|
495
571
|
}
|
|
496
572
|
} catch (err) {
|
|
@@ -670,9 +746,9 @@ async function interactiveSubmitFlow(creds, scanId, log) {
|
|
|
670
746
|
}
|
|
671
747
|
const cohortId = cohorts.length === 1 ? cohorts[0].id : await select({
|
|
672
748
|
message: "Cohort to contribute to:",
|
|
673
|
-
choices: cohorts.map((
|
|
674
|
-
name: `${
|
|
675
|
-
value:
|
|
749
|
+
choices: cohorts.map((c2) => ({
|
|
750
|
+
name: `${c2.displayName} (pack v${c2.activePackVersion})`,
|
|
751
|
+
value: c2.id
|
|
676
752
|
}))
|
|
677
753
|
});
|
|
678
754
|
const detail = await getCohort(creds, cohortId);
|
|
@@ -700,7 +776,6 @@ async function interactiveSubmitFlow(creds, scanId, log) {
|
|
|
700
776
|
// src/commands/init.ts
|
|
701
777
|
import { existsSync as existsSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
702
778
|
import { resolve } from "path";
|
|
703
|
-
import { select as select2, input, confirm as confirm2 } from "@inquirer/prompts";
|
|
704
779
|
var CONFIG_FILENAME = "shield.config.json";
|
|
705
780
|
async function initCommand() {
|
|
706
781
|
console.log("\nShield LLM \u2014 Configuration wizard\n");
|
|
@@ -713,7 +788,7 @@ async function initCommand() {
|
|
|
713
788
|
}
|
|
714
789
|
const configPath = resolve(CONFIG_FILENAME);
|
|
715
790
|
if (existsSync2(configPath)) {
|
|
716
|
-
const overwrite = await
|
|
791
|
+
const overwrite = await confirm({
|
|
717
792
|
message: `${CONFIG_FILENAME} already exists. Overwrite?`,
|
|
718
793
|
default: false
|
|
719
794
|
});
|
|
@@ -733,7 +808,7 @@ async function initCommand() {
|
|
|
733
808
|
}
|
|
734
809
|
}
|
|
735
810
|
});
|
|
736
|
-
const method = await
|
|
811
|
+
const method = await select({
|
|
737
812
|
message: "HTTP method:",
|
|
738
813
|
choices: [
|
|
739
814
|
{ value: "POST", name: "POST (most chatbots)" },
|
|
@@ -745,7 +820,7 @@ async function initCommand() {
|
|
|
745
820
|
const auth = await collectAuth();
|
|
746
821
|
const { body, responseField } = await collectBodyShape();
|
|
747
822
|
const customHeaders = await collectCustomHeaders();
|
|
748
|
-
const preset = await
|
|
823
|
+
const preset = await select({
|
|
749
824
|
message: "Default scan preset:",
|
|
750
825
|
choices: [
|
|
751
826
|
{ value: "owasp", name: "owasp \u2014 OWASP LLM Top 10 (10 tests)" },
|
|
@@ -798,7 +873,7 @@ ${issues}`);
|
|
|
798
873
|
console.log("");
|
|
799
874
|
}
|
|
800
875
|
async function collectAuth() {
|
|
801
|
-
const authType = await
|
|
876
|
+
const authType = await select({
|
|
802
877
|
message: "How does your endpoint authenticate?",
|
|
803
878
|
choices: [
|
|
804
879
|
{ value: "none", name: "No authentication" },
|
|
@@ -849,7 +924,7 @@ async function collectAuth() {
|
|
|
849
924
|
return { type: "oauth2", clientId, clientSecret, tokenUrl };
|
|
850
925
|
}
|
|
851
926
|
async function collectBodyShape() {
|
|
852
|
-
const shape = await
|
|
927
|
+
const shape = await select({
|
|
853
928
|
message: "Request body shape:",
|
|
854
929
|
choices: [
|
|
855
930
|
{
|
|
@@ -875,7 +950,7 @@ async function collectBodyShape() {
|
|
|
875
950
|
default: "message"
|
|
876
951
|
});
|
|
877
952
|
const body = { [promptField]: "{{prompt}}" };
|
|
878
|
-
const addExtra = await
|
|
953
|
+
const addExtra = await confirm({
|
|
879
954
|
message: "Add extra fixed fields to the request body (assistant_id, thread_id, ...) ?",
|
|
880
955
|
default: false
|
|
881
956
|
});
|
|
@@ -890,7 +965,7 @@ async function collectBodyShape() {
|
|
|
890
965
|
message: `Value for "${key}":`
|
|
891
966
|
});
|
|
892
967
|
body[key] = value;
|
|
893
|
-
more = await
|
|
968
|
+
more = await confirm({ message: "Another field?", default: false });
|
|
894
969
|
}
|
|
895
970
|
}
|
|
896
971
|
const responseField = await input({
|
|
@@ -900,7 +975,7 @@ async function collectBodyShape() {
|
|
|
900
975
|
return { body, responseField };
|
|
901
976
|
}
|
|
902
977
|
async function collectCustomHeaders() {
|
|
903
|
-
const add = await
|
|
978
|
+
const add = await confirm({
|
|
904
979
|
message: "Add custom request headers?",
|
|
905
980
|
default: false
|
|
906
981
|
});
|
|
@@ -917,7 +992,7 @@ async function collectCustomHeaders() {
|
|
|
917
992
|
});
|
|
918
993
|
warnIfHardcodedSecret(value);
|
|
919
994
|
headers[name] = value;
|
|
920
|
-
more = await
|
|
995
|
+
more = await confirm({ message: "Another header?", default: false });
|
|
921
996
|
}
|
|
922
997
|
return headers;
|
|
923
998
|
}
|
|
@@ -1234,21 +1309,119 @@ var BackendEvaluator = class {
|
|
|
1234
1309
|
}
|
|
1235
1310
|
};
|
|
1236
1311
|
|
|
1312
|
+
// src/display/spinner.ts
|
|
1313
|
+
var FRAMES_UNICODE = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1314
|
+
var FRAMES_ASCII = ["-", "\\", "|", "/"];
|
|
1315
|
+
function unicodeSupported() {
|
|
1316
|
+
if (process.platform !== "win32") {
|
|
1317
|
+
return /UTF-?8/i.test(
|
|
1318
|
+
process.env.LC_ALL || process.env.LC_CTYPE || process.env.LANG || ""
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
return Boolean(
|
|
1322
|
+
process.env.WT_SESSION || process.env.TERM_PROGRAM === "vscode"
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
var AnsiSpinner = class {
|
|
1326
|
+
constructor() {
|
|
1327
|
+
this._text = "";
|
|
1328
|
+
this.timer = null;
|
|
1329
|
+
this.frame = 0;
|
|
1330
|
+
this.cursorHidden = false;
|
|
1331
|
+
this.isTTY = process.stderr.isTTY === true;
|
|
1332
|
+
this.frames = unicodeSupported() ? FRAMES_UNICODE : FRAMES_ASCII;
|
|
1333
|
+
this.sym = unicodeSupported() ? { ok: "\u2714", fail: "\u2716", warn: "\u26A0", info: "\u2139" } : { ok: "\u221A", fail: "\xD7", warn: "\u203C", info: "i" };
|
|
1334
|
+
}
|
|
1335
|
+
get text() {
|
|
1336
|
+
return this._text;
|
|
1337
|
+
}
|
|
1338
|
+
set text(value) {
|
|
1339
|
+
this._text = value;
|
|
1340
|
+
if (this.isTTY && this.timer) this.render();
|
|
1341
|
+
}
|
|
1342
|
+
render() {
|
|
1343
|
+
process.stderr.write(
|
|
1344
|
+
`\r\x1B[K${c.cyan(this.frames[this.frame])} ${this._text}`
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
start(text) {
|
|
1348
|
+
if (text !== void 0) this._text = text;
|
|
1349
|
+
if (!this.isTTY) {
|
|
1350
|
+
if (text) process.stderr.write(`${text}
|
|
1351
|
+
`);
|
|
1352
|
+
return this;
|
|
1353
|
+
}
|
|
1354
|
+
if (!this.cursorHidden) {
|
|
1355
|
+
process.stderr.write("\x1B[?25l");
|
|
1356
|
+
this.cursorHidden = true;
|
|
1357
|
+
}
|
|
1358
|
+
if (this.timer) clearInterval(this.timer);
|
|
1359
|
+
this.render();
|
|
1360
|
+
this.timer = setInterval(() => {
|
|
1361
|
+
this.frame = (this.frame + 1) % this.frames.length;
|
|
1362
|
+
this.render();
|
|
1363
|
+
}, 80);
|
|
1364
|
+
this.timer.unref?.();
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1367
|
+
stop() {
|
|
1368
|
+
if (this.timer) {
|
|
1369
|
+
clearInterval(this.timer);
|
|
1370
|
+
this.timer = null;
|
|
1371
|
+
}
|
|
1372
|
+
if (this.isTTY) process.stderr.write("\r\x1B[K");
|
|
1373
|
+
if (this.cursorHidden) {
|
|
1374
|
+
process.stderr.write("\x1B[?25h");
|
|
1375
|
+
this.cursorHidden = false;
|
|
1376
|
+
}
|
|
1377
|
+
return this;
|
|
1378
|
+
}
|
|
1379
|
+
persist(symbol, text) {
|
|
1380
|
+
if (this.timer) {
|
|
1381
|
+
clearInterval(this.timer);
|
|
1382
|
+
this.timer = null;
|
|
1383
|
+
}
|
|
1384
|
+
if (this.isTTY) process.stderr.write("\r\x1B[K");
|
|
1385
|
+
process.stderr.write(`${symbol} ${text ?? this._text}
|
|
1386
|
+
`);
|
|
1387
|
+
return this;
|
|
1388
|
+
}
|
|
1389
|
+
succeed(text) {
|
|
1390
|
+
return this.persist(c.green(this.sym.ok), text);
|
|
1391
|
+
}
|
|
1392
|
+
fail(text) {
|
|
1393
|
+
return this.persist(c.red(this.sym.fail), text);
|
|
1394
|
+
}
|
|
1395
|
+
warn(text) {
|
|
1396
|
+
return this.persist(c.yellow(this.sym.warn), text);
|
|
1397
|
+
}
|
|
1398
|
+
info(text) {
|
|
1399
|
+
return this.persist(c.cyan(this.sym.info), text);
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
function createSpinner() {
|
|
1403
|
+
const spinner2 = new AnsiSpinner();
|
|
1404
|
+
if (process.stderr.isTTY) {
|
|
1405
|
+
process.once("exit", () => spinner2.stop());
|
|
1406
|
+
process.once("SIGINT", () => {
|
|
1407
|
+
spinner2.stop();
|
|
1408
|
+
process.exit(130);
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
return spinner2;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1237
1414
|
// src/display/progress.ts
|
|
1238
|
-
|
|
1239
|
-
import ora from "ora";
|
|
1240
|
-
var spinner = ora();
|
|
1415
|
+
var spinner = createSpinner();
|
|
1241
1416
|
var currentAttackName = "";
|
|
1242
1417
|
function handleEvent(event) {
|
|
1243
1418
|
switch (event.type) {
|
|
1244
1419
|
case "scan:start":
|
|
1245
|
-
spinner.start(
|
|
1246
|
-
chalk.cyan(`Starting scan (${event.totalAttacks} attacks)...`)
|
|
1247
|
-
);
|
|
1420
|
+
spinner.start(c.cyan(`Starting scan (${event.totalAttacks} attacks)...`));
|
|
1248
1421
|
break;
|
|
1249
1422
|
case "scan:resume":
|
|
1250
1423
|
spinner.info(
|
|
1251
|
-
|
|
1424
|
+
c.cyan(
|
|
1252
1425
|
`Resuming \u2014 ${event.completed}/${event.total} attacks already done, running the rest`
|
|
1253
1426
|
)
|
|
1254
1427
|
);
|
|
@@ -1256,7 +1429,7 @@ function handleEvent(event) {
|
|
|
1256
1429
|
break;
|
|
1257
1430
|
case "attack:start":
|
|
1258
1431
|
currentAttackName = event.attack.name;
|
|
1259
|
-
spinner.text =
|
|
1432
|
+
spinner.text = c.cyan(
|
|
1260
1433
|
`[${event.index + 1}/${event.total}] ${event.attack.name} (${severityColor(event.attack.severity)})`
|
|
1261
1434
|
);
|
|
1262
1435
|
break;
|
|
@@ -1265,14 +1438,14 @@ function handleEvent(event) {
|
|
|
1265
1438
|
const prefix = `[${event.index + 1}/${event.total}]`;
|
|
1266
1439
|
if (result.error) {
|
|
1267
1440
|
spinner.warn(
|
|
1268
|
-
`${prefix} ${result.name} \u2014 ${
|
|
1441
|
+
`${prefix} ${result.name} \u2014 ${c.yellow("error")}: ${result.error}`
|
|
1269
1442
|
);
|
|
1270
1443
|
} else if (result.vulnerable) {
|
|
1271
1444
|
spinner.fail(
|
|
1272
|
-
`${prefix} ${result.name} \u2014 ${
|
|
1445
|
+
`${prefix} ${result.name} \u2014 ${c.red("VULNERABLE")} (${severityColor(result.severity)})`
|
|
1273
1446
|
);
|
|
1274
1447
|
} else {
|
|
1275
|
-
spinner.succeed(`${prefix} ${result.name} \u2014 ${
|
|
1448
|
+
spinner.succeed(`${prefix} ${result.name} \u2014 ${c.green("secure")}`);
|
|
1276
1449
|
}
|
|
1277
1450
|
if (event.index < event.total - 1) {
|
|
1278
1451
|
spinner.start();
|
|
@@ -1280,18 +1453,18 @@ function handleEvent(event) {
|
|
|
1280
1453
|
break;
|
|
1281
1454
|
}
|
|
1282
1455
|
case "crescendo:turn":
|
|
1283
|
-
spinner.text =
|
|
1456
|
+
spinner.text = c.cyan(
|
|
1284
1457
|
`${currentAttackName} \u2014 turn ${event.turn}/${event.totalTurns}`
|
|
1285
1458
|
);
|
|
1286
1459
|
break;
|
|
1287
1460
|
case "attack:retry":
|
|
1288
|
-
spinner.text =
|
|
1461
|
+
spinner.text = c.yellow(
|
|
1289
1462
|
`${currentAttackName} \u2014 ${event.reason === "rate_limited" ? "rate limited" : "server error"}, backing off ${(event.waitMs / 1e3).toFixed(1)}s (retry ${event.attempt}/${event.maxRetries})`
|
|
1290
1463
|
);
|
|
1291
1464
|
break;
|
|
1292
1465
|
case "scan:rate_limited":
|
|
1293
1466
|
spinner.fail(
|
|
1294
|
-
|
|
1467
|
+
c.red(
|
|
1295
1468
|
`Rate limited by target \u2014 skipping remaining attacks${event.retryAfterSec ? ` (retry after ${event.retryAfterSec}s)` : ""}`
|
|
1296
1469
|
)
|
|
1297
1470
|
);
|
|
@@ -1304,9 +1477,9 @@ function handleEvent(event) {
|
|
|
1304
1477
|
}
|
|
1305
1478
|
function printSummary(report, thresholds) {
|
|
1306
1479
|
console.log("");
|
|
1307
|
-
console.log(
|
|
1480
|
+
console.log(c.bold("\u2550\u2550\u2550 Shield LLM Scan Results \u2550\u2550\u2550"));
|
|
1308
1481
|
console.log("");
|
|
1309
|
-
console.log(` Target: ${
|
|
1482
|
+
console.log(` Target: ${c.white(report.target)}`);
|
|
1310
1483
|
console.log(` Score: ${scoreColor(report.score)}`);
|
|
1311
1484
|
console.log(` Grade: ${gradeColor(report.grade)}`);
|
|
1312
1485
|
console.log(` Duration: ${(report.durationMs / 1e3).toFixed(1)}s`);
|
|
@@ -1315,15 +1488,15 @@ function printSummary(report, thresholds) {
|
|
|
1315
1488
|
const secure = report.attacks.filter((a) => !a.vulnerable && !a.error);
|
|
1316
1489
|
const errors = report.attacks.filter((a) => a.error);
|
|
1317
1490
|
console.log(
|
|
1318
|
-
` ${
|
|
1491
|
+
` ${c.red(`${vulnerable.length} vulnerable`)} \xB7 ${c.green(`${secure.length} secure`)} \xB7 ${c.yellow(`${errors.length} errors`)}`
|
|
1319
1492
|
);
|
|
1320
1493
|
if (vulnerable.length > 0) {
|
|
1321
1494
|
console.log("");
|
|
1322
|
-
console.log(
|
|
1495
|
+
console.log(c.redBold(" Vulnerabilities:"));
|
|
1323
1496
|
for (const a of vulnerable) {
|
|
1324
1497
|
const conf = a.llmEvaluation ? ` (${(a.llmEvaluation.confidence * 100).toFixed(0)}% confidence)` : "";
|
|
1325
1498
|
console.log(
|
|
1326
|
-
` ${
|
|
1499
|
+
` ${c.red("\u2717")} ${a.name} \u2014 ${severityColor(a.severity)}${conf}`
|
|
1327
1500
|
);
|
|
1328
1501
|
}
|
|
1329
1502
|
}
|
|
@@ -1331,21 +1504,21 @@ function printSummary(report, thresholds) {
|
|
|
1331
1504
|
if (judge.degraded) {
|
|
1332
1505
|
console.log("");
|
|
1333
1506
|
console.log(
|
|
1334
|
-
|
|
1507
|
+
c.bgYellowBlackBold(" JUDGE DEGRADED ") + c.yellow(
|
|
1335
1508
|
` ${judge.degradedCount}/${judge.totalEvaluated} verdicts fell back to regex (${judge.errorSummary}).`
|
|
1336
1509
|
)
|
|
1337
1510
|
);
|
|
1338
1511
|
console.log(
|
|
1339
|
-
|
|
1512
|
+
c.yellow(
|
|
1340
1513
|
" Regex-only verdicts are less reliable than LLM-assisted ones. False positives likely. Fix the LLM provider config and re-run."
|
|
1341
1514
|
)
|
|
1342
1515
|
);
|
|
1343
1516
|
}
|
|
1344
1517
|
console.log("");
|
|
1345
1518
|
if (thresholds.passed) {
|
|
1346
|
-
console.log(
|
|
1519
|
+
console.log(c.greenBold(" \u2713 PASSED \u2014 all thresholds met"));
|
|
1347
1520
|
} else {
|
|
1348
|
-
console.log(
|
|
1521
|
+
console.log(c.redBold(" \u2717 FAILED \u2014 threshold violations:"));
|
|
1349
1522
|
for (const reason of thresholds.reasons) {
|
|
1350
1523
|
console.log(` - ${reason}`);
|
|
1351
1524
|
}
|
|
@@ -1355,36 +1528,36 @@ function printSummary(report, thresholds) {
|
|
|
1355
1528
|
function severityColor(severity) {
|
|
1356
1529
|
switch (severity) {
|
|
1357
1530
|
case "CRITICAL":
|
|
1358
|
-
return
|
|
1531
|
+
return c.redBold(severity);
|
|
1359
1532
|
case "HIGH":
|
|
1360
1533
|
case "CRESCENDO":
|
|
1361
1534
|
case "COMBO":
|
|
1362
|
-
return
|
|
1535
|
+
return c.yellow(severity);
|
|
1363
1536
|
case "MEDIUM":
|
|
1364
|
-
return
|
|
1537
|
+
return c.blue(severity);
|
|
1365
1538
|
default:
|
|
1366
|
-
return
|
|
1539
|
+
return c.gray(severity);
|
|
1367
1540
|
}
|
|
1368
1541
|
}
|
|
1369
1542
|
function scoreColor(score) {
|
|
1370
|
-
if (score >= 90) return
|
|
1371
|
-
if (score >= 75) return
|
|
1372
|
-
if (score >= 60) return
|
|
1373
|
-
if (score >= 40) return
|
|
1374
|
-
return
|
|
1543
|
+
if (score >= 90) return c.greenBold(`${score}/100`);
|
|
1544
|
+
if (score >= 75) return c.green(`${score}/100`);
|
|
1545
|
+
if (score >= 60) return c.yellow(`${score}/100`);
|
|
1546
|
+
if (score >= 40) return c.red(`${score}/100`);
|
|
1547
|
+
return c.redBold(`${score}/100`);
|
|
1375
1548
|
}
|
|
1376
1549
|
function gradeColor(grade) {
|
|
1377
1550
|
switch (grade) {
|
|
1378
1551
|
case "A":
|
|
1379
|
-
return
|
|
1552
|
+
return c.greenBold(grade);
|
|
1380
1553
|
case "B":
|
|
1381
|
-
return
|
|
1554
|
+
return c.green(grade);
|
|
1382
1555
|
case "C":
|
|
1383
|
-
return
|
|
1556
|
+
return c.yellow(grade);
|
|
1384
1557
|
case "D":
|
|
1385
|
-
return
|
|
1558
|
+
return c.red(grade);
|
|
1386
1559
|
default:
|
|
1387
|
-
return
|
|
1560
|
+
return c.redBold(grade);
|
|
1388
1561
|
}
|
|
1389
1562
|
}
|
|
1390
1563
|
|
|
@@ -1639,7 +1812,7 @@ async function retestCommand(scanId, opts) {
|
|
|
1639
1812
|
attacks: plan.singles.map((s) => s.attack),
|
|
1640
1813
|
multiTurnAttacks: plan.multiTurn.map((m) => m.attack),
|
|
1641
1814
|
includeCrescendo: plan.multiTurn.length > 0,
|
|
1642
|
-
customTests: plan.customs.map((
|
|
1815
|
+
customTests: plan.customs.map((c2) => c2.test),
|
|
1643
1816
|
concurrency: config.concurrency,
|
|
1644
1817
|
delayMs: config.delayMs,
|
|
1645
1818
|
attackTimeoutMs: config.attackTimeoutMs,
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shield-llm",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "AI chatbot security scanner — automated red teaming for LLMs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -50,21 +50,9 @@
|
|
|
50
50
|
"prepublishOnly": "pnpm build"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@inquirer/prompts": "^8.2.1",
|
|
54
|
-
"chalk": "^5.3.0",
|
|
55
53
|
"commander": "^12.0.0",
|
|
56
|
-
"dotenv": "^17.2.3",
|
|
57
|
-
"ora": "^8.0.0",
|
|
58
54
|
"zod": "^3.23.0"
|
|
59
55
|
},
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"puppeteer": ">=24"
|
|
62
|
-
},
|
|
63
|
-
"peerDependenciesMeta": {
|
|
64
|
-
"puppeteer": {
|
|
65
|
-
"optional": true
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
56
|
"devDependencies": {
|
|
69
57
|
"@shield-llm/scanner-core": "workspace:*",
|
|
70
58
|
"@shield-llm/shared": "workspace:*",
|