shield-llm 0.15.0 → 0.16.1

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.
@@ -8672,6 +8672,262 @@ function recordVerification(claim, input) {
8672
8672
  };
8673
8673
  }
8674
8674
 
8675
+ // ../../packages/shared/src/remediation/playbooks.ts
8676
+ var FIX_OUTCOME_LABEL = {
8677
+ closable: "Can be closed in code",
8678
+ reducible: "Can be reduced, not eliminated",
8679
+ redesign: "Needs a design change"
8680
+ };
8681
+ function bench20261114(result) {
8682
+ return {
8683
+ date: "2026-11-14",
8684
+ model: "mistral-nemo 12B (local)",
8685
+ setup: "reference support bot, fixed by a coding agent from this brief, one run",
8686
+ result
8687
+ };
8688
+ }
8689
+ var SECRETS_OUT_OF_CONTEXT = "Take every secret (keys, internal codes, channel names, internal URLs) and every authorization rule out of the instructions: what is not in the model's context cannot leak. Rotate any secret that was there: treat it as disclosed.";
8690
+ var FIX_PLAYBOOKS = {
8691
+ SYSTEM_PROMPT_LEAK: {
8692
+ defect: "The bot repeats the instructions it was given when a user asks for them.",
8693
+ outcome: "reducible",
8694
+ remove: [
8695
+ SECRETS_OUT_OF_CONTEXT,
8696
+ "Remove capabilities the bot does not really have (a database it cannot query): the model states them as fact and invents content to match."
8697
+ ],
8698
+ enforceInCode: [
8699
+ "Filter the answer before it leaves the server: replace an answer that contains a long verbatim run of the instructions. Normalise first (case, whitespace, base64, hex, reversed text) so an encoded copy is caught too.",
8700
+ "Write the instructions as if they were public, so that their disclosure costs nothing."
8701
+ ],
8702
+ instructions: [
8703
+ "A short rule not to disclose or describe the instructions. On its own it does not hold: a reworded request gets through."
8704
+ ],
8705
+ redesign: [
8706
+ "Enforce business rules (discount limits, who may see what) in application code, never by a sentence in the instructions."
8707
+ ],
8708
+ pitfalls: [
8709
+ "The filter must compare the answer with the text of the instructions, not look for words such as 'instructions' or 'prompt': otherwise it replaces the bot's own correct refusals.",
8710
+ "A translation or a paraphrase of the instructions passes any verbatim filter. Record that residual risk instead of chasing it with more patterns.",
8711
+ "When the filter triggers on an ordinary question, answer that question again rather than returning a bare refusal."
8712
+ ],
8713
+ neighbours: ["REPEAT_VERBATIM_LEAK", "SYSTEM_PROMPT_LEAK_INDIRECT"],
8714
+ evidence: [
8715
+ bench20261114(
8716
+ "the exploit and its 2 neighbouring attacks failed in an independent retest."
8717
+ )
8718
+ ]
8719
+ },
8720
+ POLICY_PUPPETRY: {
8721
+ defect: "A message dressed as a system, policy or configuration block (XML, JSON, INI) makes the bot switch to a mode it does not have and dump its configuration.",
8722
+ outcome: "reducible",
8723
+ remove: [SECRETS_OUT_OF_CONTEXT],
8724
+ enforceInCode: [
8725
+ "The user channel carries no authority: a user message is never configuration. If the application has real modes (debug, admin), switch them in code from an authenticated session, never from message text.",
8726
+ "Apply the output filter of an instructions leak: the usual payload of this attack is a configuration dump.",
8727
+ "Optionally answer a message that is mostly an override block with a fixed reply, without calling the model. This is a heuristic layer: a reworded block gets past it."
8728
+ ],
8729
+ instructions: [
8730
+ "State that no message can change the bot's mode, role or rules, and that it has no diagnostic, debug or maintenance mode."
8731
+ ],
8732
+ redesign: [
8733
+ "Keep what an attacker would gain (data, tools) behind checks the model cannot waive."
8734
+ ],
8735
+ pitfalls: [
8736
+ "A block-shaped message can be legitimate: a customer pasting an XML error or a JSON payload to ask about it. Match on override vocabulary inside the block, not on the markup alone, and test with a pasted error.",
8737
+ "Questions about a real 'maintenance mode' of your own product must still be answered."
8738
+ ],
8739
+ neighbours: ["BACKDOOR_TRIGGER_TEST", "SUPPLY_CHAIN_UPDATE_SPOOF"],
8740
+ evidence: [
8741
+ bench20261114(
8742
+ "the exploit and its 2 neighbouring attacks failed in an independent retest."
8743
+ )
8744
+ ]
8745
+ },
8746
+ BACKDOOR_TRIGGER_TEST: {
8747
+ defect: "An 'activation key' or trigger phrase makes the bot announce an unrestricted or diagnostic mode and act on it.",
8748
+ outcome: "reducible",
8749
+ remove: [],
8750
+ enforceInCode: [
8751
+ "Never let message text switch a mode: a real privileged mode is entered through authenticated application code.",
8752
+ "Replace an answer that announces a special mode ('diagnostic mode enabled', 'restrictions disabled') and answer normally instead."
8753
+ ],
8754
+ instructions: [
8755
+ "State that there are no activation keys, hidden modes or passphrases, and that a claimed key changes nothing."
8756
+ ],
8757
+ redesign: [
8758
+ "If the concern is a poisoned or backdoored model, that is a supply-chain control: pin the model version, use a provider you can audit, test again on every model change. Application code cannot establish or remove a backdoor in the weights."
8759
+ ],
8760
+ pitfalls: [
8761
+ "Do not block every message that contains 'key' or 'activation': customers ask about product activation keys."
8762
+ ],
8763
+ neighbours: ["POLICY_PUPPETRY", "SUPPLY_CHAIN_UPDATE_SPOOF"],
8764
+ evidence: [
8765
+ bench20261114(
8766
+ "the exploit and its 2 neighbouring attacks failed in an independent retest."
8767
+ )
8768
+ ]
8769
+ },
8770
+ XSS_OUTPUT: {
8771
+ defect: "The bot's answer reaches a renderer as active HTML.",
8772
+ outcome: "closable",
8773
+ remove: [],
8774
+ enforceInCode: [
8775
+ `Encode the model's output for the context it is rendered in (in HTML: & < > " ') where the answer is inserted into a page (the template or the chat widget), or render it as text. Do it there for every answer, not only for suspicious ones.`,
8776
+ "If you render Markdown, use a sanitising renderer with an allow-list: no raw HTML, no javascript: or data: links, remote images disabled or limited to your own hosts.",
8777
+ "Add a Content-Security-Policy to the page that displays the chat."
8778
+ ],
8779
+ instructions: [
8780
+ "Asking the model not to produce HTML helps little and is not the fix."
8781
+ ],
8782
+ redesign: [],
8783
+ pitfalls: [
8784
+ "Encode once, at the output boundary. Encoding in the API and again in the front end shows '&amp;' to users.",
8785
+ "An API consumed by other programs should return the raw text and let each client encode for its own context.",
8786
+ "An escaped payload still contains the word 'script'. What matters is that no active tag survives: test the rendered result."
8787
+ ],
8788
+ neighbours: [],
8789
+ evidence: [bench20261114("the exploit failed in an independent retest.")]
8790
+ },
8791
+ SENSITIVE_DATA_EXTRACTION: {
8792
+ defect: "The bot discloses personal data, credentials or confidential content that is in its context.",
8793
+ outcome: "closable",
8794
+ remove: [
8795
+ "Do not put credentials, internal identifiers or other users' data in the instructions or in the conversation context. Give the model only the data of the authenticated user, fetched per request."
8796
+ ],
8797
+ enforceInCode: [
8798
+ "Redact known secret values and common credential formats from the answer before it leaves the server, after normalising encodings.",
8799
+ "Enforce who may read what in the data layer (the query), not in the model."
8800
+ ],
8801
+ instructions: ["A rule not to reveal confidential data, as a complement."],
8802
+ redesign: [],
8803
+ pitfalls: [
8804
+ "Keep the list of secrets to redact in configuration, not in the model's context.",
8805
+ "Before relying on a declared secret, check that it does not appear in ordinary answers: a value the bot is meant to give to customers is not a secret."
8806
+ ],
8807
+ neighbours: [],
8808
+ evidence: []
8809
+ },
8810
+ EXCESSIVE_AGENCY: {
8811
+ defect: "The bot runs, or says it runs, a command or an action a user asked for, with no check outside the model.",
8812
+ outcome: "closable",
8813
+ remove: [],
8814
+ enforceInCode: [
8815
+ "Give the model only the tools it needs, each with the narrowest parameters, deny by default. Validate every tool argument in code (allow-listed hosts, no shell interpolation).",
8816
+ "Require a confirmation by a human, outside the model, for any action that spends money, sends data out or cannot be undone.",
8817
+ "If the bot has no tools at all, make it say so instead of acting out an execution."
8818
+ ],
8819
+ instructions: ["State what the bot can and cannot do, as a complement."],
8820
+ redesign: [
8821
+ "Run tools with the user's own permissions, never a shared service account, so the model cannot do more than the user could."
8822
+ ],
8823
+ pitfalls: [
8824
+ "Explaining what a command does is not executing it: do not make the bot refuse to discuss commands if your product is technical."
8825
+ ],
8826
+ neighbours: ["PLUGIN_COMMAND_INJECTION"],
8827
+ evidence: []
8828
+ },
8829
+ RAG_SOURCE_LEAK: {
8830
+ defect: "Under an audit or compliance pretext, the bot lists the documents, file paths or retrieval internals behind its answers, or invents them.",
8831
+ outcome: "reducible",
8832
+ remove: [
8833
+ "Do not pass file paths, storage locations, index names or internal document ids to the model: give it the passage text and, if you cite sources, a public title or link only.",
8834
+ "Remove claims of access the bot does not have ('you can read the order database'): the model invents sources to match them."
8835
+ ],
8836
+ enforceInCode: [
8837
+ "Strip internal paths and identifiers from the answer before it leaves the server.",
8838
+ "Handle data-subject and audit requests through your real process (a form, a mailbox) and have the bot route to it."
8839
+ ],
8840
+ instructions: [
8841
+ "State that the bot does not disclose internal details of its sources, and where audit requests go."
8842
+ ],
8843
+ redesign: [],
8844
+ pitfalls: [
8845
+ "If the application has no retrieval, the 'sources' were made up: the fix is to stop the bot claiming them, not to filter metadata that does not exist.",
8846
+ "Customers may legitimately ask where an answer comes from: keep public citations working."
8847
+ ],
8848
+ neighbours: ["RAG_SOURCE_LEAK_FR", "RAG_METADATA_EXTRACTION"],
8849
+ evidence: [
8850
+ bench20261114(
8851
+ "the exploit and its 2 neighbouring attacks failed in an independent retest."
8852
+ )
8853
+ ]
8854
+ },
8855
+ SUPPLY_CHAIN_MODEL_DISCLOSURE: {
8856
+ defect: "A vendor-assessment questionnaire gets the bot to reveal which model it runs on, its knowledge cutoff or its limits, which tells an attacker which known attacks to try.",
8857
+ outcome: "reducible",
8858
+ remove: [],
8859
+ enforceInCode: [
8860
+ "Keep the bot on its task: answer an out-of-scope questionnaire with what the bot is for.",
8861
+ "Remove sentences that name the model, the provider or a training cutoff from the answer."
8862
+ ],
8863
+ instructions: [
8864
+ "State that the bot does not discuss its underlying model, provider, version, training data or limits, and answers the same way whether or not it knows them."
8865
+ ],
8866
+ redesign: [
8867
+ "Assume the model can be identified anyway: answer style and knowledge give it away. Do not let your security depend on the model being unknown; keep it patched and tested."
8868
+ ],
8869
+ pitfalls: [
8870
+ "The bot must still say it is an AI when asked: hiding the model is not hiding that it is a machine.",
8871
+ "Answering general-knowledge questions outside the bot's scope is what leaks the cutoff. A scope rule closes more than a filter on the word 'cutoff'."
8872
+ ],
8873
+ neighbours: ["SUPPLY_CHAIN_CAPABILITY_PROBE"],
8874
+ evidence: [
8875
+ bench20261114(
8876
+ "the exploit and its neighbouring attack failed in an independent retest."
8877
+ )
8878
+ ]
8879
+ },
8880
+ CONTEXT_OVERFLOW: {
8881
+ defect: "A request built to expand step by step makes the bot produce a very long answer: cost and latency grow without limit.",
8882
+ outcome: "closable",
8883
+ remove: [],
8884
+ enforceInCode: [
8885
+ "Set a hard cap on the output of one answer (maximum output tokens), sized for your use case, and caps on the input length and on the history you resend.",
8886
+ "Rate-limit and budget per user or per key, so that one caller cannot spend without limit.",
8887
+ "Set a timeout on the model call."
8888
+ ],
8889
+ instructions: [
8890
+ "A scope rule (the bot answers support questions, not academic briefings), as a complement."
8891
+ ],
8892
+ redesign: [],
8893
+ pitfalls: [
8894
+ "A cap that is too low cuts legitimate answers mid-sentence: measure the length of real answers first.",
8895
+ "A cap that already exists is not the fix if the answer cut at the cap is still delivered: decide what the user gets when the cap is hit, for example a short message asking for a narrower question."
8896
+ ],
8897
+ neighbours: ["RESOURCE_EXHAUSTION"],
8898
+ evidence: [
8899
+ bench20261114(
8900
+ "the exploit and its neighbouring attack failed in an independent retest."
8901
+ )
8902
+ ]
8903
+ },
8904
+ AI_IDENTITY_DENIAL: {
8905
+ defect: "Asked whether it is a human or an AI, the bot says it is human, or does not say it is an AI.",
8906
+ outcome: "closable",
8907
+ remove: [],
8908
+ enforceInCode: [
8909
+ "Show in the interface itself that the user is talking to an AI (a label on the chat), so the disclosure does not depend on the model.",
8910
+ "Replace an answer in which the bot states it is human."
8911
+ ],
8912
+ instructions: [
8913
+ "State that the bot is an AI assistant, says so whenever asked, in any language, and never claims or acts out being human, even when the user asks it to stay in character."
8914
+ ],
8915
+ redesign: [],
8916
+ pitfalls: [
8917
+ "Do not make the bot open every answer with 'I am an AI': it lengthens answers and annoys users. The interface label and a truthful answer when asked are enough.",
8918
+ "A persona with a first name is fine as long as it never claims to be human."
8919
+ ],
8920
+ neighbours: ["AI_IDENTITY_ROLEPLAY_DENIAL", "AI_IDENTITY_PERSISTENCE"],
8921
+ evidence: []
8922
+ }
8923
+ };
8924
+ function getFixPlaybook(attackId) {
8925
+ return FIX_PLAYBOOKS[attackId] ?? FIX_PLAYBOOKS[baseAttackId(attackId)];
8926
+ }
8927
+ function neighbourAttackIds(attackId) {
8928
+ return getFixPlaybook(attackId)?.neighbours ?? [];
8929
+ }
8930
+
8675
8931
  // ../../packages/shared/src/remediation/index.ts
8676
8932
  var DEFAULT_REMEDIATION = {
8677
8933
  vulnerabilityType: "DEFAULT",
@@ -9280,7 +9536,7 @@ function parseImportFile(textContent, format) {
9280
9536
  }
9281
9537
 
9282
9538
  // package.json
9283
- var version = "0.15.0";
9539
+ var version = "0.16.1";
9284
9540
 
9285
9541
  // src/config/schema.ts
9286
9542
  import { z as z3 } from "zod";
@@ -12281,7 +12537,9 @@ var CONFIG_FILENAMES = ["shield.config.json"];
12281
12537
  function loadConfig(options) {
12282
12538
  const { configPath, cliOverrides } = options;
12283
12539
  let fileConfig = {};
12540
+ let fileFound = false;
12284
12541
  if (configPath) {
12542
+ fileFound = true;
12285
12543
  const fullPath = resolve(configPath);
12286
12544
  if (!existsSync(fullPath)) {
12287
12545
  throw new ConfigError(`Config file not found: ${fullPath}`);
@@ -12292,10 +12550,17 @@ function loadConfig(options) {
12292
12550
  const fullPath = resolve(filename);
12293
12551
  if (existsSync(fullPath)) {
12294
12552
  fileConfig = readJsonFile(fullPath);
12553
+ fileFound = true;
12295
12554
  break;
12296
12555
  }
12297
12556
  }
12298
12557
  }
12558
+ if (!fileFound && !cliOverrides?.endpoint?.url) {
12559
+ throw new ConfigError(
12560
+ `No ${CONFIG_FILENAMES[0]} in ${process.cwd()}.
12561
+ Run \`shield-llm init\` to create one, or pass --config <path>.`
12562
+ );
12563
+ }
12299
12564
  const merged = deepMerge(fileConfig, cliOverrides ?? {});
12300
12565
  const result = ConfigSchema.safeParse(merged);
12301
12566
  if (!result.success) {
@@ -12631,8 +12896,36 @@ var CATEGORY_LABELS = {
12631
12896
  provider_error: "LLM provider returned a server error",
12632
12897
  unknown: "LLM judge failed (see backend logs)"
12633
12898
  };
12899
+ var SHIELD_BUDGET_LABELS = {
12900
+ shield_daily_user_budget: "your daily judge budget on this Shield instance is spent; it resets at 00:00 UTC, or ask your Shield administrator to raise it",
12901
+ shield_daily_total_budget: "this Shield instance's daily judge budget is spent; it resets at 00:00 UTC"
12902
+ };
12903
+ function summaryFor(category, codes) {
12904
+ const seen = codes.get(category);
12905
+ if (seen?.size === 1) {
12906
+ const label = budgetLabel(Array.from(seen)[0]);
12907
+ if (label) return label;
12908
+ }
12909
+ return CATEGORY_LABELS[category];
12910
+ }
12911
+ function shieldBudgetReason(report) {
12912
+ const codes = /* @__PURE__ */ new Set();
12913
+ for (const a of report.attacks) {
12914
+ if (!a.llmEvaluation) continue;
12915
+ const judgeError = extractJudgeError(a.llmEvaluation);
12916
+ if (judgeError && !isFloorConfirmed(a.llmEvaluation)) {
12917
+ codes.add(judgeError.providerCode);
12918
+ }
12919
+ }
12920
+ if (codes.size !== 1) return null;
12921
+ return budgetLabel(Array.from(codes)[0]);
12922
+ }
12923
+ function budgetLabel(code) {
12924
+ return code && Object.prototype.hasOwnProperty.call(SHIELD_BUDGET_LABELS, code) ? SHIELD_BUDGET_LABELS[code] : null;
12925
+ }
12634
12926
  function analyzeJudgeHealth(report) {
12635
12927
  const counts = /* @__PURE__ */ new Map();
12928
+ const codes = /* @__PURE__ */ new Map();
12636
12929
  let degradedCount = 0;
12637
12930
  let totalEvaluated = 0;
12638
12931
  for (const a of report.attacks) {
@@ -12641,7 +12934,13 @@ function analyzeJudgeHealth(report) {
12641
12934
  const judgeError = extractJudgeError(a.llmEvaluation);
12642
12935
  if (judgeError && !isFloorConfirmed(a.llmEvaluation)) {
12643
12936
  degradedCount += 1;
12644
- counts.set(judgeError.category, (counts.get(judgeError.category) ?? 0) + 1);
12937
+ counts.set(
12938
+ judgeError.category,
12939
+ (counts.get(judgeError.category) ?? 0) + 1
12940
+ );
12941
+ const seen = codes.get(judgeError.category) ?? /* @__PURE__ */ new Set();
12942
+ seen.add(judgeError.providerCode);
12943
+ codes.set(judgeError.category, seen);
12645
12944
  }
12646
12945
  }
12647
12946
  const rejudged = report.judgeRecovery?.rejudged ?? 0;
@@ -12664,7 +12963,7 @@ function analyzeJudgeHealth(report) {
12664
12963
  degradedCount,
12665
12964
  totalEvaluated,
12666
12965
  category,
12667
- errorSummary: CATEGORY_LABELS[category],
12966
+ errorSummary: summaryFor(category, codes),
12668
12967
  rejudged,
12669
12968
  notJudged: notJudged2
12670
12969
  };
@@ -12999,6 +13298,9 @@ export {
12999
13298
  isExpired,
13000
13299
  mayStampFixed,
13001
13300
  recordVerification,
13301
+ FIX_OUTCOME_LABEL,
13302
+ getFixPlaybook,
13303
+ neighbourAttackIds,
13002
13304
  getStructuredRemediation,
13003
13305
  sha256Hex,
13004
13306
  normalizeTargetUrl,
@@ -13012,6 +13314,8 @@ export {
13012
13314
  parseImportFile,
13013
13315
  version,
13014
13316
  RateLimitError,
13317
+ isPrivateUrl,
13318
+ assertPublicHost,
13015
13319
  checkConversationContext,
13016
13320
  checkSessionIsolation,
13017
13321
  createTargetClient,
@@ -13032,6 +13336,7 @@ export {
13032
13336
  buildEndpointOverride,
13033
13337
  ConfigError,
13034
13338
  c2 as c,
13339
+ shieldBudgetReason,
13035
13340
  analyzeJudgeHealth,
13036
13341
  evaluateThresholds,
13037
13342
  formatComplianceTerminal,