shield-llm 0.6.8 → 0.7.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/README.md +55 -2
- package/dist/{chunk-HQGV3UIF.js → chunk-WGJYDA2Q.js} +422 -83
- package/dist/cli.js +221 -85
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
CROSSWALK_GAPS,
|
|
8
8
|
ConfigError,
|
|
9
9
|
ConfigSchema,
|
|
10
|
+
DORA_PARAGRAPHS,
|
|
11
|
+
DORA_PARAGRAPHS_VERIFIED_ON,
|
|
12
|
+
DORA_REGULATION_LABEL,
|
|
10
13
|
EU_AI_ACT_FRAMEWORK_VERSION,
|
|
11
14
|
FRAMEWORK_IDS,
|
|
12
15
|
FRAMEWORK_LABELS,
|
|
@@ -24,6 +27,7 @@ import {
|
|
|
24
27
|
buildTargetConfig,
|
|
25
28
|
c,
|
|
26
29
|
calculateComplianceScore,
|
|
30
|
+
checkConversationContext,
|
|
27
31
|
checkSessionIsolation,
|
|
28
32
|
computeCatalogHash,
|
|
29
33
|
computeScanKey,
|
|
@@ -54,6 +58,7 @@ import {
|
|
|
54
58
|
normalizeTargetUrl,
|
|
55
59
|
parseSegmentKey,
|
|
56
60
|
parseSnapshot,
|
|
61
|
+
recordVerification,
|
|
57
62
|
replaceLoneSurrogates,
|
|
58
63
|
resolveClaim,
|
|
59
64
|
resolveOfflinePosition,
|
|
@@ -62,7 +67,7 @@ import {
|
|
|
62
67
|
sha256Hex,
|
|
63
68
|
summarizeAttackErrors,
|
|
64
69
|
version
|
|
65
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-WGJYDA2Q.js";
|
|
66
71
|
|
|
67
72
|
// src/load-env.ts
|
|
68
73
|
try {
|
|
@@ -2053,16 +2058,84 @@ function safeHostname(url) {
|
|
|
2053
2058
|
}
|
|
2054
2059
|
|
|
2055
2060
|
// src/commands/scan.ts
|
|
2056
|
-
import { writeFileSync as
|
|
2061
|
+
import { writeFileSync as writeFileSync7 } from "fs";
|
|
2057
2062
|
import { resolve as resolve4 } from "path";
|
|
2058
2063
|
|
|
2059
2064
|
// src/reporters/evidence.ts
|
|
2060
|
-
import { writeFileSync as
|
|
2065
|
+
import { writeFileSync as writeFileSync6 } from "fs";
|
|
2061
2066
|
import { resolve as resolve3 } from "path";
|
|
2062
2067
|
|
|
2063
2068
|
// ../../packages/shared/src/compliance/evidence-bundle.ts
|
|
2064
2069
|
import { createHash } from "crypto";
|
|
2065
|
-
|
|
2070
|
+
|
|
2071
|
+
// ../../packages/shared/src/compliance/remediation-validation.ts
|
|
2072
|
+
var INFORMATIVE = "Records of Shield's remediation loop for the findings of this target: each fix's frozen verification contract and every post-deploy re-test with its per-attack result. Offered as evidence a financial entity's own internal validation methodology (DORA Art. 24(5)) can rely on. The obligation binds the entity; this block does not state that the entity complies.";
|
|
2073
|
+
function toClaim(c2) {
|
|
2074
|
+
const live = c2.liveVerification;
|
|
2075
|
+
return {
|
|
2076
|
+
findingFingerprint: c2.findingFingerprint,
|
|
2077
|
+
recipeId: c2.recipeId,
|
|
2078
|
+
status: c2.status,
|
|
2079
|
+
createdAt: c2.createdAt,
|
|
2080
|
+
...c2.deployedAt ? { deployedAt: c2.deployedAt } : {},
|
|
2081
|
+
...c2.resolvedAt ? { resolvedAt: c2.resolvedAt } : {},
|
|
2082
|
+
...c2.closedBy ? { closedBy: c2.closedBy } : {},
|
|
2083
|
+
...c2.prUrl ? { prUrl: c2.prUrl } : {},
|
|
2084
|
+
...c2.benignBypassed ? { benignBypassed: true } : {},
|
|
2085
|
+
contract: {
|
|
2086
|
+
designAttackIds: [...c2.contract.designAttackIds],
|
|
2087
|
+
holdoutAttackIds: [...c2.contract.holdoutAttackIds],
|
|
2088
|
+
holdoutKind: c2.contract.holdoutKind
|
|
2089
|
+
},
|
|
2090
|
+
...live ? {
|
|
2091
|
+
fixTimeVerification: {
|
|
2092
|
+
verifiedAt: live.verifiedAt,
|
|
2093
|
+
designClearedIds: [...live.designClearedIds],
|
|
2094
|
+
holdoutClearedIds: [...live.holdoutClearedIds],
|
|
2095
|
+
notExecutedAttackIds: [...live.notExecutedAttackIds],
|
|
2096
|
+
benign: { ...live.benign },
|
|
2097
|
+
judgeDegraded: live.judgeDegraded,
|
|
2098
|
+
sessionIsolated: live.sessionIsolated,
|
|
2099
|
+
passed: live.passed
|
|
2100
|
+
}
|
|
2101
|
+
} : {},
|
|
2102
|
+
verifications: (c2.verifications ?? []).map((v) => ({
|
|
2103
|
+
...v,
|
|
2104
|
+
attacks: v.attacks.map((a) => ({ ...a })),
|
|
2105
|
+
benign: { ...v.benign }
|
|
2106
|
+
}))
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2109
|
+
function buildRemediationValidation(claims) {
|
|
2110
|
+
const paragraph = DORA_PARAGRAPHS["Art. 24(5)"];
|
|
2111
|
+
const count = (s) => claims.filter((c2) => c2.status === s).length;
|
|
2112
|
+
return {
|
|
2113
|
+
informative: INFORMATIVE,
|
|
2114
|
+
regulation: {
|
|
2115
|
+
label: DORA_REGULATION_LABEL,
|
|
2116
|
+
reference: "Art. 24(5)",
|
|
2117
|
+
text: { fr: paragraph.fr, en: paragraph.en },
|
|
2118
|
+
verifiedOn: DORA_PARAGRAPHS_VERIFIED_ON,
|
|
2119
|
+
source: "http://publications.europa.eu/resource/celex/32022R2554"
|
|
2120
|
+
},
|
|
2121
|
+
claims: claims.map(toClaim),
|
|
2122
|
+
summary: {
|
|
2123
|
+
total: claims.length,
|
|
2124
|
+
confirmed: count("confirmed"),
|
|
2125
|
+
confirmedOverfit: count("confirmed_overfit"),
|
|
2126
|
+
refutedOrNotDeployed: count("refuted_or_not_deployed"),
|
|
2127
|
+
pending: count("pending"),
|
|
2128
|
+
inconclusive: count("inconclusive"),
|
|
2129
|
+
expired: count("expired"),
|
|
2130
|
+
withVerificationEvidence: claims.filter(
|
|
2131
|
+
(c2) => (c2.verifications ?? []).length > 0
|
|
2132
|
+
).length
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
// ../../packages/shared/src/compliance/evidence-bundle.ts
|
|
2138
|
+
var EVIDENCE_BUNDLE_FORMAT = "shield-evidence/3";
|
|
2066
2139
|
var EVIDENCE_EXCERPT_LIMIT = 2e3;
|
|
2067
2140
|
var EVIDENCE_TOTAL_EXCERPT_BUDGET = 1e6;
|
|
2068
2141
|
function canonicalize(value) {
|
|
@@ -2239,6 +2312,7 @@ function buildEvidenceBundle(input2) {
|
|
|
2239
2312
|
},
|
|
2240
2313
|
crosswalk: buildCrosswalkBlock(),
|
|
2241
2314
|
structuralAssessment: input2.assessment ?? null,
|
|
2315
|
+
remediationValidation: input2.claims ? buildRemediationValidation(input2.claims) : null,
|
|
2242
2316
|
tests: budgetedTests(input2.tests),
|
|
2243
2317
|
limitations: bundleLimitations(
|
|
2244
2318
|
classification,
|
|
@@ -2281,7 +2355,77 @@ function toComplianceOutcomes(attacks) {
|
|
|
2281
2355
|
}));
|
|
2282
2356
|
}
|
|
2283
2357
|
|
|
2358
|
+
// src/fix/claim-store.ts
|
|
2359
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync5 } from "fs";
|
|
2360
|
+
import { dirname, join as join2 } from "path";
|
|
2361
|
+
var DEFAULT_CLAIM_FILE = ".shield-llm/claims.json";
|
|
2362
|
+
var ClaimStore = class _ClaimStore {
|
|
2363
|
+
constructor(path) {
|
|
2364
|
+
this.path = path;
|
|
2365
|
+
}
|
|
2366
|
+
static at(root, file = DEFAULT_CLAIM_FILE) {
|
|
2367
|
+
return new _ClaimStore(join2(root, file));
|
|
2368
|
+
}
|
|
2369
|
+
load() {
|
|
2370
|
+
if (!existsSync3(this.path)) return null;
|
|
2371
|
+
return JSON.parse(readFileSync3(this.path, "utf8"));
|
|
2372
|
+
}
|
|
2373
|
+
list() {
|
|
2374
|
+
return this.load()?.claims ?? [];
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Claims a verification run should look at.
|
|
2378
|
+
*
|
|
2379
|
+
* `refuted_or_not_deployed` is included ON PURPOSE. That status means exactly
|
|
2380
|
+
* "still vulnerable, and we cannot tell whether the patch failed or was
|
|
2381
|
+
* simply not live yet" — so treating it as terminal would make the normal
|
|
2382
|
+
* sequence (patch → verify → deploy → verify again) impossible: the second
|
|
2383
|
+
* verification would find nothing to check. `inconclusive` is included for
|
|
2384
|
+
* the same reason: the family was not executed, so nothing was decided.
|
|
2385
|
+
*
|
|
2386
|
+
* Terminal, and therefore excluded: `confirmed`, `confirmed_overfit`,
|
|
2387
|
+
* `expired`.
|
|
2388
|
+
*/
|
|
2389
|
+
openForVerification() {
|
|
2390
|
+
return this.list().filter(
|
|
2391
|
+
(c2) => c2.status === "pending" || c2.status === "refuted_or_not_deployed" || c2.status === "inconclusive"
|
|
2392
|
+
);
|
|
2393
|
+
}
|
|
2394
|
+
pending() {
|
|
2395
|
+
return this.list().filter((c2) => c2.status === "pending");
|
|
2396
|
+
}
|
|
2397
|
+
/** Upsert by fingerprint+recipe: re-running `fix` refreshes, never duplicates. */
|
|
2398
|
+
upsert(targetId, claim) {
|
|
2399
|
+
const current = this.load() ?? { version: 1, targetId, claims: [] };
|
|
2400
|
+
const idx = current.claims.findIndex(
|
|
2401
|
+
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
2402
|
+
);
|
|
2403
|
+
if (idx === -1) current.claims.push(claim);
|
|
2404
|
+
else current.claims[idx] = claim;
|
|
2405
|
+
this.write({ ...current, targetId });
|
|
2406
|
+
}
|
|
2407
|
+
replace(claim) {
|
|
2408
|
+
const current = this.load();
|
|
2409
|
+
if (!current) return;
|
|
2410
|
+
const idx = current.claims.findIndex(
|
|
2411
|
+
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
2412
|
+
);
|
|
2413
|
+
if (idx !== -1) current.claims[idx] = claim;
|
|
2414
|
+
this.write(current);
|
|
2415
|
+
}
|
|
2416
|
+
write(file) {
|
|
2417
|
+
mkdirSync2(dirname(this.path), { recursive: true });
|
|
2418
|
+
writeFileSync5(this.path, `${JSON.stringify(file, null, 2)}
|
|
2419
|
+
`, "utf8");
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
|
|
2284
2423
|
// src/reporters/evidence.ts
|
|
2424
|
+
function claimsForTarget(target, cwd) {
|
|
2425
|
+
const file = ClaimStore.at(cwd).load();
|
|
2426
|
+
if (!file) return void 0;
|
|
2427
|
+
return file.targetId === normalizeTargetUrl(target) ? file.claims : [];
|
|
2428
|
+
}
|
|
2285
2429
|
function writeEvidenceBundle(input2) {
|
|
2286
2430
|
const executed = scoredAttacks(input2.report.attacks);
|
|
2287
2431
|
const tests = executed.map((a) => ({
|
|
@@ -2299,6 +2443,7 @@ function writeEvidenceBundle(input2) {
|
|
|
2299
2443
|
prompt: a.prompt,
|
|
2300
2444
|
responseExcerpt: a.response
|
|
2301
2445
|
}));
|
|
2446
|
+
const claims = claimsForTarget(input2.report.target, input2.cwd ?? process.cwd());
|
|
2302
2447
|
const bundle = buildEvidenceBundle({
|
|
2303
2448
|
scan: {
|
|
2304
2449
|
scanId: input2.report.id,
|
|
@@ -2313,15 +2458,17 @@ function writeEvidenceBundle(input2) {
|
|
|
2313
2458
|
},
|
|
2314
2459
|
compliance: input2.compliance,
|
|
2315
2460
|
tests,
|
|
2461
|
+
claims,
|
|
2316
2462
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2317
2463
|
});
|
|
2318
2464
|
const outPath = resolve3(input2.path);
|
|
2319
2465
|
const json = JSON.stringify(bundle, null, 2);
|
|
2320
|
-
|
|
2466
|
+
writeFileSync6(outPath, json, "utf8");
|
|
2321
2467
|
return {
|
|
2322
2468
|
path: outPath,
|
|
2323
2469
|
sha256: bundle.manifest.sha256,
|
|
2324
|
-
bytes: Buffer.byteLength(json, "utf8")
|
|
2470
|
+
bytes: Buffer.byteLength(json, "utf8"),
|
|
2471
|
+
claims: claims ? claims.length : null
|
|
2325
2472
|
};
|
|
2326
2473
|
}
|
|
2327
2474
|
|
|
@@ -2380,6 +2527,30 @@ function alignOutputExtension(file, format) {
|
|
|
2380
2527
|
return { path, changed: path !== file };
|
|
2381
2528
|
}
|
|
2382
2529
|
|
|
2530
|
+
// src/lib/incomplete-scan.ts
|
|
2531
|
+
function incompleteScan(report, judged, total) {
|
|
2532
|
+
const resume = `Re-run the same command: the ${judged} judged attack(s) resume from the checkpoint.`;
|
|
2533
|
+
switch (report.stopReason) {
|
|
2534
|
+
case "auth":
|
|
2535
|
+
return {
|
|
2536
|
+
reason: `The target refused the scan's credentials (HTTP 401) after ${judged}/${total} attacks \u2014 the token has probably expired. Refresh it and re-run the same command: the ${judged} judged attack(s) resume from the checkpoint.`,
|
|
2537
|
+
exitCode: 2
|
|
2538
|
+
};
|
|
2539
|
+
case "rate_limited":
|
|
2540
|
+
return {
|
|
2541
|
+
reason: `The target kept rate-limiting the scan (HTTP 429) after ${judged}/${total} attacks, past the retry budget. Wait, or lower --concurrency / raise --delay. ${resume}`,
|
|
2542
|
+
exitCode: 3
|
|
2543
|
+
};
|
|
2544
|
+
case "consecutive_failures":
|
|
2545
|
+
return {
|
|
2546
|
+
reason: `The scan stopped after repeated failed requests to the target, ${judged}/${total} attacks judged \u2014 the target is failing or unreachable. ${resume}`,
|
|
2547
|
+
exitCode: 3
|
|
2548
|
+
};
|
|
2549
|
+
default:
|
|
2550
|
+
return null;
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2383
2554
|
// src/commands/scan.ts
|
|
2384
2555
|
async function uploadReportToBackend(report, credentials, scanId, attackPackVersion) {
|
|
2385
2556
|
const vulnerabilities = scoredAttacks(report.attacks).map((a) => ({
|
|
@@ -2673,6 +2844,14 @@ async function scanCommand(opts) {
|
|
|
2673
2844
|
if (!isolation.isolated) console.warn(`
|
|
2674
2845
|
\u26A0\uFE0F ${isolation.warning}
|
|
2675
2846
|
`);
|
|
2847
|
+
if (includeCrescendo && (multiTurnAttacks?.length ?? 0) > 0) {
|
|
2848
|
+
const conversation = checkConversationContext(target);
|
|
2849
|
+
if (!conversation.carried) {
|
|
2850
|
+
console.warn(`
|
|
2851
|
+
\u26A0\uFE0F ${conversation.warning}
|
|
2852
|
+
`);
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2676
2855
|
const catalogHash = computeCatalogHash([
|
|
2677
2856
|
...(attacks ?? []).map((a) => a.id),
|
|
2678
2857
|
...(multiTurnAttacks ?? []).map((a) => a.id),
|
|
@@ -2724,6 +2903,18 @@ async function scanCommand(opts) {
|
|
|
2724
2903
|
info("Scan started");
|
|
2725
2904
|
const scanner = new Scanner(scanOptions, onEvent);
|
|
2726
2905
|
const report = await scanner.run();
|
|
2906
|
+
const incomplete = incompleteScan(
|
|
2907
|
+
report,
|
|
2908
|
+
scoredAttacks(report.attacks).length,
|
|
2909
|
+
report.attacks.length
|
|
2910
|
+
);
|
|
2911
|
+
if (incomplete) {
|
|
2912
|
+
await reportScanFailure(credentials, reservedScanId, incomplete.reason);
|
|
2913
|
+
scanFinalized = true;
|
|
2914
|
+
console.error(`Scan stopped: ${incomplete.reason}`);
|
|
2915
|
+
setExitCode(incomplete.exitCode);
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2727
2918
|
const attempted = report.attacks.length;
|
|
2728
2919
|
const evaluated = scoredAttacks(report.attacks).length;
|
|
2729
2920
|
if (reservedScanId && attempted > 0 && evaluated === 0) {
|
|
@@ -2828,6 +3019,7 @@ async function scanCommand(opts) {
|
|
|
2828
3019
|
"",
|
|
2829
3020
|
` Evidence bundle written to ${written.path}`,
|
|
2830
3021
|
` SHA-256: ${written.sha256}`,
|
|
3022
|
+
written.claims === null ? " DORA Art. 24(5): no local claim store here \u2014 the remediation section is empty." : ` DORA Art. 24(5): ${written.claims} remediation claim(s) of this target included.`,
|
|
2831
3023
|
" Contains raw target responses. It is a checksum, not a signature.",
|
|
2832
3024
|
""
|
|
2833
3025
|
].join("\n");
|
|
@@ -2856,7 +3048,7 @@ async function scanCommand(opts) {
|
|
|
2856
3048
|
if (format === "pdf") {
|
|
2857
3049
|
const pdfPath = outputFile ?? `shield-report-${report.id.slice(0, 8)}.pdf`;
|
|
2858
3050
|
const pdfBuffer = await generatePdf(report);
|
|
2859
|
-
|
|
3051
|
+
writeFileSync7(resolve4(pdfPath), pdfBuffer);
|
|
2860
3052
|
info(`PDF report written to ${pdfPath}`);
|
|
2861
3053
|
} else {
|
|
2862
3054
|
let content;
|
|
@@ -2878,7 +3070,7 @@ async function scanCommand(opts) {
|
|
|
2878
3070
|
break;
|
|
2879
3071
|
}
|
|
2880
3072
|
if (outputFile) {
|
|
2881
|
-
|
|
3073
|
+
writeFileSync7(resolve4(outputFile), content, "utf-8");
|
|
2882
3074
|
info(`Report written to ${outputFile}`);
|
|
2883
3075
|
} else {
|
|
2884
3076
|
console.log(content);
|
|
@@ -2894,7 +3086,7 @@ async function scanCommand(opts) {
|
|
|
2894
3086
|
thresholdsConfigured,
|
|
2895
3087
|
compliance: complianceResult
|
|
2896
3088
|
});
|
|
2897
|
-
|
|
3089
|
+
writeFileSync7(jsonPath, jsonContent, "utf-8");
|
|
2898
3090
|
info(
|
|
2899
3091
|
`JSON copy written to ${jsonPath}${opts.includeFullPayloads ? " (full payloads)" : " (sanitized)"}`
|
|
2900
3092
|
);
|
|
@@ -3226,7 +3418,7 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
3226
3418
|
import { resolve as resolve6 } from "path";
|
|
3227
3419
|
|
|
3228
3420
|
// src/fix/anchor-resolver.ts
|
|
3229
|
-
import { existsSync as
|
|
3421
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, statSync } from "fs";
|
|
3230
3422
|
import { isAbsolute, relative, resolve as resolve5, sep } from "path";
|
|
3231
3423
|
var AnchorError = class extends Error {
|
|
3232
3424
|
constructor(message, kind, status) {
|
|
@@ -3265,7 +3457,7 @@ function resolveAnchor(root, kind, anchor) {
|
|
|
3265
3457
|
return { kind, status: "anchor_missing", configHint };
|
|
3266
3458
|
}
|
|
3267
3459
|
const abs = safeResolve(root, anchor.file);
|
|
3268
|
-
if (!
|
|
3460
|
+
if (!existsSync4(abs) || !statSync(abs).isFile()) {
|
|
3269
3461
|
throw new AnchorError(
|
|
3270
3462
|
`${configHint}.file points at "${anchor.file}", which does not exist under ${root}. A stale anchor is worse than a missing one \u2014 it fakes coverage.`,
|
|
3271
3463
|
kind,
|
|
@@ -3273,7 +3465,7 @@ function resolveAnchor(root, kind, anchor) {
|
|
|
3273
3465
|
);
|
|
3274
3466
|
}
|
|
3275
3467
|
if (anchor.export) {
|
|
3276
|
-
const source =
|
|
3468
|
+
const source = readFileSync4(abs, "utf8");
|
|
3277
3469
|
if (!declaresExport(source, anchor.export)) {
|
|
3278
3470
|
throw new AnchorError(
|
|
3279
3471
|
`${configHint}.export is "${anchor.export}" but ${anchor.file} does not declare it. (v1 resolves exports textually: a star re-export like \`export * from "./barrel"\` is not seen \u2014 point the anchor at the file that actually declares the symbol.)`,
|
|
@@ -3473,8 +3665,8 @@ function blockedByAnchor(anchors) {
|
|
|
3473
3665
|
}
|
|
3474
3666
|
|
|
3475
3667
|
// src/fix/operations.ts
|
|
3476
|
-
import { existsSync as
|
|
3477
|
-
import { dirname, relative as relative2 } from "path";
|
|
3668
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, rmSync, writeFileSync as writeFileSync8 } from "fs";
|
|
3669
|
+
import { dirname as dirname2, relative as relative2 } from "path";
|
|
3478
3670
|
|
|
3479
3671
|
// src/fix/marker-block.ts
|
|
3480
3672
|
var EXT_STYLE = {
|
|
@@ -3641,7 +3833,7 @@ var WorkingSet = class {
|
|
|
3641
3833
|
const cached = this.files.get(relPath);
|
|
3642
3834
|
if (cached) return cached.current;
|
|
3643
3835
|
const abs = safeResolve(this.root, relPath);
|
|
3644
|
-
const before =
|
|
3836
|
+
const before = existsSync5(abs) ? readFileSync5(abs, "utf8") : "";
|
|
3645
3837
|
this.files.set(relPath, { before, current: before });
|
|
3646
3838
|
return before;
|
|
3647
3839
|
}
|
|
@@ -3661,11 +3853,11 @@ var WorkingSet = class {
|
|
|
3661
3853
|
if (before === current) continue;
|
|
3662
3854
|
const abs = safeResolve(this.root, path);
|
|
3663
3855
|
if (this.deleted.has(path)) {
|
|
3664
|
-
if (
|
|
3856
|
+
if (existsSync5(abs)) rmSync(abs);
|
|
3665
3857
|
continue;
|
|
3666
3858
|
}
|
|
3667
|
-
|
|
3668
|
-
|
|
3859
|
+
mkdirSync3(dirname2(abs), { recursive: true });
|
|
3860
|
+
writeFileSync8(abs, current, "utf8");
|
|
3669
3861
|
}
|
|
3670
3862
|
}
|
|
3671
3863
|
};
|
|
@@ -4049,71 +4241,6 @@ function renderPrBody(plan, live, withheld = [], rescan = []) {
|
|
|
4049
4241
|
return out.join("\n");
|
|
4050
4242
|
}
|
|
4051
4243
|
|
|
4052
|
-
// src/fix/claim-store.ts
|
|
4053
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync8 } from "fs";
|
|
4054
|
-
import { dirname as dirname2, join as join2 } from "path";
|
|
4055
|
-
var DEFAULT_CLAIM_FILE = ".shield-llm/claims.json";
|
|
4056
|
-
var ClaimStore = class _ClaimStore {
|
|
4057
|
-
constructor(path) {
|
|
4058
|
-
this.path = path;
|
|
4059
|
-
}
|
|
4060
|
-
static at(root, file = DEFAULT_CLAIM_FILE) {
|
|
4061
|
-
return new _ClaimStore(join2(root, file));
|
|
4062
|
-
}
|
|
4063
|
-
load() {
|
|
4064
|
-
if (!existsSync5(this.path)) return null;
|
|
4065
|
-
return JSON.parse(readFileSync5(this.path, "utf8"));
|
|
4066
|
-
}
|
|
4067
|
-
list() {
|
|
4068
|
-
return this.load()?.claims ?? [];
|
|
4069
|
-
}
|
|
4070
|
-
/**
|
|
4071
|
-
* Claims a verification run should look at.
|
|
4072
|
-
*
|
|
4073
|
-
* `refuted_or_not_deployed` is included ON PURPOSE. That status means exactly
|
|
4074
|
-
* "still vulnerable, and we cannot tell whether the patch failed or was
|
|
4075
|
-
* simply not live yet" — so treating it as terminal would make the normal
|
|
4076
|
-
* sequence (patch → verify → deploy → verify again) impossible: the second
|
|
4077
|
-
* verification would find nothing to check. `inconclusive` is included for
|
|
4078
|
-
* the same reason: the family was not executed, so nothing was decided.
|
|
4079
|
-
*
|
|
4080
|
-
* Terminal, and therefore excluded: `confirmed`, `confirmed_overfit`,
|
|
4081
|
-
* `expired`.
|
|
4082
|
-
*/
|
|
4083
|
-
openForVerification() {
|
|
4084
|
-
return this.list().filter(
|
|
4085
|
-
(c2) => c2.status === "pending" || c2.status === "refuted_or_not_deployed" || c2.status === "inconclusive"
|
|
4086
|
-
);
|
|
4087
|
-
}
|
|
4088
|
-
pending() {
|
|
4089
|
-
return this.list().filter((c2) => c2.status === "pending");
|
|
4090
|
-
}
|
|
4091
|
-
/** Upsert by fingerprint+recipe: re-running `fix` refreshes, never duplicates. */
|
|
4092
|
-
upsert(targetId, claim) {
|
|
4093
|
-
const current = this.load() ?? { version: 1, targetId, claims: [] };
|
|
4094
|
-
const idx = current.claims.findIndex(
|
|
4095
|
-
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
4096
|
-
);
|
|
4097
|
-
if (idx === -1) current.claims.push(claim);
|
|
4098
|
-
else current.claims[idx] = claim;
|
|
4099
|
-
this.write({ ...current, targetId });
|
|
4100
|
-
}
|
|
4101
|
-
replace(claim) {
|
|
4102
|
-
const current = this.load();
|
|
4103
|
-
if (!current) return;
|
|
4104
|
-
const idx = current.claims.findIndex(
|
|
4105
|
-
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
4106
|
-
);
|
|
4107
|
-
if (idx !== -1) current.claims[idx] = claim;
|
|
4108
|
-
this.write(current);
|
|
4109
|
-
}
|
|
4110
|
-
write(file) {
|
|
4111
|
-
mkdirSync3(dirname2(this.path), { recursive: true });
|
|
4112
|
-
writeFileSync8(this.path, `${JSON.stringify(file, null, 2)}
|
|
4113
|
-
`, "utf8");
|
|
4114
|
-
}
|
|
4115
|
-
};
|
|
4116
|
-
|
|
4117
4244
|
// src/benign/runner.ts
|
|
4118
4245
|
async function captureBenign(target, cases, opts = {}) {
|
|
4119
4246
|
const client = createTargetClient(target, void 0, { resolveEnv: true });
|
|
@@ -5478,8 +5605,17 @@ async function verifyClaimsCommand(opts) {
|
|
|
5478
5605
|
trigger: "verify-claims",
|
|
5479
5606
|
nowMs: now
|
|
5480
5607
|
});
|
|
5608
|
+
const evidenced = recordVerification(claim, {
|
|
5609
|
+
verdicts,
|
|
5610
|
+
outcome,
|
|
5611
|
+
benign: { ran: benign.ran, green: benign.green, detail: benign.detail },
|
|
5612
|
+
judgeDegraded,
|
|
5613
|
+
sessionIsolated: checkSessionIsolation(target).isolated,
|
|
5614
|
+
trigger: "verify-claims",
|
|
5615
|
+
nowMs: now
|
|
5616
|
+
});
|
|
5481
5617
|
const updated = {
|
|
5482
|
-
...
|
|
5618
|
+
...evidenced,
|
|
5483
5619
|
status: outcome.status,
|
|
5484
5620
|
deployedAt: claim.deployedAt ?? opts.deployedAt ?? new Date(now).toISOString(),
|
|
5485
5621
|
// Only a TERMINAL status closes a claim. `refuted_or_not_deployed` and
|
|
@@ -5615,7 +5751,7 @@ program.command("scan").description("Run a security scan against a target chatbo
|
|
|
5615
5751
|
"Run ONLY custom tests \u2014 send no preset attack payloads to the target"
|
|
5616
5752
|
).option("--eu-ai-act", "Show EU AI Act compliance assessment after scan").option(
|
|
5617
5753
|
"--evidence-bundle <path>",
|
|
5618
|
-
"Write a checksummed
|
|
5754
|
+
"Write a checksummed evidence bundle (JSON) to <path>: EU AI Act results plus, from the local claim store, the DORA Art. 24(5) record of this target's verified fixes. Implies --eu-ai-act"
|
|
5619
5755
|
).option(
|
|
5620
5756
|
"--compliance-threshold <n>",
|
|
5621
5757
|
"Minimum compliance score (0-100)",
|
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.7.0",
|
|
4
4
|
"description": "AI chatbot security scanner — automated red teaming for LLMs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dist/"
|
|
19
19
|
],
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=22"
|
|
21
|
+
"node": ">=22.3"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"ai",
|