shield-llm 0.1.1 → 0.2.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-XTU2RLZM.js → chunk-LH6W4P2C.js} +42 -4
- package/dist/cli.js +53 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -14762,6 +14762,26 @@ function resolveEnvVar(value) {
|
|
|
14762
14762
|
}
|
|
14763
14763
|
|
|
14764
14764
|
// ../../packages/scanner-core/src/http-target-client.ts
|
|
14765
|
+
function encodeRequestBody(body, encoding) {
|
|
14766
|
+
if (encoding === "form") {
|
|
14767
|
+
const params = new URLSearchParams();
|
|
14768
|
+
for (const [k, v] of Object.entries(body)) {
|
|
14769
|
+
params.append(k, typeof v === "string" ? v : JSON.stringify(v));
|
|
14770
|
+
}
|
|
14771
|
+
return {
|
|
14772
|
+
body: params.toString(),
|
|
14773
|
+
contentType: "application/x-www-form-urlencoded"
|
|
14774
|
+
};
|
|
14775
|
+
}
|
|
14776
|
+
if (encoding === "multipart") {
|
|
14777
|
+
const form = new FormData();
|
|
14778
|
+
for (const [k, v] of Object.entries(body)) {
|
|
14779
|
+
form.append(k, typeof v === "string" ? v : JSON.stringify(v));
|
|
14780
|
+
}
|
|
14781
|
+
return { body: form, contentType: null };
|
|
14782
|
+
}
|
|
14783
|
+
return { body: JSON.stringify(body), contentType: "application/json" };
|
|
14784
|
+
}
|
|
14765
14785
|
var PRIVATE_HOSTNAME_PATTERNS = [
|
|
14766
14786
|
/^localhost$/i,
|
|
14767
14787
|
/^127\./,
|
|
@@ -14904,12 +14924,21 @@ var HttpTargetClient = class {
|
|
|
14904
14924
|
sessionId
|
|
14905
14925
|
});
|
|
14906
14926
|
const headers = this.buildHeaders(auth);
|
|
14927
|
+
const { body: encodedBody, contentType } = encodeRequestBody(
|
|
14928
|
+
body,
|
|
14929
|
+
this.config.request.encoding
|
|
14930
|
+
);
|
|
14931
|
+
if (contentType === null) {
|
|
14932
|
+
delete headers["Content-Type"];
|
|
14933
|
+
} else {
|
|
14934
|
+
headers["Content-Type"] = contentType;
|
|
14935
|
+
}
|
|
14907
14936
|
return fetchWithTimeout(
|
|
14908
14937
|
this.config.url,
|
|
14909
14938
|
{
|
|
14910
14939
|
method: this.config.request.method ?? "POST",
|
|
14911
14940
|
headers,
|
|
14912
|
-
body:
|
|
14941
|
+
body: encodedBody,
|
|
14913
14942
|
signal: options?.abortSignal
|
|
14914
14943
|
},
|
|
14915
14944
|
this.config.timeoutMs ?? 3e4,
|
|
@@ -15246,8 +15275,11 @@ async function collectSSE(response) {
|
|
|
15246
15275
|
if (typeof parsed === "string") {
|
|
15247
15276
|
result += parsed;
|
|
15248
15277
|
} else {
|
|
15249
|
-
const chunk = parsed.message ?? parsed.content ?? parsed.delta?.content ?? parsed.text ?? parsed.choices?.[0]?.delta?.content ?? parsed.data
|
|
15250
|
-
|
|
15278
|
+
const chunk = parsed.message ?? parsed.content ?? parsed.delta?.content ?? parsed.text ?? parsed.choices?.[0]?.delta?.content ?? parsed.data?.message ?? // nested: {"data":{"message":"…"}} (e.g. ChatGot)
|
|
15279
|
+
parsed.data?.content ?? parsed.data;
|
|
15280
|
+
if (chunk != null) {
|
|
15281
|
+
result += typeof chunk === "string" ? chunk : JSON.stringify(chunk);
|
|
15282
|
+
}
|
|
15251
15283
|
}
|
|
15252
15284
|
} catch {
|
|
15253
15285
|
result += payload;
|
|
@@ -23324,7 +23356,12 @@ var AuthConfigSchema = z29.discriminatedUnion("type", [
|
|
|
23324
23356
|
var RequestTemplateSchema = z29.object({
|
|
23325
23357
|
method: z29.enum(["POST", "PUT", "PATCH"]).optional(),
|
|
23326
23358
|
body: z29.record(z29.unknown()),
|
|
23327
|
-
headers: z29.record(z29.string()).optional()
|
|
23359
|
+
headers: z29.record(z29.string()).optional(),
|
|
23360
|
+
// How to encode the outgoing body. Default "json" (JSON.stringify +
|
|
23361
|
+
// application/json). "form" = application/x-www-form-urlencoded, "multipart"
|
|
23362
|
+
// = multipart/form-data (Content-Type is left to fetch so the boundary is
|
|
23363
|
+
// set). Real chatbots often expect form encodings (e.g. FastAPI `Form(...)`).
|
|
23364
|
+
encoding: z29.enum(["json", "form", "multipart"]).optional()
|
|
23328
23365
|
});
|
|
23329
23366
|
var ResponseTemplateSchema = z29.object({
|
|
23330
23367
|
field: z29.string().min(1),
|
|
@@ -24270,6 +24307,7 @@ export {
|
|
|
24270
24307
|
deserializeAttack,
|
|
24271
24308
|
deserializeMultiTurnAttack,
|
|
24272
24309
|
calculateComplianceScore,
|
|
24310
|
+
createTargetClient,
|
|
24273
24311
|
Scanner,
|
|
24274
24312
|
ConfigSchema,
|
|
24275
24313
|
loadConfig,
|
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
analyzeJudgeHealth,
|
|
7
7
|
buildTargetConfig,
|
|
8
8
|
calculateComplianceScore,
|
|
9
|
+
createTargetClient,
|
|
9
10
|
deserializeAttack,
|
|
10
11
|
deserializeMultiTurnAttack,
|
|
11
12
|
evaluateThresholds,
|
|
@@ -16,7 +17,7 @@ import {
|
|
|
16
17
|
generatePdf,
|
|
17
18
|
loadConfig,
|
|
18
19
|
loadSystemPrompt
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-LH6W4P2C.js";
|
|
20
21
|
import "./chunk-7D5WVZW5.js";
|
|
21
22
|
|
|
22
23
|
// src/cli.ts
|
|
@@ -1213,6 +1214,50 @@ async function scanCommand(opts) {
|
|
|
1213
1214
|
}
|
|
1214
1215
|
}
|
|
1215
1216
|
|
|
1217
|
+
// src/commands/test-connection.ts
|
|
1218
|
+
var DEFAULT_MESSAGE = "Hello! This is a Shield LLM connectivity test \u2014 please reply in one short sentence.";
|
|
1219
|
+
async function testConnectionCommand(opts) {
|
|
1220
|
+
let config;
|
|
1221
|
+
try {
|
|
1222
|
+
config = loadConfig({ configPath: opts.config });
|
|
1223
|
+
} catch (e) {
|
|
1224
|
+
console.error(
|
|
1225
|
+
e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`
|
|
1226
|
+
);
|
|
1227
|
+
setExitCode(2);
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
const target = buildTargetConfig(config);
|
|
1231
|
+
const systemPrompt = loadSystemPrompt(config);
|
|
1232
|
+
const message = opts.message ?? DEFAULT_MESSAGE;
|
|
1233
|
+
const where = target.mode === "endpoint" ? target.url : `${target.provider}/${target.model ?? "default"}`;
|
|
1234
|
+
console.log(`Target: ${where}`);
|
|
1235
|
+
if (target.mode === "endpoint" && target.request.encoding) {
|
|
1236
|
+
console.log(`Encoding: ${target.request.encoding}`);
|
|
1237
|
+
}
|
|
1238
|
+
console.log(`Sending benign test message: "${message}"
|
|
1239
|
+
`);
|
|
1240
|
+
try {
|
|
1241
|
+
const client = createTargetClient(target, systemPrompt);
|
|
1242
|
+
const start = Date.now();
|
|
1243
|
+
const reply = await client.sendMessage(message);
|
|
1244
|
+
const ms = Date.now() - start;
|
|
1245
|
+
console.log(`\u2713 Connection OK (${ms}ms). Chatbot replied:
|
|
1246
|
+
`);
|
|
1247
|
+
console.log(reply.trim().slice(0, 2e3) || "(empty response)");
|
|
1248
|
+
console.log(
|
|
1249
|
+
"\nConfig looks good \u2014 the target is reachable and the response parses. You can run a scan against it."
|
|
1250
|
+
);
|
|
1251
|
+
} catch (e) {
|
|
1252
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
1253
|
+
console.error(`\u2716 Connection failed: ${msg}`);
|
|
1254
|
+
console.error(
|
|
1255
|
+
"\nCheck: endpoint URL, request.encoding (json/form/multipart), auth, and response.field."
|
|
1256
|
+
);
|
|
1257
|
+
setExitCode(3);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1216
1261
|
// src/commands/tests.ts
|
|
1217
1262
|
async function testsCommand(opts) {
|
|
1218
1263
|
let localTests = [];
|
|
@@ -1344,7 +1389,7 @@ process.on("uncaughtException", (err) => {
|
|
|
1344
1389
|
});
|
|
1345
1390
|
var program = new Command();
|
|
1346
1391
|
program.exitOverride();
|
|
1347
|
-
program.name("shield-llm").description("AI chatbot security scanner \u2014 automated red teaming for LLMs").version("0.
|
|
1392
|
+
program.name("shield-llm").description("AI chatbot security scanner \u2014 automated red teaming for LLMs").version("0.2.0");
|
|
1348
1393
|
program.command("scan").description("Run a security scan against a target chatbot").option("-c, --config <path>", "Path to shield.config.json").option("-p, --provider <name>", "Target provider (openai, mistral)").option("-m, --model <name>", "Target model name").option("-e, --endpoint <url>", "Target chatbot HTTP endpoint URL").option("--auth <type>", "Auth type: bearer, api-key, oauth2").option("--token <value>", "Bearer token or API key value").option("--auth-header <name>", "Custom auth header name (for api-key auth)").option(
|
|
1349
1394
|
"--response-field <path>",
|
|
1350
1395
|
"Dot-notation path to response text in JSON (default: response)"
|
|
@@ -1379,6 +1424,12 @@ program.command("tests").description("List custom tests (local config and/or rem
|
|
|
1379
1424
|
"Backend API URL (overrides SHIELD_API_URL env var)"
|
|
1380
1425
|
).action(testsCommand);
|
|
1381
1426
|
program.command("validate").description("Validate a shield.config.json file").option("-c, --config <path>", "Path to config file").action(validateCommand);
|
|
1427
|
+
program.command("test-connection").description(
|
|
1428
|
+
"Send one benign message to the configured chatbot and print its reply (config plumbing check, no scan)"
|
|
1429
|
+
).option("-c, --config <path>", "Path to config file").option(
|
|
1430
|
+
"-m, --message <text>",
|
|
1431
|
+
"Benign message to send (default: a greeting)"
|
|
1432
|
+
).action(testConnectionCommand);
|
|
1382
1433
|
program.command("report <scanId>").description("Fetch a past scan report from your dashboard").option("-o, --output <format>", "Output format (json, markdown)", "json").option("--output-file <path>", "Write report to file").option("--api-url <url>", "Backend API URL override").action(reportCommand);
|
|
1383
1434
|
program.command("login").description("Authenticate with your Shield LLM API key").requiredOption("--key <api-key>", "Your API key (sk_shield_...)").option(
|
|
1384
1435
|
"--api-url <url>",
|
package/dist/index.js
CHANGED