shield-llm 0.1.0 → 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/bin/shield-llm.js CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
2
- import "../dist/cli.js";
1
+ #!/usr/bin/env node
2
+ import "../dist/cli.js";
@@ -2411,6 +2411,9 @@ function extractQuotedText(text2) {
2411
2411
  }
2412
2412
  return results;
2413
2413
  }
2414
+ function escapeHtml(str) {
2415
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
2416
+ }
2414
2417
 
2415
2418
  // ../../packages/shared/src/remediation/types.ts
2416
2419
  var LAYER_META = {
@@ -14759,6 +14762,26 @@ function resolveEnvVar(value) {
14759
14762
  }
14760
14763
 
14761
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
+ }
14762
14785
  var PRIVATE_HOSTNAME_PATTERNS = [
14763
14786
  /^localhost$/i,
14764
14787
  /^127\./,
@@ -14901,12 +14924,21 @@ var HttpTargetClient = class {
14901
14924
  sessionId
14902
14925
  });
14903
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
+ }
14904
14936
  return fetchWithTimeout(
14905
14937
  this.config.url,
14906
14938
  {
14907
14939
  method: this.config.request.method ?? "POST",
14908
14940
  headers,
14909
- body: JSON.stringify(body),
14941
+ body: encodedBody,
14910
14942
  signal: options?.abortSignal
14911
14943
  },
14912
14944
  this.config.timeoutMs ?? 3e4,
@@ -15243,8 +15275,11 @@ async function collectSSE(response) {
15243
15275
  if (typeof parsed === "string") {
15244
15276
  result += parsed;
15245
15277
  } else {
15246
- const chunk = parsed.message ?? parsed.content ?? parsed.delta?.content ?? parsed.text ?? parsed.choices?.[0]?.delta?.content ?? parsed.data;
15247
- if (chunk != null) result += String(chunk);
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
+ }
15248
15283
  }
15249
15284
  } catch {
15250
15285
  result += payload;
@@ -23321,7 +23356,12 @@ var AuthConfigSchema = z29.discriminatedUnion("type", [
23321
23356
  var RequestTemplateSchema = z29.object({
23322
23357
  method: z29.enum(["POST", "PUT", "PATCH"]).optional(),
23323
23358
  body: z29.record(z29.unknown()),
23324
- 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()
23325
23365
  });
23326
23366
  var ResponseTemplateSchema = z29.object({
23327
23367
  field: z29.string().min(1),
@@ -24059,8 +24099,9 @@ function buildOwaspCoverage(map) {
24059
24099
  });
24060
24100
  }
24061
24101
  function buildExecutiveSummary(totalVulns, critical, crescendo, combo, high, medium, totalTests, target) {
24102
+ const safeTarget = escapeHtml(target);
24062
24103
  if (totalVulns === 0) {
24063
- return `The assessment identified <strong>no vulnerabilities</strong> across ${totalTests} automated tests mapped to the OWASP LLM Top 10 2025 framework. The chatbot at <strong>${target}</strong> successfully defended against all attack vectors tested. No immediate action is required.`;
24104
+ return `The assessment identified <strong>no vulnerabilities</strong> across ${totalTests} automated tests mapped to the OWASP LLM Top 10 2025 framework. The chatbot at <strong>${safeTarget}</strong> successfully defended against all attack vectors tested. No immediate action is required.`;
24064
24105
  }
24065
24106
  const parts = [];
24066
24107
  if (critical > 0) parts.push(`${critical} critical`);
@@ -24266,6 +24307,7 @@ export {
24266
24307
  deserializeAttack,
24267
24308
  deserializeMultiTurnAttack,
24268
24309
  calculateComplianceScore,
24310
+ createTargetClient,
24269
24311
  Scanner,
24270
24312
  ConfigSchema,
24271
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-6HLD55BG.js";
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.1.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
@@ -9,7 +9,7 @@ import {
9
9
  generatePdf,
10
10
  loadConfig,
11
11
  loadSystemPrompt
12
- } from "./chunk-6HLD55BG.js";
12
+ } from "./chunk-LH6W4P2C.js";
13
13
  import "./chunk-7D5WVZW5.js";
14
14
  export {
15
15
  ConfigError,