shield-llm 0.6.9 → 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 +26 -0
- package/dist/{chunk-TWBU67PH.js → chunk-WGJYDA2Q.js} +238 -34
- package/dist/cli.js +209 -91
- 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.0";
|
|
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
|
}
|
|
@@ -10356,7 +10554,9 @@ var EndpointConfigSchema = z.object({
|
|
|
10356
10554
|
session: SessionConfigSchema.optional(),
|
|
10357
10555
|
// Known secret(s) / canary — server judge flags any response that surfaces
|
|
10358
10556
|
// one as a confirmed extraction. min(8) is a hard floor; prefer high-entropy.
|
|
10359
|
-
|
|
10557
|
+
// max(256) per secret: the canary floor matches each one (and five encodings)
|
|
10558
|
+
// against every response, so 20 unbounded secrets were a cost amplifier.
|
|
10559
|
+
knownSecrets: z.array(z.string().min(8).max(256)).max(20).optional()
|
|
10360
10560
|
});
|
|
10361
10561
|
var CustomTestSchema = z.object({
|
|
10362
10562
|
name: z.string().min(1),
|
|
@@ -13231,6 +13431,9 @@ function buildMessage(attack) {
|
|
|
13231
13431
|
|
|
13232
13432
|
export {
|
|
13233
13433
|
version,
|
|
13434
|
+
DORA_REGULATION_LABEL,
|
|
13435
|
+
DORA_PARAGRAPHS_VERIFIED_ON,
|
|
13436
|
+
DORA_PARAGRAPHS,
|
|
13234
13437
|
ATTACK_PACK_VERSION,
|
|
13235
13438
|
MUTATORS,
|
|
13236
13439
|
getMutator,
|
|
@@ -13258,6 +13461,7 @@ export {
|
|
|
13258
13461
|
resolveClaim,
|
|
13259
13462
|
isExpired,
|
|
13260
13463
|
mayStampFixed,
|
|
13464
|
+
recordVerification,
|
|
13261
13465
|
getStructuredRemediation,
|
|
13262
13466
|
CONSENT_SCOPES,
|
|
13263
13467
|
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-WGJYDA2Q.js";
|
|
67
71
|
|
|
68
72
|
// src/load-env.ts
|
|
69
73
|
try {
|
|
@@ -2054,16 +2058,84 @@ function safeHostname(url) {
|
|
|
2054
2058
|
}
|
|
2055
2059
|
|
|
2056
2060
|
// src/commands/scan.ts
|
|
2057
|
-
import { writeFileSync as
|
|
2061
|
+
import { writeFileSync as writeFileSync7 } from "fs";
|
|
2058
2062
|
import { resolve as resolve4 } from "path";
|
|
2059
2063
|
|
|
2060
2064
|
// src/reporters/evidence.ts
|
|
2061
|
-
import { writeFileSync as
|
|
2065
|
+
import { writeFileSync as writeFileSync6 } from "fs";
|
|
2062
2066
|
import { resolve as resolve3 } from "path";
|
|
2063
2067
|
|
|
2064
2068
|
// ../../packages/shared/src/compliance/evidence-bundle.ts
|
|
2065
2069
|
import { createHash } from "crypto";
|
|
2066
|
-
|
|
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";
|
|
2067
2139
|
var EVIDENCE_EXCERPT_LIMIT = 2e3;
|
|
2068
2140
|
var EVIDENCE_TOTAL_EXCERPT_BUDGET = 1e6;
|
|
2069
2141
|
function canonicalize(value) {
|
|
@@ -2240,6 +2312,7 @@ function buildEvidenceBundle(input2) {
|
|
|
2240
2312
|
},
|
|
2241
2313
|
crosswalk: buildCrosswalkBlock(),
|
|
2242
2314
|
structuralAssessment: input2.assessment ?? null,
|
|
2315
|
+
remediationValidation: input2.claims ? buildRemediationValidation(input2.claims) : null,
|
|
2243
2316
|
tests: budgetedTests(input2.tests),
|
|
2244
2317
|
limitations: bundleLimitations(
|
|
2245
2318
|
classification,
|
|
@@ -2282,7 +2355,77 @@ function toComplianceOutcomes(attacks) {
|
|
|
2282
2355
|
}));
|
|
2283
2356
|
}
|
|
2284
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
|
+
|
|
2285
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
|
+
}
|
|
2286
2429
|
function writeEvidenceBundle(input2) {
|
|
2287
2430
|
const executed = scoredAttacks(input2.report.attacks);
|
|
2288
2431
|
const tests = executed.map((a) => ({
|
|
@@ -2300,6 +2443,7 @@ function writeEvidenceBundle(input2) {
|
|
|
2300
2443
|
prompt: a.prompt,
|
|
2301
2444
|
responseExcerpt: a.response
|
|
2302
2445
|
}));
|
|
2446
|
+
const claims = claimsForTarget(input2.report.target, input2.cwd ?? process.cwd());
|
|
2303
2447
|
const bundle = buildEvidenceBundle({
|
|
2304
2448
|
scan: {
|
|
2305
2449
|
scanId: input2.report.id,
|
|
@@ -2314,15 +2458,17 @@ function writeEvidenceBundle(input2) {
|
|
|
2314
2458
|
},
|
|
2315
2459
|
compliance: input2.compliance,
|
|
2316
2460
|
tests,
|
|
2461
|
+
claims,
|
|
2317
2462
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2318
2463
|
});
|
|
2319
2464
|
const outPath = resolve3(input2.path);
|
|
2320
2465
|
const json = JSON.stringify(bundle, null, 2);
|
|
2321
|
-
|
|
2466
|
+
writeFileSync6(outPath, json, "utf8");
|
|
2322
2467
|
return {
|
|
2323
2468
|
path: outPath,
|
|
2324
2469
|
sha256: bundle.manifest.sha256,
|
|
2325
|
-
bytes: Buffer.byteLength(json, "utf8")
|
|
2470
|
+
bytes: Buffer.byteLength(json, "utf8"),
|
|
2471
|
+
claims: claims ? claims.length : null
|
|
2326
2472
|
};
|
|
2327
2473
|
}
|
|
2328
2474
|
|
|
@@ -2381,6 +2527,30 @@ function alignOutputExtension(file, format) {
|
|
|
2381
2527
|
return { path, changed: path !== file };
|
|
2382
2528
|
}
|
|
2383
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
|
+
|
|
2384
2554
|
// src/commands/scan.ts
|
|
2385
2555
|
async function uploadReportToBackend(report, credentials, scanId, attackPackVersion) {
|
|
2386
2556
|
const vulnerabilities = scoredAttacks(report.attacks).map((a) => ({
|
|
@@ -2733,13 +2903,16 @@ async function scanCommand(opts) {
|
|
|
2733
2903
|
info("Scan started");
|
|
2734
2904
|
const scanner = new Scanner(scanOptions, onEvent);
|
|
2735
2905
|
const report = await scanner.run();
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
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);
|
|
2740
2913
|
scanFinalized = true;
|
|
2741
|
-
console.error(`Scan stopped: ${reason}`);
|
|
2742
|
-
setExitCode(
|
|
2914
|
+
console.error(`Scan stopped: ${incomplete.reason}`);
|
|
2915
|
+
setExitCode(incomplete.exitCode);
|
|
2743
2916
|
return;
|
|
2744
2917
|
}
|
|
2745
2918
|
const attempted = report.attacks.length;
|
|
@@ -2846,6 +3019,7 @@ async function scanCommand(opts) {
|
|
|
2846
3019
|
"",
|
|
2847
3020
|
` Evidence bundle written to ${written.path}`,
|
|
2848
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.`,
|
|
2849
3023
|
" Contains raw target responses. It is a checksum, not a signature.",
|
|
2850
3024
|
""
|
|
2851
3025
|
].join("\n");
|
|
@@ -2874,7 +3048,7 @@ async function scanCommand(opts) {
|
|
|
2874
3048
|
if (format === "pdf") {
|
|
2875
3049
|
const pdfPath = outputFile ?? `shield-report-${report.id.slice(0, 8)}.pdf`;
|
|
2876
3050
|
const pdfBuffer = await generatePdf(report);
|
|
2877
|
-
|
|
3051
|
+
writeFileSync7(resolve4(pdfPath), pdfBuffer);
|
|
2878
3052
|
info(`PDF report written to ${pdfPath}`);
|
|
2879
3053
|
} else {
|
|
2880
3054
|
let content;
|
|
@@ -2896,7 +3070,7 @@ async function scanCommand(opts) {
|
|
|
2896
3070
|
break;
|
|
2897
3071
|
}
|
|
2898
3072
|
if (outputFile) {
|
|
2899
|
-
|
|
3073
|
+
writeFileSync7(resolve4(outputFile), content, "utf-8");
|
|
2900
3074
|
info(`Report written to ${outputFile}`);
|
|
2901
3075
|
} else {
|
|
2902
3076
|
console.log(content);
|
|
@@ -2912,7 +3086,7 @@ async function scanCommand(opts) {
|
|
|
2912
3086
|
thresholdsConfigured,
|
|
2913
3087
|
compliance: complianceResult
|
|
2914
3088
|
});
|
|
2915
|
-
|
|
3089
|
+
writeFileSync7(jsonPath, jsonContent, "utf-8");
|
|
2916
3090
|
info(
|
|
2917
3091
|
`JSON copy written to ${jsonPath}${opts.includeFullPayloads ? " (full payloads)" : " (sanitized)"}`
|
|
2918
3092
|
);
|
|
@@ -3244,7 +3418,7 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
3244
3418
|
import { resolve as resolve6 } from "path";
|
|
3245
3419
|
|
|
3246
3420
|
// src/fix/anchor-resolver.ts
|
|
3247
|
-
import { existsSync as
|
|
3421
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, statSync } from "fs";
|
|
3248
3422
|
import { isAbsolute, relative, resolve as resolve5, sep } from "path";
|
|
3249
3423
|
var AnchorError = class extends Error {
|
|
3250
3424
|
constructor(message, kind, status) {
|
|
@@ -3283,7 +3457,7 @@ function resolveAnchor(root, kind, anchor) {
|
|
|
3283
3457
|
return { kind, status: "anchor_missing", configHint };
|
|
3284
3458
|
}
|
|
3285
3459
|
const abs = safeResolve(root, anchor.file);
|
|
3286
|
-
if (!
|
|
3460
|
+
if (!existsSync4(abs) || !statSync(abs).isFile()) {
|
|
3287
3461
|
throw new AnchorError(
|
|
3288
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.`,
|
|
3289
3463
|
kind,
|
|
@@ -3291,7 +3465,7 @@ function resolveAnchor(root, kind, anchor) {
|
|
|
3291
3465
|
);
|
|
3292
3466
|
}
|
|
3293
3467
|
if (anchor.export) {
|
|
3294
|
-
const source =
|
|
3468
|
+
const source = readFileSync4(abs, "utf8");
|
|
3295
3469
|
if (!declaresExport(source, anchor.export)) {
|
|
3296
3470
|
throw new AnchorError(
|
|
3297
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.)`,
|
|
@@ -3491,8 +3665,8 @@ function blockedByAnchor(anchors) {
|
|
|
3491
3665
|
}
|
|
3492
3666
|
|
|
3493
3667
|
// src/fix/operations.ts
|
|
3494
|
-
import { existsSync as
|
|
3495
|
-
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";
|
|
3496
3670
|
|
|
3497
3671
|
// src/fix/marker-block.ts
|
|
3498
3672
|
var EXT_STYLE = {
|
|
@@ -3659,7 +3833,7 @@ var WorkingSet = class {
|
|
|
3659
3833
|
const cached = this.files.get(relPath);
|
|
3660
3834
|
if (cached) return cached.current;
|
|
3661
3835
|
const abs = safeResolve(this.root, relPath);
|
|
3662
|
-
const before =
|
|
3836
|
+
const before = existsSync5(abs) ? readFileSync5(abs, "utf8") : "";
|
|
3663
3837
|
this.files.set(relPath, { before, current: before });
|
|
3664
3838
|
return before;
|
|
3665
3839
|
}
|
|
@@ -3679,11 +3853,11 @@ var WorkingSet = class {
|
|
|
3679
3853
|
if (before === current) continue;
|
|
3680
3854
|
const abs = safeResolve(this.root, path);
|
|
3681
3855
|
if (this.deleted.has(path)) {
|
|
3682
|
-
if (
|
|
3856
|
+
if (existsSync5(abs)) rmSync(abs);
|
|
3683
3857
|
continue;
|
|
3684
3858
|
}
|
|
3685
|
-
|
|
3686
|
-
|
|
3859
|
+
mkdirSync3(dirname2(abs), { recursive: true });
|
|
3860
|
+
writeFileSync8(abs, current, "utf8");
|
|
3687
3861
|
}
|
|
3688
3862
|
}
|
|
3689
3863
|
};
|
|
@@ -4067,71 +4241,6 @@ function renderPrBody(plan, live, withheld = [], rescan = []) {
|
|
|
4067
4241
|
return out.join("\n");
|
|
4068
4242
|
}
|
|
4069
4243
|
|
|
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
4244
|
// src/benign/runner.ts
|
|
4136
4245
|
async function captureBenign(target, cases, opts = {}) {
|
|
4137
4246
|
const client = createTargetClient(target, void 0, { resolveEnv: true });
|
|
@@ -5496,8 +5605,17 @@ async function verifyClaimsCommand(opts) {
|
|
|
5496
5605
|
trigger: "verify-claims",
|
|
5497
5606
|
nowMs: now
|
|
5498
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
|
+
});
|
|
5499
5617
|
const updated = {
|
|
5500
|
-
...
|
|
5618
|
+
...evidenced,
|
|
5501
5619
|
status: outcome.status,
|
|
5502
5620
|
deployedAt: claim.deployedAt ?? opts.deployedAt ?? new Date(now).toISOString(),
|
|
5503
5621
|
// Only a TERMINAL status closes a claim. `refuted_or_not_deployed` and
|
|
@@ -5633,7 +5751,7 @@ program.command("scan").description("Run a security scan against a target chatbo
|
|
|
5633
5751
|
"Run ONLY custom tests \u2014 send no preset attack payloads to the target"
|
|
5634
5752
|
).option("--eu-ai-act", "Show EU AI Act compliance assessment after scan").option(
|
|
5635
5753
|
"--evidence-bundle <path>",
|
|
5636
|
-
"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"
|
|
5637
5755
|
).option(
|
|
5638
5756
|
"--compliance-threshold <n>",
|
|
5639
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",
|