shield-llm 0.6.8 → 0.6.9
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 +29 -2
- package/dist/{chunk-HQGV3UIF.js → chunk-TWBU67PH.js} +185 -50
- package/dist/cli.js +19 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,8 +79,29 @@ shield-llm scan --preset owasp
|
|
|
79
79
|
}
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
- `{{prompt}}` is replaced with each attack. `{{
|
|
83
|
-
|
|
82
|
+
- `{{prompt}}` is replaced with each attack. `{{sessionId}}` (URL, header or
|
|
83
|
+
body) gives each attack its own conversation on a stateful chatbot.
|
|
84
|
+
- **Multi-turn attacks need the target to see the conversation.** For a
|
|
85
|
+
stateless chat API, put `{{history}}` as an item of the message array, before
|
|
86
|
+
the current turn — it expands to the turns so far:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
"body": { "messages": ["{{history}}", { "role": "user", "content": "{{prompt}}" }] }
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Gemini / Vertex AI (`generateContent`) uses its own shape — add
|
|
93
|
+
`"historyFormat": "gemini"` to `request`:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
"request": {
|
|
97
|
+
"body": { "contents": ["{{history}}", { "role": "user", "parts": [{ "text": "{{prompt}}" }] }] },
|
|
98
|
+
"historyFormat": "gemini"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
With no `{{history}}`, no `{{sessionId}}` and no `"statefulConversation": true`,
|
|
103
|
+
multi-turn attacks are reported as **not run** (each turn would arrive as a
|
|
104
|
+
new conversation, so they could only ever "resist").
|
|
84
105
|
- `response.field` is a dot-path into the JSON response (e.g.
|
|
85
106
|
`choices[0].message.content`). SSE streams are auto-detected.
|
|
86
107
|
- Auth: `bearer`, `api-key`, or `oauth2` (use `$ENV_VAR` to read secrets from
|
|
@@ -257,6 +278,12 @@ Exit codes: `0` passed · `1` threshold violation · `2` config/auth error ·
|
|
|
257
278
|
`3` runtime/network error. Upload the SARIF to GitHub's Security tab, or use
|
|
258
279
|
`--write-json` to emit a parseable copy alongside any other format.
|
|
259
280
|
|
|
281
|
+
A target that answers `401` mid-scan (typically an access token that expired:
|
|
282
|
+
a Google Cloud token lasts about an hour) stops the scan with exit `2`. Nothing
|
|
283
|
+
is uploaded, the dashboard row is marked failed with the reason, and the
|
|
284
|
+
checkpoint is kept: refresh the token and re-run the same command to resume
|
|
285
|
+
where it stopped.
|
|
286
|
+
|
|
260
287
|
Run `verify-claims` from the deploy job itself, so a claim is re-proved against
|
|
261
288
|
what actually went live:
|
|
262
289
|
|
|
@@ -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.6.
|
|
4
|
+
var version = "0.6.9";
|
|
5
5
|
|
|
6
6
|
// src/config/schema.ts
|
|
7
7
|
import { z as z2 } from "zod";
|
|
@@ -8541,6 +8541,64 @@ async function assertPublicHost(url) {
|
|
|
8541
8541
|
};
|
|
8542
8542
|
}
|
|
8543
8543
|
|
|
8544
|
+
// ../../packages/scanner-core/src/session-isolation.ts
|
|
8545
|
+
var SESSION_PLACEHOLDER = /\{\{\s*(sessionId|threadId)\s*\}\}/;
|
|
8546
|
+
var PLACEHOLDER = SESSION_PLACEHOLDER;
|
|
8547
|
+
function containsPlaceholder(value) {
|
|
8548
|
+
if (typeof value === "string") return PLACEHOLDER.test(value);
|
|
8549
|
+
if (Array.isArray(value)) return value.some(containsPlaceholder);
|
|
8550
|
+
if (value && typeof value === "object") {
|
|
8551
|
+
return Object.values(value).some(
|
|
8552
|
+
containsPlaceholder
|
|
8553
|
+
);
|
|
8554
|
+
}
|
|
8555
|
+
return false;
|
|
8556
|
+
}
|
|
8557
|
+
function containsHistoryPlaceholder(value) {
|
|
8558
|
+
if (value === "{{history}}") return true;
|
|
8559
|
+
if (Array.isArray(value)) return value.some(containsHistoryPlaceholder);
|
|
8560
|
+
if (value && typeof value === "object") {
|
|
8561
|
+
return Object.values(value).some(
|
|
8562
|
+
containsHistoryPlaceholder
|
|
8563
|
+
);
|
|
8564
|
+
}
|
|
8565
|
+
return false;
|
|
8566
|
+
}
|
|
8567
|
+
function checkConversationContext(target) {
|
|
8568
|
+
const body = target.request?.body;
|
|
8569
|
+
if (containsHistoryPlaceholder(body)) {
|
|
8570
|
+
return { carried: true, via: "history", warning: "" };
|
|
8571
|
+
}
|
|
8572
|
+
if (checkSessionIsolation(target).isolated) {
|
|
8573
|
+
return { carried: true, via: "session", warning: "" };
|
|
8574
|
+
}
|
|
8575
|
+
if (target.statefulConversation) {
|
|
8576
|
+
return { carried: true, via: "stateful", warning: "" };
|
|
8577
|
+
}
|
|
8578
|
+
return {
|
|
8579
|
+
carried: false,
|
|
8580
|
+
warning: `Multi-turn attacks will NOT run: this config gives the target no way to see the conversation (no {{history}} in the body, no {{sessionId}}, not statefulConversation). Each turn would arrive as a new conversation, so a crescendo could only ever 'resist'.
|
|
8581
|
+
Stateless chat API \u2014 send the history before the current turn:
|
|
8582
|
+
"messages": ["{{history}}", { "role": "user", "content": "{{prompt}}" }]
|
|
8583
|
+
(Gemini / Vertex AI: "contents" with parts, and "historyFormat": "gemini")
|
|
8584
|
+
Stateful chatbot \u2014 add {{sessionId}} to the request, or set statefulConversation: true.`
|
|
8585
|
+
};
|
|
8586
|
+
}
|
|
8587
|
+
function checkSessionIsolation(target) {
|
|
8588
|
+
const req = target.request;
|
|
8589
|
+
if (containsPlaceholder(target.url))
|
|
8590
|
+
return { isolated: true, foundIn: "url", warning: "" };
|
|
8591
|
+
if (containsPlaceholder(req?.body))
|
|
8592
|
+
return { isolated: true, foundIn: "body", warning: "" };
|
|
8593
|
+
if (containsPlaceholder(req?.headers)) {
|
|
8594
|
+
return { isolated: true, foundIn: "headers", warning: "" };
|
|
8595
|
+
}
|
|
8596
|
+
return {
|
|
8597
|
+
isolated: false,
|
|
8598
|
+
warning: 'This scan sends no session identifier, so a target that keeps conversation state will handle every attack in ONE conversation: each verdict then depends on the attacks that ran before it, and on catalogue order.\n If your chatbot is stateful, add the placeholder to your request template:\n "body": { "message": "{{prompt}}", "sessionId": "{{sessionId}}" }\n (or a header / URL segment \u2014 anywhere in the template works). Stateless endpoints can ignore this.'
|
|
8599
|
+
};
|
|
8600
|
+
}
|
|
8601
|
+
|
|
8544
8602
|
// ../../packages/scanner-core/src/http-sse.ts
|
|
8545
8603
|
var MAX_RESPONSE_BYTES = 50 * 1024 * 1024;
|
|
8546
8604
|
function extractSseChunk(parsed) {
|
|
@@ -8830,14 +8888,30 @@ var HttpTargetClient = class {
|
|
|
8830
8888
|
}
|
|
8831
8889
|
// ── Internal (exposed for session classes) ──
|
|
8832
8890
|
async sendRaw(prompt, history, options) {
|
|
8891
|
+
try {
|
|
8892
|
+
return await this.sendRawOnce(prompt, history, options);
|
|
8893
|
+
} catch (error) {
|
|
8894
|
+
if (error instanceof HttpTargetError && error.statusCode === 401 && this.config.auth?.type === "oauth2") {
|
|
8895
|
+
this.resolvedAuth = null;
|
|
8896
|
+
return this.sendRawOnce(prompt, history, options);
|
|
8897
|
+
}
|
|
8898
|
+
throw error;
|
|
8899
|
+
}
|
|
8900
|
+
}
|
|
8901
|
+
async sendRawOnce(prompt, history, options) {
|
|
8833
8902
|
const auth = await this.getAuth();
|
|
8834
8903
|
const sessionId = options?.sessionId ?? randomUUID();
|
|
8835
8904
|
const body = renderTemplate(this.config.request.body, {
|
|
8836
8905
|
prompt,
|
|
8837
8906
|
history,
|
|
8838
|
-
sessionId
|
|
8907
|
+
sessionId,
|
|
8908
|
+
historyFormat: this.config.request.historyFormat
|
|
8839
8909
|
});
|
|
8910
|
+
const url = withSessionId(this.config.url, sessionId, encodeURIComponent);
|
|
8840
8911
|
const headers = this.buildHeaders(auth);
|
|
8912
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
8913
|
+
headers[name] = withSessionId(value, sessionId);
|
|
8914
|
+
}
|
|
8841
8915
|
const { body: encodedBody, contentType } = encodeRequestBody(
|
|
8842
8916
|
body,
|
|
8843
8917
|
this.config.request.encoding
|
|
@@ -8848,7 +8922,7 @@ var HttpTargetClient = class {
|
|
|
8848
8922
|
headers["Content-Type"] = contentType;
|
|
8849
8923
|
}
|
|
8850
8924
|
return fetchWithTimeout(
|
|
8851
|
-
|
|
8925
|
+
url,
|
|
8852
8926
|
{
|
|
8853
8927
|
method: this.config.request.method ?? "POST",
|
|
8854
8928
|
headers,
|
|
@@ -8968,31 +9042,55 @@ var StatelessHttpSession = class extends LazyAllocatedSession {
|
|
|
8968
9042
|
return text;
|
|
8969
9043
|
}
|
|
8970
9044
|
};
|
|
9045
|
+
function formatHistory(history, format = "openai") {
|
|
9046
|
+
if (format === "gemini") {
|
|
9047
|
+
return history.map((t) => ({
|
|
9048
|
+
role: t.role === "assistant" ? "model" : "user",
|
|
9049
|
+
parts: [{ text: t.content }]
|
|
9050
|
+
}));
|
|
9051
|
+
}
|
|
9052
|
+
return history;
|
|
9053
|
+
}
|
|
8971
9054
|
function renderTemplate(template, context) {
|
|
8972
9055
|
const sessionId = context.sessionId ?? randomUUID();
|
|
8973
9056
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
8974
9057
|
const nowUnix = Math.floor(Date.now() / 1e3).toString();
|
|
8975
9058
|
function substitute(value) {
|
|
8976
9059
|
if (value === "{{prompt}}") return context.prompt;
|
|
8977
|
-
if (value === "{{history}}")
|
|
8978
|
-
|
|
9060
|
+
if (value === "{{history}}") {
|
|
9061
|
+
return formatHistory(context.history, context.historyFormat);
|
|
9062
|
+
}
|
|
9063
|
+
if (WHOLE_SESSION_PLACEHOLDER.test(value)) return sessionId;
|
|
8979
9064
|
if (value === "{{now}}") return now;
|
|
8980
9065
|
if (value === "{{nowUnix}}") return nowUnix;
|
|
8981
9066
|
if (value === "{{uuid}}") return randomUUID();
|
|
8982
9067
|
if (!value.includes("{{")) return value;
|
|
8983
|
-
return
|
|
9068
|
+
return withSessionId(
|
|
9069
|
+
// Function replacer: a payload is data, never a `$&` / `$$` pattern.
|
|
9070
|
+
value.replace(/\{\{prompt\}\}/g, () => context.prompt),
|
|
9071
|
+
sessionId
|
|
9072
|
+
).replace(/\{\{now\}\}/g, now).replace(/\{\{nowUnix\}\}/g, nowUnix).replace(/\{\{uuid\}\}/g, () => randomUUID());
|
|
8984
9073
|
}
|
|
8985
9074
|
const result = {};
|
|
8986
9075
|
for (const [key, value] of Object.entries(template)) {
|
|
8987
9076
|
if (typeof value === "string") {
|
|
8988
9077
|
result[key] = substitute(value);
|
|
8989
9078
|
} else if (Array.isArray(value)) {
|
|
8990
|
-
result[key] = value.
|
|
8991
|
-
(item
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
|
|
8995
|
-
|
|
9079
|
+
result[key] = value.flatMap((item) => {
|
|
9080
|
+
if (item === "{{history}}") {
|
|
9081
|
+
return formatHistory(context.history, context.historyFormat);
|
|
9082
|
+
}
|
|
9083
|
+
if (typeof item === "string") return [substitute(item)];
|
|
9084
|
+
if (typeof item === "object" && item !== null) {
|
|
9085
|
+
return [
|
|
9086
|
+
renderTemplate(item, {
|
|
9087
|
+
...context,
|
|
9088
|
+
sessionId
|
|
9089
|
+
})
|
|
9090
|
+
];
|
|
9091
|
+
}
|
|
9092
|
+
return [item];
|
|
9093
|
+
});
|
|
8996
9094
|
} else if (typeof value === "object" && value !== null) {
|
|
8997
9095
|
result[key] = renderTemplate(value, {
|
|
8998
9096
|
...context,
|
|
@@ -9004,6 +9102,11 @@ function renderTemplate(template, context) {
|
|
|
9004
9102
|
}
|
|
9005
9103
|
return result;
|
|
9006
9104
|
}
|
|
9105
|
+
var SESSION_PLACEHOLDER_ALL = new RegExp(SESSION_PLACEHOLDER.source, "g");
|
|
9106
|
+
var WHOLE_SESSION_PLACEHOLDER = new RegExp(`^${SESSION_PLACEHOLDER.source}$`);
|
|
9107
|
+
function withSessionId(value, sessionId, encode = (s) => s) {
|
|
9108
|
+
return value.replace(SESSION_PLACEHOLDER_ALL, () => encode(sessionId));
|
|
9109
|
+
}
|
|
9007
9110
|
function getByPath(obj, path2) {
|
|
9008
9111
|
const segments = path2.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
9009
9112
|
let current = obj;
|
|
@@ -9379,6 +9482,8 @@ var Scanner = class {
|
|
|
9379
9482
|
let consecutiveFailures = 0;
|
|
9380
9483
|
let attackIndex = 0;
|
|
9381
9484
|
let rateLimited = false;
|
|
9485
|
+
let authFailed = false;
|
|
9486
|
+
let terminalSkip = false;
|
|
9382
9487
|
this.currentDelayMs = this.options.delayMs;
|
|
9383
9488
|
this.throttleFloorStreak = 0;
|
|
9384
9489
|
this.pauseUntil = 0;
|
|
@@ -9404,7 +9509,8 @@ var Scanner = class {
|
|
|
9404
9509
|
this.aimdLimit = this.aimdMax;
|
|
9405
9510
|
this.aimdSuccessStreak = 0;
|
|
9406
9511
|
this.inConcurrentPhase = true;
|
|
9407
|
-
const stop = () => rateLimited || consecutiveFailures >= this.options.maxConsecutiveFailures;
|
|
9512
|
+
const stop = () => rateLimited || authFailed || consecutiveFailures >= this.options.maxConsecutiveFailures;
|
|
9513
|
+
const skipReason = () => authFailed ? SKIP_AUTH : rateLimited ? "Skipped: target rate limited" : "Skipped: too many consecutive failures";
|
|
9408
9514
|
let nextPending = 0;
|
|
9409
9515
|
let active = 0;
|
|
9410
9516
|
await new Promise((resolve2, reject) => {
|
|
@@ -9445,7 +9551,8 @@ var Scanner = class {
|
|
|
9445
9551
|
rateLimited = true;
|
|
9446
9552
|
}
|
|
9447
9553
|
} else if (result.error) {
|
|
9448
|
-
if (
|
|
9554
|
+
if (result.authFailed) authFailed = true;
|
|
9555
|
+
else if (!result.payloadRejected) consecutiveFailures++;
|
|
9449
9556
|
} else {
|
|
9450
9557
|
consecutiveFailures = 0;
|
|
9451
9558
|
this.handleSuccess();
|
|
@@ -9505,10 +9612,11 @@ var Scanner = class {
|
|
|
9505
9612
|
}
|
|
9506
9613
|
for (let i = 0; i < attacks.length; i++) {
|
|
9507
9614
|
if (singleResults[i] === void 0) {
|
|
9615
|
+
terminalSkip = true;
|
|
9508
9616
|
const skip = this.createSkippedResult(
|
|
9509
9617
|
attacks[i],
|
|
9510
|
-
|
|
9511
|
-
rateLimited
|
|
9618
|
+
skipReason(),
|
|
9619
|
+
rateLimited && !authFailed
|
|
9512
9620
|
);
|
|
9513
9621
|
singleResults[i] = skip;
|
|
9514
9622
|
this.emit({
|
|
@@ -9521,6 +9629,7 @@ var Scanner = class {
|
|
|
9521
9629
|
}
|
|
9522
9630
|
for (const r of singleResults) results.push(r);
|
|
9523
9631
|
attackIndex = attacks.length;
|
|
9632
|
+
const conversation = checkConversationContext(this.options.target);
|
|
9524
9633
|
for (const crescendo of crescendoAttacks) {
|
|
9525
9634
|
const resumed = done.get(crescendo.id);
|
|
9526
9635
|
if (resumed) {
|
|
@@ -9534,8 +9643,10 @@ var Scanner = class {
|
|
|
9534
9643
|
attackIndex++;
|
|
9535
9644
|
continue;
|
|
9536
9645
|
}
|
|
9537
|
-
if (
|
|
9538
|
-
|
|
9646
|
+
if (stop() || !conversation.carried) {
|
|
9647
|
+
const terminal = stop();
|
|
9648
|
+
if (terminal) terminalSkip = true;
|
|
9649
|
+
const skip = {
|
|
9539
9650
|
id: crescendo.id,
|
|
9540
9651
|
name: crescendo.name,
|
|
9541
9652
|
severity: crescendo.severity,
|
|
@@ -9544,8 +9655,15 @@ var Scanner = class {
|
|
|
9544
9655
|
response: "",
|
|
9545
9656
|
multiTurn: true,
|
|
9546
9657
|
durationMs: 0,
|
|
9547
|
-
error:
|
|
9548
|
-
...rateLimited ? { rateLimited: true } : {}
|
|
9658
|
+
error: terminal ? skipReason() : SKIP_NO_CONVERSATION,
|
|
9659
|
+
...terminal && rateLimited && !authFailed ? { rateLimited: true } : {}
|
|
9660
|
+
};
|
|
9661
|
+
results.push(skip);
|
|
9662
|
+
this.emit({
|
|
9663
|
+
type: "attack:complete",
|
|
9664
|
+
result: skip,
|
|
9665
|
+
index: attackIndex,
|
|
9666
|
+
total: totalAttacks
|
|
9549
9667
|
});
|
|
9550
9668
|
attackIndex++;
|
|
9551
9669
|
continue;
|
|
@@ -9568,7 +9686,8 @@ var Scanner = class {
|
|
|
9568
9686
|
rateLimited = true;
|
|
9569
9687
|
}
|
|
9570
9688
|
} else if (result.error) {
|
|
9571
|
-
if (
|
|
9689
|
+
if (result.authFailed) authFailed = true;
|
|
9690
|
+
else if (!result.payloadRejected) consecutiveFailures++;
|
|
9572
9691
|
} else {
|
|
9573
9692
|
consecutiveFailures = 0;
|
|
9574
9693
|
this.handleSuccess();
|
|
@@ -9631,6 +9750,27 @@ var Scanner = class {
|
|
|
9631
9750
|
attackIndex++;
|
|
9632
9751
|
continue;
|
|
9633
9752
|
}
|
|
9753
|
+
if (authFailed) {
|
|
9754
|
+
const skip = {
|
|
9755
|
+
id: `custom_${customTest.name}`,
|
|
9756
|
+
name: customTest.name,
|
|
9757
|
+
severity: "HIGH",
|
|
9758
|
+
vulnerable: false,
|
|
9759
|
+
prompt: customTest.prompt,
|
|
9760
|
+
response: "",
|
|
9761
|
+
durationMs: 0,
|
|
9762
|
+
error: SKIP_AUTH
|
|
9763
|
+
};
|
|
9764
|
+
results.push(skip);
|
|
9765
|
+
this.emit({
|
|
9766
|
+
type: "attack:complete",
|
|
9767
|
+
result: skip,
|
|
9768
|
+
index: attackIndex,
|
|
9769
|
+
total: totalAttacks
|
|
9770
|
+
});
|
|
9771
|
+
attackIndex++;
|
|
9772
|
+
continue;
|
|
9773
|
+
}
|
|
9634
9774
|
this.emit({
|
|
9635
9775
|
type: "attack:start",
|
|
9636
9776
|
attack: {
|
|
@@ -9644,6 +9784,7 @@ var Scanner = class {
|
|
|
9644
9784
|
const result = await this.executeCustomTest(customTest);
|
|
9645
9785
|
results.push(result);
|
|
9646
9786
|
await store?.record(result);
|
|
9787
|
+
if (result.authFailed) authFailed = true;
|
|
9647
9788
|
this.emit({
|
|
9648
9789
|
type: "attack:complete",
|
|
9649
9790
|
result,
|
|
@@ -9673,6 +9814,11 @@ var Scanner = class {
|
|
|
9673
9814
|
customTests: customTests.length
|
|
9674
9815
|
}
|
|
9675
9816
|
};
|
|
9817
|
+
if (authFailed) {
|
|
9818
|
+
report.stopReason = "auth";
|
|
9819
|
+
} else if (terminalSkip) {
|
|
9820
|
+
report.stopReason = rateLimited ? "rate_limited" : "consecutive_failures";
|
|
9821
|
+
}
|
|
9676
9822
|
this.emit({ type: "scan:complete", report });
|
|
9677
9823
|
return report;
|
|
9678
9824
|
}
|
|
@@ -9734,7 +9880,8 @@ var Scanner = class {
|
|
|
9734
9880
|
durationMs: Date.now() - startTime,
|
|
9735
9881
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
9736
9882
|
...isRateLimit ? { rateLimited: true } : {},
|
|
9737
|
-
...isPayloadRejection(error) ? { payloadRejected: true } : {}
|
|
9883
|
+
...isPayloadRejection(error) ? { payloadRejected: true } : {},
|
|
9884
|
+
...isAuthFailure(error) ? { authFailed: true } : {}
|
|
9738
9885
|
};
|
|
9739
9886
|
} finally {
|
|
9740
9887
|
await session.dispose?.();
|
|
@@ -9817,7 +9964,8 @@ var Scanner = class {
|
|
|
9817
9964
|
durationMs: Date.now() - startTime,
|
|
9818
9965
|
error: errorMsg,
|
|
9819
9966
|
...isRateLimit ? { rateLimited: true } : {},
|
|
9820
|
-
...isPayloadRejection(error) ? { payloadRejected: true } : {}
|
|
9967
|
+
...isPayloadRejection(error) ? { payloadRejected: true } : {},
|
|
9968
|
+
...isAuthFailure(error) ? { authFailed: true } : {}
|
|
9821
9969
|
};
|
|
9822
9970
|
} finally {
|
|
9823
9971
|
await session.dispose?.();
|
|
@@ -9868,7 +10016,8 @@ var Scanner = class {
|
|
|
9868
10016
|
prompt: test.prompt,
|
|
9869
10017
|
response: "",
|
|
9870
10018
|
durationMs: Date.now() - startTime,
|
|
9871
|
-
error: errorMsg
|
|
10019
|
+
error: errorMsg,
|
|
10020
|
+
...isAuthFailure(error) ? { authFailed: true } : {}
|
|
9872
10021
|
};
|
|
9873
10022
|
} finally {
|
|
9874
10023
|
await session.dispose?.();
|
|
@@ -10081,8 +10230,13 @@ function isRetryable(error) {
|
|
|
10081
10230
|
return false;
|
|
10082
10231
|
}
|
|
10083
10232
|
function isPayloadRejection(error) {
|
|
10084
|
-
return error instanceof HttpTargetError && !(error instanceof RateLimitError) && error.statusCode >= 400 && error.statusCode < 500;
|
|
10233
|
+
return error instanceof HttpTargetError && !(error instanceof RateLimitError) && !isAuthFailure(error) && error.statusCode >= 400 && error.statusCode < 500;
|
|
10234
|
+
}
|
|
10235
|
+
function isAuthFailure(error) {
|
|
10236
|
+
return error instanceof HttpTargetError && error.statusCode === 401;
|
|
10085
10237
|
}
|
|
10238
|
+
var SKIP_AUTH = "Skipped: the target rejected the scan's credentials (HTTP 401)";
|
|
10239
|
+
var SKIP_NO_CONVERSATION = "Skipped: the target config carries no conversation context \u2014 multi-turn not run (add {{history}} to the body, a {{sessionId}}, or statefulConversation: true)";
|
|
10086
10240
|
function sleep(ms) {
|
|
10087
10241
|
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
10088
10242
|
}
|
|
@@ -10130,29 +10284,6 @@ var RegexOnlyEvaluator = class {
|
|
|
10130
10284
|
}
|
|
10131
10285
|
};
|
|
10132
10286
|
|
|
10133
|
-
// ../../packages/scanner-core/src/session-isolation.ts
|
|
10134
|
-
var PLACEHOLDER = /\{\{\s*(sessionId|threadId)\s*\}\}/;
|
|
10135
|
-
function containsPlaceholder(value) {
|
|
10136
|
-
if (typeof value === "string") return PLACEHOLDER.test(value);
|
|
10137
|
-
if (Array.isArray(value)) return value.some(containsPlaceholder);
|
|
10138
|
-
if (value && typeof value === "object") {
|
|
10139
|
-
return Object.values(value).some(containsPlaceholder);
|
|
10140
|
-
}
|
|
10141
|
-
return false;
|
|
10142
|
-
}
|
|
10143
|
-
function checkSessionIsolation(target) {
|
|
10144
|
-
const req = target.request;
|
|
10145
|
-
if (containsPlaceholder(target.url)) return { isolated: true, foundIn: "url", warning: "" };
|
|
10146
|
-
if (containsPlaceholder(req?.body)) return { isolated: true, foundIn: "body", warning: "" };
|
|
10147
|
-
if (containsPlaceholder(req?.headers)) {
|
|
10148
|
-
return { isolated: true, foundIn: "headers", warning: "" };
|
|
10149
|
-
}
|
|
10150
|
-
return {
|
|
10151
|
-
isolated: false,
|
|
10152
|
-
warning: 'This scan sends no session identifier, so a target that keeps conversation state will handle every attack in ONE conversation: each verdict then depends on the attacks that ran before it, and on catalogue order.\n If your chatbot is stateful, add the placeholder to your request template:\n "body": { "message": "{{prompt}}", "sessionId": "{{sessionId}}" }\n (or a header / URL segment \u2014 anywhere in the template works). Stateless endpoints can ignore this.'
|
|
10153
|
-
};
|
|
10154
|
-
}
|
|
10155
|
-
|
|
10156
10287
|
// ../../packages/scanner-core/src/schemas.ts
|
|
10157
10288
|
import { z } from "zod";
|
|
10158
10289
|
var AuthConfigSchema = z.discriminatedUnion("type", [
|
|
@@ -10182,7 +10313,10 @@ var RequestTemplateSchema = z.object({
|
|
|
10182
10313
|
// application/json). "form" = application/x-www-form-urlencoded, "multipart"
|
|
10183
10314
|
// = multipart/form-data (Content-Type is left to fetch so the boundary is
|
|
10184
10315
|
// set). Real chatbots often expect form encodings (e.g. FastAPI `Form(...)`).
|
|
10185
|
-
encoding: z.enum(["json", "form", "multipart"]).optional()
|
|
10316
|
+
encoding: z.enum(["json", "form", "multipart"]).optional(),
|
|
10317
|
+
// Shape of each {{history}} turn: OpenAI-style {role, content} (default) or
|
|
10318
|
+
// Gemini {role: user|model, parts: [{text}]} for generateContent / Vertex AI.
|
|
10319
|
+
historyFormat: z.enum(["openai", "gemini"]).optional()
|
|
10186
10320
|
});
|
|
10187
10321
|
var ResponseTemplateSchema = z.object({
|
|
10188
10322
|
field: z.string().min(1),
|
|
@@ -13137,13 +13271,14 @@ export {
|
|
|
13137
13271
|
BENIGN_SUITE_ID,
|
|
13138
13272
|
BENIGN_CORE_V1,
|
|
13139
13273
|
evaluateBenign,
|
|
13274
|
+
checkConversationContext,
|
|
13275
|
+
checkSessionIsolation,
|
|
13140
13276
|
createTargetClient,
|
|
13141
13277
|
computeCatalogHash,
|
|
13142
13278
|
computeScanKey,
|
|
13143
13279
|
FileCheckpointStore,
|
|
13144
13280
|
Scanner,
|
|
13145
13281
|
RegexOnlyEvaluator,
|
|
13146
|
-
checkSessionIsolation,
|
|
13147
13282
|
ConfigSchema,
|
|
13148
13283
|
loadConfig,
|
|
13149
13284
|
buildTargetConfig,
|
package/dist/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
buildTargetConfig,
|
|
25
25
|
c,
|
|
26
26
|
calculateComplianceScore,
|
|
27
|
+
checkConversationContext,
|
|
27
28
|
checkSessionIsolation,
|
|
28
29
|
computeCatalogHash,
|
|
29
30
|
computeScanKey,
|
|
@@ -62,7 +63,7 @@ import {
|
|
|
62
63
|
sha256Hex,
|
|
63
64
|
summarizeAttackErrors,
|
|
64
65
|
version
|
|
65
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-TWBU67PH.js";
|
|
66
67
|
|
|
67
68
|
// src/load-env.ts
|
|
68
69
|
try {
|
|
@@ -2673,6 +2674,14 @@ async function scanCommand(opts) {
|
|
|
2673
2674
|
if (!isolation.isolated) console.warn(`
|
|
2674
2675
|
\u26A0\uFE0F ${isolation.warning}
|
|
2675
2676
|
`);
|
|
2677
|
+
if (includeCrescendo && (multiTurnAttacks?.length ?? 0) > 0) {
|
|
2678
|
+
const conversation = checkConversationContext(target);
|
|
2679
|
+
if (!conversation.carried) {
|
|
2680
|
+
console.warn(`
|
|
2681
|
+
\u26A0\uFE0F ${conversation.warning}
|
|
2682
|
+
`);
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2676
2685
|
const catalogHash = computeCatalogHash([
|
|
2677
2686
|
...(attacks ?? []).map((a) => a.id),
|
|
2678
2687
|
...(multiTurnAttacks ?? []).map((a) => a.id),
|
|
@@ -2724,6 +2733,15 @@ async function scanCommand(opts) {
|
|
|
2724
2733
|
info("Scan started");
|
|
2725
2734
|
const scanner = new Scanner(scanOptions, onEvent);
|
|
2726
2735
|
const report = await scanner.run();
|
|
2736
|
+
if (report.stopReason === "auth") {
|
|
2737
|
+
const judged = scoredAttacks(report.attacks).length;
|
|
2738
|
+
const reason = `The target refused the scan's credentials (HTTP 401) after ${judged}/${report.attacks.length} attacks \u2014 the token has probably expired. Refresh it and re-run the same command: the ${judged} judged attack(s) resume from the checkpoint.`;
|
|
2739
|
+
await reportScanFailure(credentials, reservedScanId, reason);
|
|
2740
|
+
scanFinalized = true;
|
|
2741
|
+
console.error(`Scan stopped: ${reason}`);
|
|
2742
|
+
setExitCode(2);
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2727
2745
|
const attempted = report.attacks.length;
|
|
2728
2746
|
const evaluated = scoredAttacks(report.attacks).length;
|
|
2729
2747
|
if (reservedScanId && attempted > 0 && evaluated === 0) {
|
package/dist/index.js
CHANGED