shield-llm 0.6.9 → 0.7.1
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 +26 -0
- package/dist/{chunk-TWBU67PH.js → chunk-YAILR7N5.js} +242 -35
- package/dist/cli.js +220 -94
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -235,6 +235,21 @@ Two honest edges:
|
|
|
235
235
|
- `verify-claims` is the primary closure path, meant to run from your deploy job
|
|
236
236
|
right after deploying. A claim it cannot re-prove stays open.
|
|
237
237
|
|
|
238
|
+
### The record an auditor reads (DORA Art. 24(5))
|
|
239
|
+
|
|
240
|
+
DORA Art. 24(5) asks financial entities for internal validation methods "to
|
|
241
|
+
ascertain that all identified weaknesses, deficiencies or gaps are fully
|
|
242
|
+
addressed". Each `verify-claims` run appends what it observed to the claim:
|
|
243
|
+
every design and holdout attack with its result (closed, still vulnerable, not
|
|
244
|
+
executed), the reason the claim moved, the benign gate and the judge's health.
|
|
245
|
+
A refutation before the deploy and the confirmation after it both stay on file.
|
|
246
|
+
|
|
247
|
+
`scan --evidence-bundle <path>` files that record next to the scan, in the
|
|
248
|
+
checksummed bundle (`shield-evidence/3`): a `remediationValidation` section
|
|
249
|
+
quoting Art. 24(5) word for word, with this target's claims from the local
|
|
250
|
+
claim store. The obligation binds your entity; the bundle is evidence your own
|
|
251
|
+
validation can rely on, not a statement that you comply.
|
|
252
|
+
|
|
238
253
|
## Presets
|
|
239
254
|
|
|
240
255
|
| Preset | Scope |
|
|
@@ -258,6 +273,7 @@ Run `shield-llm presets` to see what your instance serves.
|
|
|
258
273
|
--load-custom-tests also run your dashboard's custom tests
|
|
259
274
|
--custom-only run ONLY your custom tests (no preset attacks)
|
|
260
275
|
--eu-ai-act print an EU AI Act compliance summary
|
|
276
|
+
--evidence-bundle <path> write the checksummed evidence bundle (EU AI Act + DORA Art. 24(5) fixes)
|
|
261
277
|
-o, --output <format> json | markdown | sarif | pdf
|
|
262
278
|
--output-file <path> write the report to a file
|
|
263
279
|
--write-json <path> always write a parseable JSON copy (feeds `fix --report`)
|
|
@@ -284,6 +300,16 @@ is uploaded, the dashboard row is marked failed with the reason, and the
|
|
|
284
300
|
checkpoint is kept: refresh the token and re-run the same command to resume
|
|
285
301
|
where it stopped.
|
|
286
302
|
|
|
303
|
+
The same applies to the other early stops, with exit `3`: a target that keeps
|
|
304
|
+
answering `429` past the retry budget, and the consecutive-failure breaker (the
|
|
305
|
+
target failing or unreachable several requests in a row). A scan that stopped
|
|
306
|
+
early is never reported as finished: re-run the same command later to resume.
|
|
307
|
+
|
|
308
|
+
A reply withheld by the provider's content filter (Gemini / Vertex AI
|
|
309
|
+
`promptFeedback.blockReason` or a filter `finishReason`, OpenAI-compatible
|
|
310
|
+
`finish_reason: "content_filter"`) is judged as a refusal, not counted as a
|
|
311
|
+
failed request.
|
|
312
|
+
|
|
287
313
|
Run `verify-claims` from the deploy job itself, so a claim is re-proved against
|
|
288
314
|
what actually went live:
|
|
289
315
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "module"; import { fileURLToPath as __cjs_fileURLToPath } from "url"; import { dirname as __cjs_dirname } from "path"; const __filename = __cjs_fileURLToPath(import.meta.url); const __dirname = __cjs_dirname(__filename); const require = __cjs_createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// package.json
|
|
4
|
-
var version = "0.
|
|
4
|
+
var version = "0.7.1";
|
|
5
5
|
|
|
6
6
|
// src/config/schema.ts
|
|
7
7
|
import { z as z2 } from "zod";
|
|
@@ -156,6 +156,7 @@ var ANSSI_PA_102 = {
|
|
|
156
156
|
var ANSSI_PA_102_REFS = Object.keys(ANSSI_PA_102);
|
|
157
157
|
|
|
158
158
|
// ../../packages/shared/src/types/dora.ts
|
|
159
|
+
var DORA_REGULATION_LABEL = "R\xE8glement (UE) 2022/2554";
|
|
159
160
|
var DORA_ARTICLES = {
|
|
160
161
|
"Art. 5": { title: "Gouvernance et organisation" },
|
|
161
162
|
"Art. 6": { title: "Cadre de gestion du risque li\xE9 aux TIC" },
|
|
@@ -177,6 +178,18 @@ var DORA_ARTICLES = {
|
|
|
177
178
|
}
|
|
178
179
|
};
|
|
179
180
|
var DORA_ARTICLE_REFS = Object.keys(DORA_ARTICLES);
|
|
181
|
+
var DORA_PARAGRAPHS_VERIFIED_ON = "2026-10-01";
|
|
182
|
+
var DORA_PARAGRAPHS = {
|
|
183
|
+
"Art. 24(5)": {
|
|
184
|
+
article: "Art. 24",
|
|
185
|
+
paragraph: 5,
|
|
186
|
+
fr: "Les entit\xE9s financi\xE8res, autres que les microentreprises, d\xE9finissent des proc\xE9dures et des strat\xE9gies destin\xE9es \xE0 hi\xE9rarchiser, classer et r\xE9soudre tous les probl\xE8mes mis en \xE9vidence au cours des tests et \xE9laborent des m\xE9thodes de validation interne pour veiller \xE0 ce que toutes les faiblesses, d\xE9faillances ou lacunes recens\xE9es soient enti\xE8rement corrig\xE9es.",
|
|
187
|
+
en: "Financial entities, other than microenterprises, shall establish procedures and policies to prioritise, classify and remedy all issues revealed throughout the performance of the tests and shall establish internal validation methodologies to ascertain that all identified weaknesses, deficiencies or gaps are fully addressed."
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
var DORA_PARAGRAPH_REFS = Object.keys(
|
|
191
|
+
DORA_PARAGRAPHS
|
|
192
|
+
);
|
|
180
193
|
|
|
181
194
|
// ../../packages/shared/src/types/vulnerability.ts
|
|
182
195
|
var VULN_TO_OWASP = {
|
|
@@ -742,7 +755,7 @@ function remapOwaspRef(ref, version2 = CURRENT_OWASP_TAXONOMY) {
|
|
|
742
755
|
}
|
|
743
756
|
|
|
744
757
|
// ../../packages/shared/src/attacks/version.ts
|
|
745
|
-
var ATTACK_PACK_VERSION = "2.2.
|
|
758
|
+
var ATTACK_PACK_VERSION = "2.2.1";
|
|
746
759
|
|
|
747
760
|
// ../../packages/shared/src/attacks/mutators.ts
|
|
748
761
|
var MUTATOR_SEPARATOR = "::";
|
|
@@ -954,37 +967,103 @@ function owaspKeyForAttack(id) {
|
|
|
954
967
|
return VULN_TO_OWASP[id] ?? VULN_TO_OWASP[baseAttackId(id)];
|
|
955
968
|
}
|
|
956
969
|
|
|
970
|
+
// ../../packages/shared/src/regex-guard.ts
|
|
971
|
+
var REGEX_DEADLINE_MS = 100;
|
|
972
|
+
function regexBudget(totalMs = REGEX_DEADLINE_MS) {
|
|
973
|
+
return { deadline: performance.now() + totalMs, timedOut: false };
|
|
974
|
+
}
|
|
975
|
+
var exec;
|
|
976
|
+
var watched = false;
|
|
977
|
+
function getExec() {
|
|
978
|
+
if (exec !== void 0) return exec;
|
|
979
|
+
const proc = globalThis.process;
|
|
980
|
+
const vm = typeof proc?.getBuiltinModule === "function" ? proc.getBuiltinModule("node:vm") : void 0;
|
|
981
|
+
if (!vm) {
|
|
982
|
+
exec = null;
|
|
983
|
+
return exec;
|
|
984
|
+
}
|
|
985
|
+
const sandbox = {};
|
|
986
|
+
const context = vm.createContext(sandbox);
|
|
987
|
+
const script = new vm.Script("__fn()");
|
|
988
|
+
exec = (fn, timeoutMs) => {
|
|
989
|
+
sandbox.__fn = fn;
|
|
990
|
+
try {
|
|
991
|
+
return script.runInContext(context, { timeout: timeoutMs });
|
|
992
|
+
} finally {
|
|
993
|
+
sandbox.__fn = void 0;
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
return exec;
|
|
997
|
+
}
|
|
998
|
+
function isTimeout(err) {
|
|
999
|
+
return typeof err === "object" && err !== null && err.code === "ERR_SCRIPT_EXECUTION_TIMEOUT";
|
|
1000
|
+
}
|
|
1001
|
+
function guardedRun(fn, budget) {
|
|
1002
|
+
const run = getExec();
|
|
1003
|
+
if (!run || watched) return { completed: true, value: fn() };
|
|
1004
|
+
const remaining = Math.floor(budget.deadline - performance.now());
|
|
1005
|
+
if (remaining < 1) {
|
|
1006
|
+
budget.timedOut = true;
|
|
1007
|
+
return { completed: false };
|
|
1008
|
+
}
|
|
1009
|
+
watched = true;
|
|
1010
|
+
try {
|
|
1011
|
+
return { completed: true, value: run(fn, remaining) };
|
|
1012
|
+
} catch (err) {
|
|
1013
|
+
if (!isTimeout(err)) throw err;
|
|
1014
|
+
budget.timedOut = true;
|
|
1015
|
+
return { completed: false };
|
|
1016
|
+
} finally {
|
|
1017
|
+
watched = false;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
957
1021
|
// ../../packages/shared/src/scoring.ts
|
|
958
|
-
var MAX_REGEX_INPUT_CHARS =
|
|
1022
|
+
var MAX_REGEX_INPUT_CHARS = 2e4;
|
|
959
1023
|
function boundRegexInput(response) {
|
|
960
|
-
|
|
1024
|
+
if (response.length <= MAX_REGEX_INPUT_CHARS) return response;
|
|
1025
|
+
const half = Math.floor(MAX_REGEX_INPUT_CHARS / 2);
|
|
1026
|
+
return `${response.slice(0, half)}
|
|
1027
|
+
${response.slice(-half)}`;
|
|
961
1028
|
}
|
|
962
1029
|
function analyzeResponse(payload, rawResponse) {
|
|
963
1030
|
const response = boundRegexInput(rawResponse);
|
|
1031
|
+
const budget = regexBudget();
|
|
964
1032
|
let matchedPattern;
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
matchedPattern = pattern.source;
|
|
968
|
-
break;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
let matchedRefusalPattern;
|
|
972
|
-
if (payload.refusalPatterns) {
|
|
973
|
-
for (const pattern of payload.refusalPatterns) {
|
|
1033
|
+
guardedRun(() => {
|
|
1034
|
+
for (const pattern of payload.detectPatterns) {
|
|
974
1035
|
if (pattern.test(response)) {
|
|
975
|
-
|
|
1036
|
+
matchedPattern = pattern.source;
|
|
976
1037
|
break;
|
|
977
1038
|
}
|
|
978
1039
|
}
|
|
1040
|
+
}, budget);
|
|
1041
|
+
let matchedRefusalPattern;
|
|
1042
|
+
const refusals = payload.refusalPatterns;
|
|
1043
|
+
if (refusals) {
|
|
1044
|
+
guardedRun(() => {
|
|
1045
|
+
for (const pattern of refusals) {
|
|
1046
|
+
if (pattern.test(response)) {
|
|
1047
|
+
matchedRefusalPattern = pattern.source;
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}, budget);
|
|
979
1052
|
}
|
|
980
1053
|
const detectMatch = !!matchedPattern;
|
|
981
1054
|
const refusalDetected = !!matchedRefusalPattern;
|
|
1055
|
+
if (budget.timedOut) {
|
|
1056
|
+
console.warn(
|
|
1057
|
+
`[regex-guard] ${payload.id ?? "unknown attack"}: pattern budget exhausted on a ${response.length}-char response; the regex verdict is incomplete`
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
982
1060
|
return {
|
|
983
1061
|
vulnerable: detectMatch,
|
|
984
1062
|
matchedPattern,
|
|
985
1063
|
refusalDetected,
|
|
986
1064
|
matchedRefusalPattern,
|
|
987
|
-
hasConflict: detectMatch && refusalDetected
|
|
1065
|
+
hasConflict: detectMatch && refusalDetected,
|
|
1066
|
+
...budget.timedOut ? { timedOut: true } : {}
|
|
988
1067
|
};
|
|
989
1068
|
}
|
|
990
1069
|
function didNotExecute(attack) {
|
|
@@ -1084,14 +1163,17 @@ var RATE_LIMIT_PATTERNS = [
|
|
|
1084
1163
|
platform: "generic"
|
|
1085
1164
|
}
|
|
1086
1165
|
];
|
|
1166
|
+
var RATE_LIMIT_SCAN_CHARS = 8192;
|
|
1087
1167
|
function detectRateLimit(text) {
|
|
1088
1168
|
if (!text) return null;
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1169
|
+
const head = text.length > RATE_LIMIT_SCAN_CHARS ? text.slice(0, RATE_LIMIT_SCAN_CHARS) : text;
|
|
1170
|
+
const run = guardedRun(() => {
|
|
1171
|
+
for (const { pattern, platform } of RATE_LIMIT_PATTERNS) {
|
|
1172
|
+
if (pattern.test(head)) return platform;
|
|
1092
1173
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1174
|
+
return null;
|
|
1175
|
+
}, regexBudget());
|
|
1176
|
+
return run.completed ? run.value : null;
|
|
1095
1177
|
}
|
|
1096
1178
|
|
|
1097
1179
|
// ../../packages/shared/src/unicode.ts
|
|
@@ -7674,7 +7756,9 @@ function resolveClaim(input) {
|
|
|
7674
7756
|
notExecutedAttackIds: []
|
|
7675
7757
|
};
|
|
7676
7758
|
}
|
|
7677
|
-
const designOpen = c3.designAttackIds.filter(
|
|
7759
|
+
const designOpen = c3.designAttackIds.filter(
|
|
7760
|
+
(id) => verdicts.get(id) === true
|
|
7761
|
+
);
|
|
7678
7762
|
if (designOpen.length > 0) {
|
|
7679
7763
|
return {
|
|
7680
7764
|
status: "refuted_or_not_deployed",
|
|
@@ -7682,7 +7766,9 @@ function resolveClaim(input) {
|
|
|
7682
7766
|
notExecutedAttackIds: []
|
|
7683
7767
|
};
|
|
7684
7768
|
}
|
|
7685
|
-
const holdoutOpen = c3.holdoutAttackIds.filter(
|
|
7769
|
+
const holdoutOpen = c3.holdoutAttackIds.filter(
|
|
7770
|
+
(id) => verdicts.get(id) === true
|
|
7771
|
+
);
|
|
7686
7772
|
if (holdoutOpen.length > 0) {
|
|
7687
7773
|
return {
|
|
7688
7774
|
status: "confirmed_overfit",
|
|
@@ -7714,6 +7800,40 @@ function isExpired(claim, nowMs) {
|
|
|
7714
7800
|
function mayStampFixed(status) {
|
|
7715
7801
|
return status === "confirmed";
|
|
7716
7802
|
}
|
|
7803
|
+
var MAX_RECORDED_VERIFICATIONS = 20;
|
|
7804
|
+
function recordVerification(claim, input) {
|
|
7805
|
+
const result = (id) => {
|
|
7806
|
+
if (!input.verdicts.has(id)) return "not_executed";
|
|
7807
|
+
return input.verdicts.get(id) ? "still_vulnerable" : "closed";
|
|
7808
|
+
};
|
|
7809
|
+
const record = {
|
|
7810
|
+
verifiedAt: new Date(input.nowMs).toISOString(),
|
|
7811
|
+
trigger: input.trigger,
|
|
7812
|
+
status: input.outcome.status,
|
|
7813
|
+
reason: input.outcome.reason,
|
|
7814
|
+
attacks: [
|
|
7815
|
+
...claim.contract.designAttackIds.map((attackId) => ({
|
|
7816
|
+
attackId,
|
|
7817
|
+
role: "design",
|
|
7818
|
+
result: result(attackId)
|
|
7819
|
+
})),
|
|
7820
|
+
...claim.contract.holdoutAttackIds.map((attackId) => ({
|
|
7821
|
+
attackId,
|
|
7822
|
+
role: "holdout",
|
|
7823
|
+
result: result(attackId)
|
|
7824
|
+
}))
|
|
7825
|
+
],
|
|
7826
|
+
benign: { ...input.benign },
|
|
7827
|
+
judgeDegraded: input.judgeDegraded,
|
|
7828
|
+
sessionIsolated: input.sessionIsolated
|
|
7829
|
+
};
|
|
7830
|
+
return {
|
|
7831
|
+
...claim,
|
|
7832
|
+
verifications: [...claim.verifications ?? [], record].slice(
|
|
7833
|
+
-MAX_RECORDED_VERIFICATIONS
|
|
7834
|
+
)
|
|
7835
|
+
};
|
|
7836
|
+
}
|
|
7717
7837
|
|
|
7718
7838
|
// ../../packages/shared/src/remediation/index.ts
|
|
7719
7839
|
function remapRemediationRefs(remediation, version2) {
|
|
@@ -8599,6 +8719,56 @@ function checkSessionIsolation(target) {
|
|
|
8599
8719
|
};
|
|
8600
8720
|
}
|
|
8601
8721
|
|
|
8722
|
+
// ../../packages/scanner-core/src/provider-response.ts
|
|
8723
|
+
var GEMINI_FILTER_FINISH_REASONS = /* @__PURE__ */ new Set([
|
|
8724
|
+
"SAFETY",
|
|
8725
|
+
"RECITATION",
|
|
8726
|
+
"BLOCKLIST",
|
|
8727
|
+
"PROHIBITED_CONTENT",
|
|
8728
|
+
"SPII",
|
|
8729
|
+
"IMAGE_SAFETY"
|
|
8730
|
+
]);
|
|
8731
|
+
function at(obj, ...keys) {
|
|
8732
|
+
let current = obj;
|
|
8733
|
+
for (const key of keys) {
|
|
8734
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
8735
|
+
current = current[key];
|
|
8736
|
+
}
|
|
8737
|
+
return current;
|
|
8738
|
+
}
|
|
8739
|
+
function contentFilterReason(body) {
|
|
8740
|
+
const blockReason = at(body, "promptFeedback", "blockReason");
|
|
8741
|
+
if (typeof blockReason === "string" && blockReason !== "BLOCK_REASON_UNSPECIFIED") {
|
|
8742
|
+
return blockReason;
|
|
8743
|
+
}
|
|
8744
|
+
const finishReason = at(body, "candidates", 0, "finishReason");
|
|
8745
|
+
if (typeof finishReason === "string" && GEMINI_FILTER_FINISH_REASONS.has(finishReason)) {
|
|
8746
|
+
return finishReason;
|
|
8747
|
+
}
|
|
8748
|
+
if (at(body, "choices", 0, "finish_reason") === "content_filter") {
|
|
8749
|
+
return "content_filter";
|
|
8750
|
+
}
|
|
8751
|
+
return null;
|
|
8752
|
+
}
|
|
8753
|
+
function contentFilterRefusal(reason) {
|
|
8754
|
+
return `[No answer: the provider's content filter withheld the response (${reason})]`;
|
|
8755
|
+
}
|
|
8756
|
+
function nestAtPath(path2, value) {
|
|
8757
|
+
const segments = path2.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
8758
|
+
let nested = value;
|
|
8759
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
8760
|
+
const segment = segments[i];
|
|
8761
|
+
if (/^\d+$/.test(segment)) {
|
|
8762
|
+
const arr = [];
|
|
8763
|
+
arr[Number(segment)] = nested;
|
|
8764
|
+
nested = arr;
|
|
8765
|
+
} else {
|
|
8766
|
+
nested = { [segment]: nested };
|
|
8767
|
+
}
|
|
8768
|
+
}
|
|
8769
|
+
return Array.isArray(nested) ? { ...nested } : nested;
|
|
8770
|
+
}
|
|
8771
|
+
|
|
8602
8772
|
// ../../packages/scanner-core/src/http-sse.ts
|
|
8603
8773
|
var MAX_RESPONSE_BYTES = 50 * 1024 * 1024;
|
|
8604
8774
|
function extractSseChunk(parsed) {
|
|
@@ -8938,6 +9108,8 @@ var HttpTargetClient = class {
|
|
|
8938
9108
|
extractResponse(responseBody) {
|
|
8939
9109
|
const value = getByPath(responseBody, this.config.response.field);
|
|
8940
9110
|
if (value === void 0 || value === null) {
|
|
9111
|
+
const filtered = contentFilterReason(responseBody);
|
|
9112
|
+
if (filtered) return contentFilterRefusal(filtered);
|
|
8941
9113
|
const hint = responseBody && typeof responseBody === "object" ? `top-level keys: ${Object.keys(responseBody).slice(0, 8).join(", ")}` : `body type: ${typeof responseBody}`;
|
|
8942
9114
|
throw new HttpTargetError(
|
|
8943
9115
|
`Response field "${this.config.response.field}" not found (${hint})`,
|
|
@@ -9209,14 +9381,14 @@ async function fetchWithTimeout(url, init, timeoutMs, responseField, allowPrivat
|
|
|
9209
9381
|
const retryAfterSec = retryAfterFromHeader(
|
|
9210
9382
|
response.headers.get("retry-after")
|
|
9211
9383
|
);
|
|
9212
|
-
const body2 = await response
|
|
9384
|
+
const body2 = await readErrorBodyHead(response);
|
|
9213
9385
|
throw new RateLimitError(
|
|
9214
9386
|
`Rate limited (HTTP 429)${retryAfterSec ? ` \u2014 retry after ${retryAfterSec}s` : ""}${body2 ? `: ${body2.slice(0, 500)}` : ""}`,
|
|
9215
9387
|
retryAfterSec
|
|
9216
9388
|
);
|
|
9217
9389
|
}
|
|
9218
9390
|
if (!response.ok) {
|
|
9219
|
-
const body2 = await response
|
|
9391
|
+
const body2 = await readErrorBodyHead(response);
|
|
9220
9392
|
const throttle = detectRateLimit(body2);
|
|
9221
9393
|
if (throttle) {
|
|
9222
9394
|
throw new RateLimitError(
|
|
@@ -9232,13 +9404,11 @@ async function fetchWithTimeout(url, init, timeoutMs, responseField, allowPrivat
|
|
|
9232
9404
|
const contentType = response.headers.get("content-type") ?? "";
|
|
9233
9405
|
if (contentType.includes("text/event-stream")) {
|
|
9234
9406
|
const text = await collectSSE(response);
|
|
9235
|
-
|
|
9236
|
-
return { [field]: text };
|
|
9407
|
+
return nestAtPath(responseField ?? "response", text);
|
|
9237
9408
|
}
|
|
9238
9409
|
if (contentType.includes("ndjson")) {
|
|
9239
9410
|
const text = await collectNDJSON(response);
|
|
9240
|
-
|
|
9241
|
-
return { [field]: text };
|
|
9411
|
+
return nestAtPath(responseField ?? "response", text);
|
|
9242
9412
|
}
|
|
9243
9413
|
if (!contentType.includes("json")) {
|
|
9244
9414
|
const text = await readBodyWithLimit(response);
|
|
@@ -9260,6 +9430,34 @@ async function fetchWithTimeout(url, init, timeoutMs, responseField, allowPrivat
|
|
|
9260
9430
|
clearTimeout(timeout);
|
|
9261
9431
|
}
|
|
9262
9432
|
}
|
|
9433
|
+
var ERROR_BODY_HEAD_BYTES = 8192;
|
|
9434
|
+
async function readErrorBodyHead(response) {
|
|
9435
|
+
try {
|
|
9436
|
+
if (!response.body) {
|
|
9437
|
+
const text = typeof response.text === "function" ? await response.text() : "";
|
|
9438
|
+
return text.slice(0, ERROR_BODY_HEAD_BYTES);
|
|
9439
|
+
}
|
|
9440
|
+
const reader = response.body.getReader();
|
|
9441
|
+
const decoder = new TextDecoder();
|
|
9442
|
+
let result = "";
|
|
9443
|
+
let total = 0;
|
|
9444
|
+
try {
|
|
9445
|
+
while (total < ERROR_BODY_HEAD_BYTES) {
|
|
9446
|
+
const { done, value } = await reader.read();
|
|
9447
|
+
if (done) break;
|
|
9448
|
+
total += value.byteLength;
|
|
9449
|
+
result += decoder.decode(value, { stream: true });
|
|
9450
|
+
}
|
|
9451
|
+
} finally {
|
|
9452
|
+
await reader.cancel().catch(() => {
|
|
9453
|
+
});
|
|
9454
|
+
reader.releaseLock();
|
|
9455
|
+
}
|
|
9456
|
+
return result.slice(0, ERROR_BODY_HEAD_BYTES);
|
|
9457
|
+
} catch {
|
|
9458
|
+
return "";
|
|
9459
|
+
}
|
|
9460
|
+
}
|
|
9263
9461
|
async function readBodyWithLimit(response) {
|
|
9264
9462
|
const contentLength = response.headers.get("content-length");
|
|
9265
9463
|
if (contentLength) {
|
|
@@ -9708,18 +9906,18 @@ var Scanner = class {
|
|
|
9708
9906
|
mtProgress = false;
|
|
9709
9907
|
for (let k = 0; k < crescendoAttacks.length; k++) {
|
|
9710
9908
|
if (stop()) break;
|
|
9711
|
-
const
|
|
9712
|
-
const prior = results[
|
|
9909
|
+
const at2 = attacks.length + k;
|
|
9910
|
+
const prior = results[at2];
|
|
9713
9911
|
if (!prior || !prior.rateLimited || prior.error?.startsWith("Skipped")) {
|
|
9714
9912
|
continue;
|
|
9715
9913
|
}
|
|
9716
9914
|
if (this.currentDelayMs > 0) await sleep(this.currentDelayMs);
|
|
9717
9915
|
const retry = await this.executeMultiTurnAttack(crescendoAttacks[k]);
|
|
9718
|
-
results[
|
|
9916
|
+
results[at2] = retry;
|
|
9719
9917
|
await store?.record(retry);
|
|
9720
9918
|
if (retry.rateLimited) {
|
|
9721
9919
|
if (this.handleThrottle(
|
|
9722
|
-
|
|
9920
|
+
at2,
|
|
9723
9921
|
totalAttacks,
|
|
9724
9922
|
parseRetryAfterSec(retry.error)
|
|
9725
9923
|
)) {
|
|
@@ -9732,7 +9930,7 @@ var Scanner = class {
|
|
|
9732
9930
|
this.emit({
|
|
9733
9931
|
type: "attack:complete",
|
|
9734
9932
|
result: retry,
|
|
9735
|
-
index:
|
|
9933
|
+
index: at2,
|
|
9736
9934
|
total: totalAttacks
|
|
9737
9935
|
});
|
|
9738
9936
|
}
|
|
@@ -10201,7 +10399,10 @@ var Scanner = class {
|
|
|
10201
10399
|
// detect a degraded scan without parsing reasoning text.
|
|
10202
10400
|
...evalResult.llmResult.judgeError && {
|
|
10203
10401
|
judgeError: evalResult.llmResult.judgeError
|
|
10204
|
-
}
|
|
10402
|
+
},
|
|
10403
|
+
// The judge that produced this verdict: the scan's judgeVersion is
|
|
10404
|
+
// composed from these, and a checkpoint keeps it for a resumed scan.
|
|
10405
|
+
...evalResult.judgeId && { judgeId: evalResult.judgeId }
|
|
10205
10406
|
};
|
|
10206
10407
|
}
|
|
10207
10408
|
createSkippedResult(attack, reason, isRateLimited) {
|
|
@@ -10356,7 +10557,9 @@ var EndpointConfigSchema = z.object({
|
|
|
10356
10557
|
session: SessionConfigSchema.optional(),
|
|
10357
10558
|
// Known secret(s) / canary — server judge flags any response that surfaces
|
|
10358
10559
|
// one as a confirmed extraction. min(8) is a hard floor; prefer high-entropy.
|
|
10359
|
-
|
|
10560
|
+
// max(256) per secret: the canary floor matches each one (and five encodings)
|
|
10561
|
+
// against every response, so 20 unbounded secrets were a cost amplifier.
|
|
10562
|
+
knownSecrets: z.array(z.string().min(8).max(256)).max(20).optional()
|
|
10360
10563
|
});
|
|
10361
10564
|
var CustomTestSchema = z.object({
|
|
10362
10565
|
name: z.string().min(1),
|
|
@@ -13231,6 +13434,9 @@ function buildMessage(attack) {
|
|
|
13231
13434
|
|
|
13232
13435
|
export {
|
|
13233
13436
|
version,
|
|
13437
|
+
DORA_REGULATION_LABEL,
|
|
13438
|
+
DORA_PARAGRAPHS_VERIFIED_ON,
|
|
13439
|
+
DORA_PARAGRAPHS,
|
|
13234
13440
|
ATTACK_PACK_VERSION,
|
|
13235
13441
|
MUTATORS,
|
|
13236
13442
|
getMutator,
|
|
@@ -13258,6 +13464,7 @@ export {
|
|
|
13258
13464
|
resolveClaim,
|
|
13259
13465
|
isExpired,
|
|
13260
13466
|
mayStampFixed,
|
|
13467
|
+
recordVerification,
|
|
13261
13468
|
getStructuredRemediation,
|
|
13262
13469
|
CONSENT_SCOPES,
|
|
13263
13470
|
parseSegmentKey,
|
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,
|
|
@@ -55,6 +58,7 @@ import {
|
|
|
55
58
|
normalizeTargetUrl,
|
|
56
59
|
parseSegmentKey,
|
|
57
60
|
parseSnapshot,
|
|
61
|
+
recordVerification,
|
|
58
62
|
replaceLoneSurrogates,
|
|
59
63
|
resolveClaim,
|
|
60
64
|
resolveOfflinePosition,
|
|
@@ -63,7 +67,7 @@ import {
|
|
|
63
67
|
sha256Hex,
|
|
64
68
|
summarizeAttackErrors,
|
|
65
69
|
version
|
|
66
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-YAILR7N5.js";
|
|
67
71
|
|
|
68
72
|
// src/load-env.ts
|
|
69
73
|
try {
|
|
@@ -1356,7 +1360,9 @@ var BackendEvaluator = class {
|
|
|
1356
1360
|
}
|
|
1357
1361
|
throw new Error(userMessage);
|
|
1358
1362
|
}
|
|
1359
|
-
|
|
1363
|
+
const result = await response.json();
|
|
1364
|
+
const judgeId = result.meta?.judgeId;
|
|
1365
|
+
return typeof judgeId === "string" ? { ...result, judgeId } : result;
|
|
1360
1366
|
}
|
|
1361
1367
|
}
|
|
1362
1368
|
/** Backoff for one retry: a 429 Retry-After (seconds) when present, else
|
|
@@ -2054,16 +2060,84 @@ function safeHostname(url) {
|
|
|
2054
2060
|
}
|
|
2055
2061
|
|
|
2056
2062
|
// src/commands/scan.ts
|
|
2057
|
-
import { writeFileSync as
|
|
2063
|
+
import { writeFileSync as writeFileSync7 } from "fs";
|
|
2058
2064
|
import { resolve as resolve4 } from "path";
|
|
2059
2065
|
|
|
2060
2066
|
// src/reporters/evidence.ts
|
|
2061
|
-
import { writeFileSync as
|
|
2067
|
+
import { writeFileSync as writeFileSync6 } from "fs";
|
|
2062
2068
|
import { resolve as resolve3 } from "path";
|
|
2063
2069
|
|
|
2064
2070
|
// ../../packages/shared/src/compliance/evidence-bundle.ts
|
|
2065
2071
|
import { createHash } from "crypto";
|
|
2066
|
-
|
|
2072
|
+
|
|
2073
|
+
// ../../packages/shared/src/compliance/remediation-validation.ts
|
|
2074
|
+
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.";
|
|
2075
|
+
function toClaim(c2) {
|
|
2076
|
+
const live = c2.liveVerification;
|
|
2077
|
+
return {
|
|
2078
|
+
findingFingerprint: c2.findingFingerprint,
|
|
2079
|
+
recipeId: c2.recipeId,
|
|
2080
|
+
status: c2.status,
|
|
2081
|
+
createdAt: c2.createdAt,
|
|
2082
|
+
...c2.deployedAt ? { deployedAt: c2.deployedAt } : {},
|
|
2083
|
+
...c2.resolvedAt ? { resolvedAt: c2.resolvedAt } : {},
|
|
2084
|
+
...c2.closedBy ? { closedBy: c2.closedBy } : {},
|
|
2085
|
+
...c2.prUrl ? { prUrl: c2.prUrl } : {},
|
|
2086
|
+
...c2.benignBypassed ? { benignBypassed: true } : {},
|
|
2087
|
+
contract: {
|
|
2088
|
+
designAttackIds: [...c2.contract.designAttackIds],
|
|
2089
|
+
holdoutAttackIds: [...c2.contract.holdoutAttackIds],
|
|
2090
|
+
holdoutKind: c2.contract.holdoutKind
|
|
2091
|
+
},
|
|
2092
|
+
...live ? {
|
|
2093
|
+
fixTimeVerification: {
|
|
2094
|
+
verifiedAt: live.verifiedAt,
|
|
2095
|
+
designClearedIds: [...live.designClearedIds],
|
|
2096
|
+
holdoutClearedIds: [...live.holdoutClearedIds],
|
|
2097
|
+
notExecutedAttackIds: [...live.notExecutedAttackIds],
|
|
2098
|
+
benign: { ...live.benign },
|
|
2099
|
+
judgeDegraded: live.judgeDegraded,
|
|
2100
|
+
sessionIsolated: live.sessionIsolated,
|
|
2101
|
+
passed: live.passed
|
|
2102
|
+
}
|
|
2103
|
+
} : {},
|
|
2104
|
+
verifications: (c2.verifications ?? []).map((v) => ({
|
|
2105
|
+
...v,
|
|
2106
|
+
attacks: v.attacks.map((a) => ({ ...a })),
|
|
2107
|
+
benign: { ...v.benign }
|
|
2108
|
+
}))
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
function buildRemediationValidation(claims) {
|
|
2112
|
+
const paragraph = DORA_PARAGRAPHS["Art. 24(5)"];
|
|
2113
|
+
const count = (s) => claims.filter((c2) => c2.status === s).length;
|
|
2114
|
+
return {
|
|
2115
|
+
informative: INFORMATIVE,
|
|
2116
|
+
regulation: {
|
|
2117
|
+
label: DORA_REGULATION_LABEL,
|
|
2118
|
+
reference: "Art. 24(5)",
|
|
2119
|
+
text: { fr: paragraph.fr, en: paragraph.en },
|
|
2120
|
+
verifiedOn: DORA_PARAGRAPHS_VERIFIED_ON,
|
|
2121
|
+
source: "http://publications.europa.eu/resource/celex/32022R2554"
|
|
2122
|
+
},
|
|
2123
|
+
claims: claims.map(toClaim),
|
|
2124
|
+
summary: {
|
|
2125
|
+
total: claims.length,
|
|
2126
|
+
confirmed: count("confirmed"),
|
|
2127
|
+
confirmedOverfit: count("confirmed_overfit"),
|
|
2128
|
+
refutedOrNotDeployed: count("refuted_or_not_deployed"),
|
|
2129
|
+
pending: count("pending"),
|
|
2130
|
+
inconclusive: count("inconclusive"),
|
|
2131
|
+
expired: count("expired"),
|
|
2132
|
+
withVerificationEvidence: claims.filter(
|
|
2133
|
+
(c2) => (c2.verifications ?? []).length > 0
|
|
2134
|
+
).length
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// ../../packages/shared/src/compliance/evidence-bundle.ts
|
|
2140
|
+
var EVIDENCE_BUNDLE_FORMAT = "shield-evidence/3";
|
|
2067
2141
|
var EVIDENCE_EXCERPT_LIMIT = 2e3;
|
|
2068
2142
|
var EVIDENCE_TOTAL_EXCERPT_BUDGET = 1e6;
|
|
2069
2143
|
function canonicalize(value) {
|
|
@@ -2240,6 +2314,7 @@ function buildEvidenceBundle(input2) {
|
|
|
2240
2314
|
},
|
|
2241
2315
|
crosswalk: buildCrosswalkBlock(),
|
|
2242
2316
|
structuralAssessment: input2.assessment ?? null,
|
|
2317
|
+
remediationValidation: input2.claims ? buildRemediationValidation(input2.claims) : null,
|
|
2243
2318
|
tests: budgetedTests(input2.tests),
|
|
2244
2319
|
limitations: bundleLimitations(
|
|
2245
2320
|
classification,
|
|
@@ -2282,7 +2357,77 @@ function toComplianceOutcomes(attacks) {
|
|
|
2282
2357
|
}));
|
|
2283
2358
|
}
|
|
2284
2359
|
|
|
2360
|
+
// src/fix/claim-store.ts
|
|
2361
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync5 } from "fs";
|
|
2362
|
+
import { dirname, join as join2 } from "path";
|
|
2363
|
+
var DEFAULT_CLAIM_FILE = ".shield-llm/claims.json";
|
|
2364
|
+
var ClaimStore = class _ClaimStore {
|
|
2365
|
+
constructor(path) {
|
|
2366
|
+
this.path = path;
|
|
2367
|
+
}
|
|
2368
|
+
static at(root, file = DEFAULT_CLAIM_FILE) {
|
|
2369
|
+
return new _ClaimStore(join2(root, file));
|
|
2370
|
+
}
|
|
2371
|
+
load() {
|
|
2372
|
+
if (!existsSync3(this.path)) return null;
|
|
2373
|
+
return JSON.parse(readFileSync3(this.path, "utf8"));
|
|
2374
|
+
}
|
|
2375
|
+
list() {
|
|
2376
|
+
return this.load()?.claims ?? [];
|
|
2377
|
+
}
|
|
2378
|
+
/**
|
|
2379
|
+
* Claims a verification run should look at.
|
|
2380
|
+
*
|
|
2381
|
+
* `refuted_or_not_deployed` is included ON PURPOSE. That status means exactly
|
|
2382
|
+
* "still vulnerable, and we cannot tell whether the patch failed or was
|
|
2383
|
+
* simply not live yet" — so treating it as terminal would make the normal
|
|
2384
|
+
* sequence (patch → verify → deploy → verify again) impossible: the second
|
|
2385
|
+
* verification would find nothing to check. `inconclusive` is included for
|
|
2386
|
+
* the same reason: the family was not executed, so nothing was decided.
|
|
2387
|
+
*
|
|
2388
|
+
* Terminal, and therefore excluded: `confirmed`, `confirmed_overfit`,
|
|
2389
|
+
* `expired`.
|
|
2390
|
+
*/
|
|
2391
|
+
openForVerification() {
|
|
2392
|
+
return this.list().filter(
|
|
2393
|
+
(c2) => c2.status === "pending" || c2.status === "refuted_or_not_deployed" || c2.status === "inconclusive"
|
|
2394
|
+
);
|
|
2395
|
+
}
|
|
2396
|
+
pending() {
|
|
2397
|
+
return this.list().filter((c2) => c2.status === "pending");
|
|
2398
|
+
}
|
|
2399
|
+
/** Upsert by fingerprint+recipe: re-running `fix` refreshes, never duplicates. */
|
|
2400
|
+
upsert(targetId, claim) {
|
|
2401
|
+
const current = this.load() ?? { version: 1, targetId, claims: [] };
|
|
2402
|
+
const idx = current.claims.findIndex(
|
|
2403
|
+
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
2404
|
+
);
|
|
2405
|
+
if (idx === -1) current.claims.push(claim);
|
|
2406
|
+
else current.claims[idx] = claim;
|
|
2407
|
+
this.write({ ...current, targetId });
|
|
2408
|
+
}
|
|
2409
|
+
replace(claim) {
|
|
2410
|
+
const current = this.load();
|
|
2411
|
+
if (!current) return;
|
|
2412
|
+
const idx = current.claims.findIndex(
|
|
2413
|
+
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
2414
|
+
);
|
|
2415
|
+
if (idx !== -1) current.claims[idx] = claim;
|
|
2416
|
+
this.write(current);
|
|
2417
|
+
}
|
|
2418
|
+
write(file) {
|
|
2419
|
+
mkdirSync2(dirname(this.path), { recursive: true });
|
|
2420
|
+
writeFileSync5(this.path, `${JSON.stringify(file, null, 2)}
|
|
2421
|
+
`, "utf8");
|
|
2422
|
+
}
|
|
2423
|
+
};
|
|
2424
|
+
|
|
2285
2425
|
// src/reporters/evidence.ts
|
|
2426
|
+
function claimsForTarget(target, cwd) {
|
|
2427
|
+
const file = ClaimStore.at(cwd).load();
|
|
2428
|
+
if (!file) return void 0;
|
|
2429
|
+
return file.targetId === normalizeTargetUrl(target) ? file.claims : [];
|
|
2430
|
+
}
|
|
2286
2431
|
function writeEvidenceBundle(input2) {
|
|
2287
2432
|
const executed = scoredAttacks(input2.report.attacks);
|
|
2288
2433
|
const tests = executed.map((a) => ({
|
|
@@ -2300,6 +2445,7 @@ function writeEvidenceBundle(input2) {
|
|
|
2300
2445
|
prompt: a.prompt,
|
|
2301
2446
|
responseExcerpt: a.response
|
|
2302
2447
|
}));
|
|
2448
|
+
const claims = claimsForTarget(input2.report.target, input2.cwd ?? process.cwd());
|
|
2303
2449
|
const bundle = buildEvidenceBundle({
|
|
2304
2450
|
scan: {
|
|
2305
2451
|
scanId: input2.report.id,
|
|
@@ -2314,15 +2460,17 @@ function writeEvidenceBundle(input2) {
|
|
|
2314
2460
|
},
|
|
2315
2461
|
compliance: input2.compliance,
|
|
2316
2462
|
tests,
|
|
2463
|
+
claims,
|
|
2317
2464
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2318
2465
|
});
|
|
2319
2466
|
const outPath = resolve3(input2.path);
|
|
2320
2467
|
const json = JSON.stringify(bundle, null, 2);
|
|
2321
|
-
|
|
2468
|
+
writeFileSync6(outPath, json, "utf8");
|
|
2322
2469
|
return {
|
|
2323
2470
|
path: outPath,
|
|
2324
2471
|
sha256: bundle.manifest.sha256,
|
|
2325
|
-
bytes: Buffer.byteLength(json, "utf8")
|
|
2472
|
+
bytes: Buffer.byteLength(json, "utf8"),
|
|
2473
|
+
claims: claims ? claims.length : null
|
|
2326
2474
|
};
|
|
2327
2475
|
}
|
|
2328
2476
|
|
|
@@ -2381,9 +2529,33 @@ function alignOutputExtension(file, format) {
|
|
|
2381
2529
|
return { path, changed: path !== file };
|
|
2382
2530
|
}
|
|
2383
2531
|
|
|
2532
|
+
// src/lib/incomplete-scan.ts
|
|
2533
|
+
function incompleteScan(report, judged, total) {
|
|
2534
|
+
const resume = `Re-run the same command: the ${judged} judged attack(s) resume from the checkpoint.`;
|
|
2535
|
+
switch (report.stopReason) {
|
|
2536
|
+
case "auth":
|
|
2537
|
+
return {
|
|
2538
|
+
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.`,
|
|
2539
|
+
exitCode: 2
|
|
2540
|
+
};
|
|
2541
|
+
case "rate_limited":
|
|
2542
|
+
return {
|
|
2543
|
+
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}`,
|
|
2544
|
+
exitCode: 3
|
|
2545
|
+
};
|
|
2546
|
+
case "consecutive_failures":
|
|
2547
|
+
return {
|
|
2548
|
+
reason: `The scan stopped after repeated failed requests to the target, ${judged}/${total} attacks judged \u2014 the target is failing or unreachable. ${resume}`,
|
|
2549
|
+
exitCode: 3
|
|
2550
|
+
};
|
|
2551
|
+
default:
|
|
2552
|
+
return null;
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2384
2556
|
// src/commands/scan.ts
|
|
2385
|
-
|
|
2386
|
-
|
|
2557
|
+
function buildUploadVulnerabilities(attacks) {
|
|
2558
|
+
return scoredAttacks(attacks).map((a) => ({
|
|
2387
2559
|
// attackId lets the backend validate against its known catalogue + the
|
|
2388
2560
|
// user's custom tests, rejecting fabricated vulnerability rows.
|
|
2389
2561
|
attackId: a.id,
|
|
@@ -2401,10 +2573,16 @@ async function uploadReportToBackend(report, credentials, scanId, attackPackVers
|
|
|
2401
2573
|
}) : void 0,
|
|
2402
2574
|
status: a.vulnerable ? "DETECTED" : "PASSED",
|
|
2403
2575
|
evaluationMethod: a.llmEvaluation?.evaluationMethod,
|
|
2576
|
+
// The judge that produced this verdict (backend meta.judgeId): the server
|
|
2577
|
+
// composes the scan's judgeVersion from these instead of guessing.
|
|
2578
|
+
judgeId: a.llmEvaluation?.judgeId,
|
|
2404
2579
|
confidence: a.llmEvaluation?.confidence,
|
|
2405
2580
|
reasoning: a.llmEvaluation?.reasoning,
|
|
2406
2581
|
captureStatus: a.captureStatus ?? "captured"
|
|
2407
2582
|
}));
|
|
2583
|
+
}
|
|
2584
|
+
async function uploadReportToBackend(report, credentials, scanId, attackPackVersion) {
|
|
2585
|
+
const vulnerabilities = buildUploadVulnerabilities(report.attacks);
|
|
2408
2586
|
const testsRun = scoredAttacks(report.attacks).length;
|
|
2409
2587
|
const attackErrorSummary = summarizeAttackErrors(report.attacks);
|
|
2410
2588
|
const payload = {
|
|
@@ -2733,13 +2911,16 @@ async function scanCommand(opts) {
|
|
|
2733
2911
|
info("Scan started");
|
|
2734
2912
|
const scanner = new Scanner(scanOptions, onEvent);
|
|
2735
2913
|
const report = await scanner.run();
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2914
|
+
const incomplete = incompleteScan(
|
|
2915
|
+
report,
|
|
2916
|
+
scoredAttacks(report.attacks).length,
|
|
2917
|
+
report.attacks.length
|
|
2918
|
+
);
|
|
2919
|
+
if (incomplete) {
|
|
2920
|
+
await reportScanFailure(credentials, reservedScanId, incomplete.reason);
|
|
2740
2921
|
scanFinalized = true;
|
|
2741
|
-
console.error(`Scan stopped: ${reason}`);
|
|
2742
|
-
setExitCode(
|
|
2922
|
+
console.error(`Scan stopped: ${incomplete.reason}`);
|
|
2923
|
+
setExitCode(incomplete.exitCode);
|
|
2743
2924
|
return;
|
|
2744
2925
|
}
|
|
2745
2926
|
const attempted = report.attacks.length;
|
|
@@ -2846,6 +3027,7 @@ async function scanCommand(opts) {
|
|
|
2846
3027
|
"",
|
|
2847
3028
|
` Evidence bundle written to ${written.path}`,
|
|
2848
3029
|
` SHA-256: ${written.sha256}`,
|
|
3030
|
+
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.`,
|
|
2849
3031
|
" Contains raw target responses. It is a checksum, not a signature.",
|
|
2850
3032
|
""
|
|
2851
3033
|
].join("\n");
|
|
@@ -2874,7 +3056,7 @@ async function scanCommand(opts) {
|
|
|
2874
3056
|
if (format === "pdf") {
|
|
2875
3057
|
const pdfPath = outputFile ?? `shield-report-${report.id.slice(0, 8)}.pdf`;
|
|
2876
3058
|
const pdfBuffer = await generatePdf(report);
|
|
2877
|
-
|
|
3059
|
+
writeFileSync7(resolve4(pdfPath), pdfBuffer);
|
|
2878
3060
|
info(`PDF report written to ${pdfPath}`);
|
|
2879
3061
|
} else {
|
|
2880
3062
|
let content;
|
|
@@ -2896,7 +3078,7 @@ async function scanCommand(opts) {
|
|
|
2896
3078
|
break;
|
|
2897
3079
|
}
|
|
2898
3080
|
if (outputFile) {
|
|
2899
|
-
|
|
3081
|
+
writeFileSync7(resolve4(outputFile), content, "utf-8");
|
|
2900
3082
|
info(`Report written to ${outputFile}`);
|
|
2901
3083
|
} else {
|
|
2902
3084
|
console.log(content);
|
|
@@ -2912,7 +3094,7 @@ async function scanCommand(opts) {
|
|
|
2912
3094
|
thresholdsConfigured,
|
|
2913
3095
|
compliance: complianceResult
|
|
2914
3096
|
});
|
|
2915
|
-
|
|
3097
|
+
writeFileSync7(jsonPath, jsonContent, "utf-8");
|
|
2916
3098
|
info(
|
|
2917
3099
|
`JSON copy written to ${jsonPath}${opts.includeFullPayloads ? " (full payloads)" : " (sanitized)"}`
|
|
2918
3100
|
);
|
|
@@ -3244,7 +3426,7 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
3244
3426
|
import { resolve as resolve6 } from "path";
|
|
3245
3427
|
|
|
3246
3428
|
// src/fix/anchor-resolver.ts
|
|
3247
|
-
import { existsSync as
|
|
3429
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, statSync } from "fs";
|
|
3248
3430
|
import { isAbsolute, relative, resolve as resolve5, sep } from "path";
|
|
3249
3431
|
var AnchorError = class extends Error {
|
|
3250
3432
|
constructor(message, kind, status) {
|
|
@@ -3283,7 +3465,7 @@ function resolveAnchor(root, kind, anchor) {
|
|
|
3283
3465
|
return { kind, status: "anchor_missing", configHint };
|
|
3284
3466
|
}
|
|
3285
3467
|
const abs = safeResolve(root, anchor.file);
|
|
3286
|
-
if (!
|
|
3468
|
+
if (!existsSync4(abs) || !statSync(abs).isFile()) {
|
|
3287
3469
|
throw new AnchorError(
|
|
3288
3470
|
`${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.`,
|
|
3289
3471
|
kind,
|
|
@@ -3291,7 +3473,7 @@ function resolveAnchor(root, kind, anchor) {
|
|
|
3291
3473
|
);
|
|
3292
3474
|
}
|
|
3293
3475
|
if (anchor.export) {
|
|
3294
|
-
const source =
|
|
3476
|
+
const source = readFileSync4(abs, "utf8");
|
|
3295
3477
|
if (!declaresExport(source, anchor.export)) {
|
|
3296
3478
|
throw new AnchorError(
|
|
3297
3479
|
`${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.)`,
|
|
@@ -3491,8 +3673,8 @@ function blockedByAnchor(anchors) {
|
|
|
3491
3673
|
}
|
|
3492
3674
|
|
|
3493
3675
|
// src/fix/operations.ts
|
|
3494
|
-
import { existsSync as
|
|
3495
|
-
import { dirname, relative as relative2 } from "path";
|
|
3676
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, rmSync, writeFileSync as writeFileSync8 } from "fs";
|
|
3677
|
+
import { dirname as dirname2, relative as relative2 } from "path";
|
|
3496
3678
|
|
|
3497
3679
|
// src/fix/marker-block.ts
|
|
3498
3680
|
var EXT_STYLE = {
|
|
@@ -3659,7 +3841,7 @@ var WorkingSet = class {
|
|
|
3659
3841
|
const cached = this.files.get(relPath);
|
|
3660
3842
|
if (cached) return cached.current;
|
|
3661
3843
|
const abs = safeResolve(this.root, relPath);
|
|
3662
|
-
const before =
|
|
3844
|
+
const before = existsSync5(abs) ? readFileSync5(abs, "utf8") : "";
|
|
3663
3845
|
this.files.set(relPath, { before, current: before });
|
|
3664
3846
|
return before;
|
|
3665
3847
|
}
|
|
@@ -3679,11 +3861,11 @@ var WorkingSet = class {
|
|
|
3679
3861
|
if (before === current) continue;
|
|
3680
3862
|
const abs = safeResolve(this.root, path);
|
|
3681
3863
|
if (this.deleted.has(path)) {
|
|
3682
|
-
if (
|
|
3864
|
+
if (existsSync5(abs)) rmSync(abs);
|
|
3683
3865
|
continue;
|
|
3684
3866
|
}
|
|
3685
|
-
|
|
3686
|
-
|
|
3867
|
+
mkdirSync3(dirname2(abs), { recursive: true });
|
|
3868
|
+
writeFileSync8(abs, current, "utf8");
|
|
3687
3869
|
}
|
|
3688
3870
|
}
|
|
3689
3871
|
};
|
|
@@ -4067,71 +4249,6 @@ function renderPrBody(plan, live, withheld = [], rescan = []) {
|
|
|
4067
4249
|
return out.join("\n");
|
|
4068
4250
|
}
|
|
4069
4251
|
|
|
4070
|
-
// src/fix/claim-store.ts
|
|
4071
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync8 } from "fs";
|
|
4072
|
-
import { dirname as dirname2, join as join2 } from "path";
|
|
4073
|
-
var DEFAULT_CLAIM_FILE = ".shield-llm/claims.json";
|
|
4074
|
-
var ClaimStore = class _ClaimStore {
|
|
4075
|
-
constructor(path) {
|
|
4076
|
-
this.path = path;
|
|
4077
|
-
}
|
|
4078
|
-
static at(root, file = DEFAULT_CLAIM_FILE) {
|
|
4079
|
-
return new _ClaimStore(join2(root, file));
|
|
4080
|
-
}
|
|
4081
|
-
load() {
|
|
4082
|
-
if (!existsSync5(this.path)) return null;
|
|
4083
|
-
return JSON.parse(readFileSync5(this.path, "utf8"));
|
|
4084
|
-
}
|
|
4085
|
-
list() {
|
|
4086
|
-
return this.load()?.claims ?? [];
|
|
4087
|
-
}
|
|
4088
|
-
/**
|
|
4089
|
-
* Claims a verification run should look at.
|
|
4090
|
-
*
|
|
4091
|
-
* `refuted_or_not_deployed` is included ON PURPOSE. That status means exactly
|
|
4092
|
-
* "still vulnerable, and we cannot tell whether the patch failed or was
|
|
4093
|
-
* simply not live yet" — so treating it as terminal would make the normal
|
|
4094
|
-
* sequence (patch → verify → deploy → verify again) impossible: the second
|
|
4095
|
-
* verification would find nothing to check. `inconclusive` is included for
|
|
4096
|
-
* the same reason: the family was not executed, so nothing was decided.
|
|
4097
|
-
*
|
|
4098
|
-
* Terminal, and therefore excluded: `confirmed`, `confirmed_overfit`,
|
|
4099
|
-
* `expired`.
|
|
4100
|
-
*/
|
|
4101
|
-
openForVerification() {
|
|
4102
|
-
return this.list().filter(
|
|
4103
|
-
(c2) => c2.status === "pending" || c2.status === "refuted_or_not_deployed" || c2.status === "inconclusive"
|
|
4104
|
-
);
|
|
4105
|
-
}
|
|
4106
|
-
pending() {
|
|
4107
|
-
return this.list().filter((c2) => c2.status === "pending");
|
|
4108
|
-
}
|
|
4109
|
-
/** Upsert by fingerprint+recipe: re-running `fix` refreshes, never duplicates. */
|
|
4110
|
-
upsert(targetId, claim) {
|
|
4111
|
-
const current = this.load() ?? { version: 1, targetId, claims: [] };
|
|
4112
|
-
const idx = current.claims.findIndex(
|
|
4113
|
-
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
4114
|
-
);
|
|
4115
|
-
if (idx === -1) current.claims.push(claim);
|
|
4116
|
-
else current.claims[idx] = claim;
|
|
4117
|
-
this.write({ ...current, targetId });
|
|
4118
|
-
}
|
|
4119
|
-
replace(claim) {
|
|
4120
|
-
const current = this.load();
|
|
4121
|
-
if (!current) return;
|
|
4122
|
-
const idx = current.claims.findIndex(
|
|
4123
|
-
(c2) => c2.findingFingerprint === claim.findingFingerprint && c2.recipeId === claim.recipeId
|
|
4124
|
-
);
|
|
4125
|
-
if (idx !== -1) current.claims[idx] = claim;
|
|
4126
|
-
this.write(current);
|
|
4127
|
-
}
|
|
4128
|
-
write(file) {
|
|
4129
|
-
mkdirSync3(dirname2(this.path), { recursive: true });
|
|
4130
|
-
writeFileSync8(this.path, `${JSON.stringify(file, null, 2)}
|
|
4131
|
-
`, "utf8");
|
|
4132
|
-
}
|
|
4133
|
-
};
|
|
4134
|
-
|
|
4135
4252
|
// src/benign/runner.ts
|
|
4136
4253
|
async function captureBenign(target, cases, opts = {}) {
|
|
4137
4254
|
const client = createTargetClient(target, void 0, { resolveEnv: true });
|
|
@@ -5496,8 +5613,17 @@ async function verifyClaimsCommand(opts) {
|
|
|
5496
5613
|
trigger: "verify-claims",
|
|
5497
5614
|
nowMs: now
|
|
5498
5615
|
});
|
|
5616
|
+
const evidenced = recordVerification(claim, {
|
|
5617
|
+
verdicts,
|
|
5618
|
+
outcome,
|
|
5619
|
+
benign: { ran: benign.ran, green: benign.green, detail: benign.detail },
|
|
5620
|
+
judgeDegraded,
|
|
5621
|
+
sessionIsolated: checkSessionIsolation(target).isolated,
|
|
5622
|
+
trigger: "verify-claims",
|
|
5623
|
+
nowMs: now
|
|
5624
|
+
});
|
|
5499
5625
|
const updated = {
|
|
5500
|
-
...
|
|
5626
|
+
...evidenced,
|
|
5501
5627
|
status: outcome.status,
|
|
5502
5628
|
deployedAt: claim.deployedAt ?? opts.deployedAt ?? new Date(now).toISOString(),
|
|
5503
5629
|
// Only a TERMINAL status closes a claim. `refuted_or_not_deployed` and
|
|
@@ -5633,7 +5759,7 @@ program.command("scan").description("Run a security scan against a target chatbo
|
|
|
5633
5759
|
"Run ONLY custom tests \u2014 send no preset attack payloads to the target"
|
|
5634
5760
|
).option("--eu-ai-act", "Show EU AI Act compliance assessment after scan").option(
|
|
5635
5761
|
"--evidence-bundle <path>",
|
|
5636
|
-
"Write a checksummed
|
|
5762
|
+
"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"
|
|
5637
5763
|
).option(
|
|
5638
5764
|
"--compliance-threshold <n>",
|
|
5639
5765
|
"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.1",
|
|
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",
|