shield-llm 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-CWJWN44I.js → chunk-6AYERWP2.js} +227 -32
- package/dist/cli.js +49 -9
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,8 @@
|
|
|
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
|
+
// package.json
|
|
4
|
+
var version = "0.6.0";
|
|
5
|
+
|
|
3
6
|
// src/config/schema.ts
|
|
4
7
|
import { z as z2 } from "zod";
|
|
5
8
|
|
|
@@ -301,8 +304,12 @@ var RATE_LIMIT_PATTERNS = [
|
|
|
301
304
|
{ pattern: /vous avez atteint la limite de messages/i, platform: "ChatGPT" },
|
|
302
305
|
{ pattern: /you[''’]ve reached the? message limit/i, platform: "ChatGPT" },
|
|
303
306
|
{
|
|
304
|
-
|
|
305
|
-
|
|
307
|
+
// "Too many requests, please slow down." — the standard HTTP 429-style body,
|
|
308
|
+
// emitted by many backends (incl. WordPress chat plugins) sometimes with a
|
|
309
|
+
// NON-standard status like 500. The separator class includes the comma that
|
|
310
|
+
// the old /too many requests[.\s]*please/ form missed (the anao.io incident).
|
|
311
|
+
pattern: /\btoo many requests\b[\s,.:;-]*(please\s+)?(slow down|try again|retry|wait|come back|later)/i,
|
|
312
|
+
platform: "generic"
|
|
306
313
|
},
|
|
307
314
|
// Claude.ai (FR + EN)
|
|
308
315
|
{ pattern: /usage limit reached/i, platform: "Claude.ai" },
|
|
@@ -313,7 +320,12 @@ var RATE_LIMIT_PATTERNS = [
|
|
|
313
320
|
},
|
|
314
321
|
// Generic rate-limit banners (must include an action word to avoid false positives)
|
|
315
322
|
{
|
|
316
|
-
pattern: /\brate limit(ed)?\b.*\b(wait|try again|later|exceeded)\b/i,
|
|
323
|
+
pattern: /\brate limit(ed)?\b.*\b(wait|try again|later|exceeded|slow down|reached)\b/i,
|
|
324
|
+
platform: "generic"
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
// Quota / usage-cap exhaustion phrased without "rate limit".
|
|
328
|
+
pattern: /\b(quota|usage cap)\b.*\b(exceeded|reached|exhausted|hit)\b/i,
|
|
317
329
|
platform: "generic"
|
|
318
330
|
},
|
|
319
331
|
{
|
|
@@ -331,6 +343,21 @@ function detectRateLimit(text) {
|
|
|
331
343
|
return null;
|
|
332
344
|
}
|
|
333
345
|
|
|
346
|
+
// ../../packages/shared/src/unicode.ts
|
|
347
|
+
function replaceLoneSurrogates(input) {
|
|
348
|
+
return input.replace(/[\uD800-\uDFFF]/g, (ch, index, str) => {
|
|
349
|
+
const code = ch.charCodeAt(0);
|
|
350
|
+
if (code <= 56319) {
|
|
351
|
+
const next = str.charCodeAt(index + 1);
|
|
352
|
+
if (next >= 56320 && next <= 57343) return ch;
|
|
353
|
+
} else {
|
|
354
|
+
const prev = str.charCodeAt(index - 1);
|
|
355
|
+
if (prev >= 55296 && prev <= 56319) return ch;
|
|
356
|
+
}
|
|
357
|
+
return "\uFFFD";
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
334
361
|
// ../../packages/shared/src/attack-error.ts
|
|
335
362
|
var MAX_ATTACK_ERROR_ITEMS = 50;
|
|
336
363
|
function categorizeAttackError(error, rateLimited) {
|
|
@@ -5052,10 +5079,24 @@ function resolveEnvVar(value) {
|
|
|
5052
5079
|
}
|
|
5053
5080
|
|
|
5054
5081
|
// ../../packages/scanner-core/src/http-target-client.ts
|
|
5082
|
+
function sanitizeWireValue(value) {
|
|
5083
|
+
if (typeof value === "string") return replaceLoneSurrogates(value);
|
|
5084
|
+
if (Array.isArray(value)) return value.map(sanitizeWireValue);
|
|
5085
|
+
if (value && typeof value === "object") {
|
|
5086
|
+
return Object.fromEntries(
|
|
5087
|
+
Object.entries(value).map(([k, v]) => [
|
|
5088
|
+
k,
|
|
5089
|
+
sanitizeWireValue(v)
|
|
5090
|
+
])
|
|
5091
|
+
);
|
|
5092
|
+
}
|
|
5093
|
+
return value;
|
|
5094
|
+
}
|
|
5055
5095
|
function encodeRequestBody(body, encoding) {
|
|
5096
|
+
const safe = sanitizeWireValue(body);
|
|
5056
5097
|
if (encoding === "form") {
|
|
5057
5098
|
const params = new URLSearchParams();
|
|
5058
|
-
for (const [k, v] of Object.entries(
|
|
5099
|
+
for (const [k, v] of Object.entries(safe)) {
|
|
5059
5100
|
params.append(k, typeof v === "string" ? v : JSON.stringify(v));
|
|
5060
5101
|
}
|
|
5061
5102
|
return {
|
|
@@ -5065,12 +5106,12 @@ function encodeRequestBody(body, encoding) {
|
|
|
5065
5106
|
}
|
|
5066
5107
|
if (encoding === "multipart") {
|
|
5067
5108
|
const form = new FormData();
|
|
5068
|
-
for (const [k, v] of Object.entries(
|
|
5109
|
+
for (const [k, v] of Object.entries(safe)) {
|
|
5069
5110
|
form.append(k, typeof v === "string" ? v : JSON.stringify(v));
|
|
5070
5111
|
}
|
|
5071
5112
|
return { body: form, contentType: null };
|
|
5072
5113
|
}
|
|
5073
|
-
return { body: JSON.stringify(
|
|
5114
|
+
return { body: JSON.stringify(safe), contentType: "application/json" };
|
|
5074
5115
|
}
|
|
5075
5116
|
var PRIVATE_HOSTNAME_PATTERNS = [
|
|
5076
5117
|
/^localhost$/i,
|
|
@@ -5503,6 +5544,11 @@ async function resolveAuth(auth, timeoutMs = 3e4, allowPrivateUrls = false) {
|
|
|
5503
5544
|
return { type: "bearer", token: "" };
|
|
5504
5545
|
}
|
|
5505
5546
|
}
|
|
5547
|
+
function retryAfterFromHeader(value) {
|
|
5548
|
+
if (!value) return null;
|
|
5549
|
+
const sec = parseInt(value, 10);
|
|
5550
|
+
return Number.isNaN(sec) ? null : sec;
|
|
5551
|
+
}
|
|
5506
5552
|
async function fetchWithTimeout(url, init, timeoutMs, responseField, allowPrivateUrls = false) {
|
|
5507
5553
|
if (!allowPrivateUrls) {
|
|
5508
5554
|
await assertPublicHost(url);
|
|
@@ -5527,16 +5573,24 @@ async function fetchWithTimeout(url, init, timeoutMs, responseField, allowPrivat
|
|
|
5527
5573
|
);
|
|
5528
5574
|
}
|
|
5529
5575
|
if (response.status === 429) {
|
|
5530
|
-
const
|
|
5531
|
-
|
|
5576
|
+
const retryAfterSec = retryAfterFromHeader(
|
|
5577
|
+
response.headers.get("retry-after")
|
|
5578
|
+
);
|
|
5532
5579
|
const body2 = await response.text().catch(() => "");
|
|
5533
5580
|
throw new RateLimitError(
|
|
5534
5581
|
`Rate limited (HTTP 429)${retryAfterSec ? ` \u2014 retry after ${retryAfterSec}s` : ""}${body2 ? `: ${body2.slice(0, 500)}` : ""}`,
|
|
5535
|
-
|
|
5582
|
+
retryAfterSec
|
|
5536
5583
|
);
|
|
5537
5584
|
}
|
|
5538
5585
|
if (!response.ok) {
|
|
5539
5586
|
const body2 = await response.text().catch(() => "");
|
|
5587
|
+
const throttle = detectRateLimit(body2);
|
|
5588
|
+
if (throttle) {
|
|
5589
|
+
throw new RateLimitError(
|
|
5590
|
+
`Rate limited (soft, HTTP ${response.status} \u2014 ${throttle})${body2 ? `: ${body2.slice(0, 500)}` : ""}`,
|
|
5591
|
+
retryAfterFromHeader(response.headers.get("retry-after"))
|
|
5592
|
+
);
|
|
5593
|
+
}
|
|
5540
5594
|
throw new HttpTargetError(
|
|
5541
5595
|
`HTTP ${response.status} ${response.statusText}${body2 ? `: ${body2.slice(0, 500)}` : ""}`,
|
|
5542
5596
|
response.status
|
|
@@ -5762,6 +5816,13 @@ var Scanner = class {
|
|
|
5762
5816
|
this.aimdLimit = 1;
|
|
5763
5817
|
this.aimdSuccessStreak = 0;
|
|
5764
5818
|
this.inConcurrentPhase = false;
|
|
5819
|
+
// Adaptive-pacing state (the second AIMD lever — the inter-request delay).
|
|
5820
|
+
// `currentDelayMs` rises multiplicatively on a throttle and decays additively
|
|
5821
|
+
// on success; `throttleFloorStreak` counts throttles suffered while already at
|
|
5822
|
+
// the floor (concurrency 1 + maxDelayMs) to tell a transient slow-down apart
|
|
5823
|
+
// from a hard quota/ban. Both reset at the start of run().
|
|
5824
|
+
this.currentDelayMs = 0;
|
|
5825
|
+
this.throttleFloorStreak = 0;
|
|
5765
5826
|
this.targetClient = createTargetClient(
|
|
5766
5827
|
options.target,
|
|
5767
5828
|
options.systemPrompt
|
|
@@ -5781,7 +5842,9 @@ var Scanner = class {
|
|
|
5781
5842
|
includeCrescendo: options.includeCrescendo ?? false,
|
|
5782
5843
|
maxRateLimitRetries: options.maxRateLimitRetries ?? 3,
|
|
5783
5844
|
rateLimitBackoffMs: options.rateLimitBackoffMs ?? 1e3,
|
|
5784
|
-
rateLimitMaxBackoffMs: options.rateLimitMaxBackoffMs ?? 3e4
|
|
5845
|
+
rateLimitMaxBackoffMs: options.rateLimitMaxBackoffMs ?? 3e4,
|
|
5846
|
+
maxDelayMs: options.maxDelayMs ?? 5e3,
|
|
5847
|
+
maxFloorThrottles: options.maxFloorThrottles ?? 3
|
|
5785
5848
|
};
|
|
5786
5849
|
this.onEvent = onEvent;
|
|
5787
5850
|
}
|
|
@@ -5835,6 +5898,8 @@ var Scanner = class {
|
|
|
5835
5898
|
let consecutiveFailures = 0;
|
|
5836
5899
|
let attackIndex = 0;
|
|
5837
5900
|
let rateLimited = false;
|
|
5901
|
+
this.currentDelayMs = this.options.delayMs;
|
|
5902
|
+
this.throttleFloorStreak = 0;
|
|
5838
5903
|
const singleResults = new Array(
|
|
5839
5904
|
attacks.length
|
|
5840
5905
|
);
|
|
@@ -5885,23 +5950,23 @@ var Scanner = class {
|
|
|
5885
5950
|
total: totalAttacks
|
|
5886
5951
|
});
|
|
5887
5952
|
void (async () => {
|
|
5888
|
-
if (this.
|
|
5953
|
+
if (this.currentDelayMs > 0) await sleep(this.currentDelayMs);
|
|
5889
5954
|
const result = await this.executeSingleTurnAttack(attack);
|
|
5890
5955
|
singleResults[idx] = result;
|
|
5891
5956
|
await store?.record(result);
|
|
5892
5957
|
if (result.rateLimited) {
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
}
|
|
5958
|
+
if (this.handleThrottle(
|
|
5959
|
+
idx,
|
|
5960
|
+
totalAttacks,
|
|
5961
|
+
parseRetryAfterSec(result.error)
|
|
5962
|
+
)) {
|
|
5963
|
+
rateLimited = true;
|
|
5964
|
+
}
|
|
5900
5965
|
} else if (result.error) {
|
|
5901
5966
|
if (!result.payloadRejected) consecutiveFailures++;
|
|
5902
5967
|
} else {
|
|
5903
5968
|
consecutiveFailures = 0;
|
|
5904
|
-
this.
|
|
5969
|
+
this.handleSuccess();
|
|
5905
5970
|
}
|
|
5906
5971
|
this.emit({
|
|
5907
5972
|
type: "attack:complete",
|
|
@@ -5925,6 +5990,37 @@ var Scanner = class {
|
|
|
5925
5990
|
pump();
|
|
5926
5991
|
});
|
|
5927
5992
|
this.inConcurrentPhase = false;
|
|
5993
|
+
let madeProgress = !stop();
|
|
5994
|
+
while (madeProgress && !stop()) {
|
|
5995
|
+
madeProgress = false;
|
|
5996
|
+
for (let i = 0; i < attacks.length; i++) {
|
|
5997
|
+
if (stop()) break;
|
|
5998
|
+
const prior = singleResults[i];
|
|
5999
|
+
if (!prior || !prior.rateLimited) continue;
|
|
6000
|
+
if (this.currentDelayMs > 0) await sleep(this.currentDelayMs);
|
|
6001
|
+
const retry = await this.executeSingleTurnAttack(attacks[i]);
|
|
6002
|
+
singleResults[i] = retry;
|
|
6003
|
+
await store?.record(retry);
|
|
6004
|
+
if (retry.rateLimited) {
|
|
6005
|
+
if (this.handleThrottle(
|
|
6006
|
+
i,
|
|
6007
|
+
totalAttacks,
|
|
6008
|
+
parseRetryAfterSec(retry.error)
|
|
6009
|
+
)) {
|
|
6010
|
+
rateLimited = true;
|
|
6011
|
+
}
|
|
6012
|
+
} else {
|
|
6013
|
+
if (!retry.error) this.handleSuccess();
|
|
6014
|
+
madeProgress = true;
|
|
6015
|
+
}
|
|
6016
|
+
this.emit({
|
|
6017
|
+
type: "attack:complete",
|
|
6018
|
+
result: retry,
|
|
6019
|
+
index: i,
|
|
6020
|
+
total: totalAttacks
|
|
6021
|
+
});
|
|
6022
|
+
}
|
|
6023
|
+
}
|
|
5928
6024
|
for (let i = 0; i < attacks.length; i++) {
|
|
5929
6025
|
if (singleResults[i] === void 0) {
|
|
5930
6026
|
const skip = this.createSkippedResult(
|
|
@@ -5986,17 +6082,14 @@ var Scanner = class {
|
|
|
5986
6082
|
results.push(result);
|
|
5987
6083
|
await store?.record(result);
|
|
5988
6084
|
if (result.rateLimited) {
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
attackIndex,
|
|
5993
|
-
total: totalAttacks,
|
|
5994
|
-
retryAfterSec: null
|
|
5995
|
-
});
|
|
6085
|
+
if (this.handleThrottle(attackIndex, totalAttacks, null)) {
|
|
6086
|
+
rateLimited = true;
|
|
6087
|
+
}
|
|
5996
6088
|
} else if (result.error) {
|
|
5997
6089
|
if (!result.payloadRejected) consecutiveFailures++;
|
|
5998
6090
|
} else {
|
|
5999
6091
|
consecutiveFailures = 0;
|
|
6092
|
+
this.handleSuccess();
|
|
6000
6093
|
}
|
|
6001
6094
|
this.emit({
|
|
6002
6095
|
type: "attack:complete",
|
|
@@ -6005,8 +6098,42 @@ var Scanner = class {
|
|
|
6005
6098
|
total: totalAttacks
|
|
6006
6099
|
});
|
|
6007
6100
|
attackIndex++;
|
|
6008
|
-
if (attackIndex < totalAttacks && this.
|
|
6009
|
-
await sleep(this.
|
|
6101
|
+
if (attackIndex < totalAttacks && this.currentDelayMs > 0) {
|
|
6102
|
+
await sleep(this.currentDelayMs);
|
|
6103
|
+
}
|
|
6104
|
+
}
|
|
6105
|
+
let mtProgress = !stop();
|
|
6106
|
+
while (mtProgress && !stop()) {
|
|
6107
|
+
mtProgress = false;
|
|
6108
|
+
for (let k = 0; k < crescendoAttacks.length; k++) {
|
|
6109
|
+
if (stop()) break;
|
|
6110
|
+
const at = attacks.length + k;
|
|
6111
|
+
const prior = results[at];
|
|
6112
|
+
if (!prior || !prior.rateLimited || prior.error?.startsWith("Skipped")) {
|
|
6113
|
+
continue;
|
|
6114
|
+
}
|
|
6115
|
+
if (this.currentDelayMs > 0) await sleep(this.currentDelayMs);
|
|
6116
|
+
const retry = await this.executeMultiTurnAttack(crescendoAttacks[k]);
|
|
6117
|
+
results[at] = retry;
|
|
6118
|
+
await store?.record(retry);
|
|
6119
|
+
if (retry.rateLimited) {
|
|
6120
|
+
if (this.handleThrottle(
|
|
6121
|
+
at,
|
|
6122
|
+
totalAttacks,
|
|
6123
|
+
parseRetryAfterSec(retry.error)
|
|
6124
|
+
)) {
|
|
6125
|
+
rateLimited = true;
|
|
6126
|
+
}
|
|
6127
|
+
} else {
|
|
6128
|
+
if (!retry.error) this.handleSuccess();
|
|
6129
|
+
mtProgress = true;
|
|
6130
|
+
}
|
|
6131
|
+
this.emit({
|
|
6132
|
+
type: "attack:complete",
|
|
6133
|
+
result: retry,
|
|
6134
|
+
index: at,
|
|
6135
|
+
total: totalAttacks
|
|
6136
|
+
});
|
|
6010
6137
|
}
|
|
6011
6138
|
}
|
|
6012
6139
|
for (const customTest of customTests) {
|
|
@@ -6042,8 +6169,8 @@ var Scanner = class {
|
|
|
6042
6169
|
total: totalAttacks
|
|
6043
6170
|
});
|
|
6044
6171
|
attackIndex++;
|
|
6045
|
-
if (attackIndex < totalAttacks && this.
|
|
6046
|
-
await sleep(this.
|
|
6172
|
+
if (attackIndex < totalAttacks && this.currentDelayMs > 0) {
|
|
6173
|
+
await sleep(this.currentDelayMs);
|
|
6047
6174
|
}
|
|
6048
6175
|
}
|
|
6049
6176
|
const score = calculateScore(results);
|
|
@@ -6314,7 +6441,11 @@ var Scanner = class {
|
|
|
6314
6441
|
if (error instanceof RateLimitError && error.retryAfterSec != null && error.retryAfterSec > 0) {
|
|
6315
6442
|
return Math.min(error.retryAfterSec * 1e3, cap);
|
|
6316
6443
|
}
|
|
6317
|
-
|
|
6444
|
+
const window = Math.min(
|
|
6445
|
+
this.options.rateLimitBackoffMs * 2 ** attempt,
|
|
6446
|
+
cap
|
|
6447
|
+
);
|
|
6448
|
+
return Math.floor(Math.random() * window);
|
|
6318
6449
|
}
|
|
6319
6450
|
// ──────────────────────────────────────────────
|
|
6320
6451
|
// AIMD adaptive concurrency
|
|
@@ -6352,6 +6483,68 @@ var Scanner = class {
|
|
|
6352
6483
|
}
|
|
6353
6484
|
}
|
|
6354
6485
|
// ──────────────────────────────────────────────
|
|
6486
|
+
// Adaptive pacing (second AIMD lever — inter-request delay)
|
|
6487
|
+
// ──────────────────────────────────────────────
|
|
6488
|
+
/** Multiplicative increase of the inter-request delay on a throttle, capped
|
|
6489
|
+
* at maxDelayMs. Uses a 250ms floor so it still slows down when delayMs=0. */
|
|
6490
|
+
inflateDelay() {
|
|
6491
|
+
const base = Math.max(this.options.delayMs, 250);
|
|
6492
|
+
this.currentDelayMs = Math.min(
|
|
6493
|
+
this.options.maxDelayMs,
|
|
6494
|
+
Math.max(base, this.currentDelayMs * 2)
|
|
6495
|
+
);
|
|
6496
|
+
}
|
|
6497
|
+
/** Additive decrease of the delay on a clean success — slow reconvergence
|
|
6498
|
+
* toward the floor (delayMs) so we don't immediately re-trip the limiter. */
|
|
6499
|
+
decayDelay() {
|
|
6500
|
+
if (this.currentDelayMs <= this.options.delayMs) return;
|
|
6501
|
+
const step = Math.max(this.options.delayMs, 200);
|
|
6502
|
+
this.currentDelayMs = Math.max(
|
|
6503
|
+
this.options.delayMs,
|
|
6504
|
+
this.currentDelayMs - step
|
|
6505
|
+
);
|
|
6506
|
+
}
|
|
6507
|
+
/**
|
|
6508
|
+
* Process a throttle (a rate-limited result that survived the per-attack retry
|
|
6509
|
+
* budget). Back the pacer off — halve the concurrency cap AND inflate the
|
|
6510
|
+
* delay — and report whether the scan should HARD-STOP. It stops only when the
|
|
6511
|
+
* pacer is already at the floor (cap 1 + maxDelayMs) and STILL gets throttled
|
|
6512
|
+
* `maxFloorThrottles` times in a row: that is a hard quota/ban, not transient
|
|
6513
|
+
* congestion. Below the floor a throttle just slows the scan and it continues,
|
|
6514
|
+
* so a target that responds to backoff finishes the whole suite.
|
|
6515
|
+
*/
|
|
6516
|
+
handleThrottle(attackIndex, total, retryAfterSec) {
|
|
6517
|
+
this.aimdDecrease();
|
|
6518
|
+
this.inflateDelay();
|
|
6519
|
+
const atFloor = this.aimdLimit <= 1 && this.currentDelayMs >= this.options.maxDelayMs;
|
|
6520
|
+
if (atFloor) this.throttleFloorStreak++;
|
|
6521
|
+
const stop = this.throttleFloorStreak >= this.options.maxFloorThrottles;
|
|
6522
|
+
if (stop) {
|
|
6523
|
+
this.emit({
|
|
6524
|
+
type: "scan:rate_limited",
|
|
6525
|
+
attackIndex,
|
|
6526
|
+
total,
|
|
6527
|
+
retryAfterSec
|
|
6528
|
+
});
|
|
6529
|
+
} else {
|
|
6530
|
+
this.emit({
|
|
6531
|
+
type: "scan:throttled",
|
|
6532
|
+
attackIndex,
|
|
6533
|
+
total,
|
|
6534
|
+
delayMs: this.currentDelayMs,
|
|
6535
|
+
atFloor
|
|
6536
|
+
});
|
|
6537
|
+
}
|
|
6538
|
+
return stop;
|
|
6539
|
+
}
|
|
6540
|
+
/** A clean success: reset the at-floor streak and speed the pacer back up
|
|
6541
|
+
* (decay the delay, grow the concurrency cap). */
|
|
6542
|
+
handleSuccess() {
|
|
6543
|
+
this.throttleFloorStreak = 0;
|
|
6544
|
+
this.decayDelay();
|
|
6545
|
+
this.aimdIncrease();
|
|
6546
|
+
}
|
|
6547
|
+
// ──────────────────────────────────────────────
|
|
6355
6548
|
// Helpers
|
|
6356
6549
|
// ──────────────────────────────────────────────
|
|
6357
6550
|
buildEvaluation(evalResult) {
|
|
@@ -9052,7 +9245,7 @@ function formatSarif(report) {
|
|
|
9052
9245
|
tool: {
|
|
9053
9246
|
driver: {
|
|
9054
9247
|
name: "Shield LLM",
|
|
9055
|
-
version
|
|
9248
|
+
version,
|
|
9056
9249
|
informationUri: "https://shield-llm.com",
|
|
9057
9250
|
rules: vulnerableAttacks.map((a) => {
|
|
9058
9251
|
const structured = getStructuredRemediation(a.id);
|
|
@@ -9115,6 +9308,8 @@ function buildMessage(attack) {
|
|
|
9115
9308
|
}
|
|
9116
9309
|
|
|
9117
9310
|
export {
|
|
9311
|
+
version,
|
|
9312
|
+
replaceLoneSurrogates,
|
|
9118
9313
|
summarizeAttackErrors,
|
|
9119
9314
|
deserializeAttack,
|
|
9120
9315
|
deserializeMultiTurnAttack,
|
package/dist/cli.js
CHANGED
|
@@ -25,9 +25,11 @@ import {
|
|
|
25
25
|
loadSystemPrompt,
|
|
26
26
|
parseSegmentKey,
|
|
27
27
|
parseSnapshot,
|
|
28
|
+
replaceLoneSurrogates,
|
|
28
29
|
resolveOfflinePosition,
|
|
29
|
-
summarizeAttackErrors
|
|
30
|
-
|
|
30
|
+
summarizeAttackErrors,
|
|
31
|
+
version
|
|
32
|
+
} from "./chunk-6AYERWP2.js";
|
|
31
33
|
|
|
32
34
|
// src/load-env.ts
|
|
33
35
|
try {
|
|
@@ -38,9 +40,6 @@ try {
|
|
|
38
40
|
// src/cli.ts
|
|
39
41
|
import { Command, CommanderError } from "commander";
|
|
40
42
|
|
|
41
|
-
// package.json
|
|
42
|
-
var version = "0.5.3";
|
|
43
|
-
|
|
44
43
|
// src/credentials.ts
|
|
45
44
|
import {
|
|
46
45
|
readFileSync,
|
|
@@ -1229,10 +1228,11 @@ ${text.slice(-TAIL_CHARS)}`;
|
|
|
1229
1228
|
function truncateInput(input2) {
|
|
1230
1229
|
return {
|
|
1231
1230
|
...input2,
|
|
1232
|
-
|
|
1231
|
+
attackPrompt: replaceLoneSurrogates(input2.attackPrompt),
|
|
1232
|
+
response: replaceLoneSurrogates(truncateResponse(input2.response)),
|
|
1233
1233
|
turns: input2.turns?.map((t) => ({
|
|
1234
|
-
prompt: t.prompt,
|
|
1235
|
-
response: truncateResponse(t.response)
|
|
1234
|
+
prompt: replaceLoneSurrogates(t.prompt),
|
|
1235
|
+
response: replaceLoneSurrogates(truncateResponse(t.response))
|
|
1236
1236
|
}))
|
|
1237
1237
|
};
|
|
1238
1238
|
}
|
|
@@ -1461,6 +1461,11 @@ function handleEvent(event) {
|
|
|
1461
1461
|
`${currentAttackName} \u2014 ${event.reason === "rate_limited" ? "rate limited" : "server error"}, backing off ${(event.waitMs / 1e3).toFixed(1)}s (retry ${event.attempt}/${event.maxRetries})`
|
|
1462
1462
|
);
|
|
1463
1463
|
break;
|
|
1464
|
+
case "scan:throttled":
|
|
1465
|
+
spinner.text = c.yellow(
|
|
1466
|
+
`Target throttling \u2014 slowing to ${(event.delayMs / 1e3).toFixed(1)}s/req${event.atFloor ? " (at floor)" : ""}, continuing\u2026`
|
|
1467
|
+
);
|
|
1468
|
+
break;
|
|
1464
1469
|
case "scan:rate_limited":
|
|
1465
1470
|
spinner.fail(
|
|
1466
1471
|
c.red(
|
|
@@ -1489,6 +1494,17 @@ function printSummary(report, thresholds) {
|
|
|
1489
1494
|
console.log(
|
|
1490
1495
|
` ${c.red(`${vulnerable.length} vulnerable`)} \xB7 ${c.green(`${secure.length} secure`)} \xB7 ${c.yellow(`${errors.length} errors`)}`
|
|
1491
1496
|
);
|
|
1497
|
+
const evaluated = vulnerable.length + secure.length;
|
|
1498
|
+
const total = report.attacks.length;
|
|
1499
|
+
if (evaluated < total) {
|
|
1500
|
+
console.log(
|
|
1501
|
+
c.yellow(
|
|
1502
|
+
` Coverage: ${evaluated}/${total} evaluated \u2014 grade reflects only these; re-run to cover the ${total - evaluated} rate-limited/errored.`
|
|
1503
|
+
)
|
|
1504
|
+
);
|
|
1505
|
+
} else {
|
|
1506
|
+
console.log(` Coverage: ${evaluated}/${total} evaluated`);
|
|
1507
|
+
}
|
|
1492
1508
|
if (vulnerable.length > 0) {
|
|
1493
1509
|
console.log("");
|
|
1494
1510
|
console.log(c.redBold(" Vulnerabilities:"));
|
|
@@ -1997,6 +2013,21 @@ function sanitizeReportForDisk(report, opts = {}) {
|
|
|
1997
2013
|
};
|
|
1998
2014
|
}
|
|
1999
2015
|
|
|
2016
|
+
// src/lib/output-path.ts
|
|
2017
|
+
var FORMAT_EXTENSIONS = {
|
|
2018
|
+
json: ".json",
|
|
2019
|
+
markdown: ".md",
|
|
2020
|
+
sarif: ".sarif",
|
|
2021
|
+
pdf: ".pdf"
|
|
2022
|
+
};
|
|
2023
|
+
function alignOutputExtension(file, format) {
|
|
2024
|
+
const ext = FORMAT_EXTENSIONS[format];
|
|
2025
|
+
if (!ext) return { path: file, changed: false };
|
|
2026
|
+
if (file.toLowerCase().endsWith(ext)) return { path: file, changed: false };
|
|
2027
|
+
const path = file.replace(/\.[^./\\]+$/, "") + ext;
|
|
2028
|
+
return { path, changed: path !== file };
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2000
2031
|
// src/commands/scan.ts
|
|
2001
2032
|
async function uploadReportToBackend(report, credentials, scanId, attackPackVersion) {
|
|
2002
2033
|
const vulnerabilities = report.attacks.filter((a) => !a.error && !a.rateLimited).map((a) => ({
|
|
@@ -2366,7 +2397,16 @@ async function scanCommand(opts) {
|
|
|
2366
2397
|
}
|
|
2367
2398
|
}
|
|
2368
2399
|
const format = config.output?.format ?? opts.output;
|
|
2369
|
-
|
|
2400
|
+
let outputFile = config.output?.file ?? opts.outputFile;
|
|
2401
|
+
if (outputFile && format && opts.output && !opts.outputFile) {
|
|
2402
|
+
const aligned = alignOutputExtension(outputFile, format);
|
|
2403
|
+
if (aligned.changed) {
|
|
2404
|
+
info(
|
|
2405
|
+
`Output format is ${format}; writing to ${aligned.path} (config output.file was ${outputFile})`
|
|
2406
|
+
);
|
|
2407
|
+
outputFile = aligned.path;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2370
2410
|
if (format || outputFile) {
|
|
2371
2411
|
if (format === "pdf") {
|
|
2372
2412
|
const pdfPath = outputFile ?? `shield-report-${report.id.slice(0, 8)}.pdf`;
|
package/dist/index.js
CHANGED