xploitscan-shared-rules 2.4.32 → 2.4.33

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/index.cjs CHANGED
@@ -236,7 +236,7 @@ __export(index_exports, {
236
236
  module.exports = __toCommonJS(index_exports);
237
237
 
238
238
  // src/version.ts
239
- var SCANNER_VERSION = "2.4.32";
239
+ var SCANNER_VERSION = "2.4.33";
240
240
 
241
241
  // src/snippet.ts
242
242
  var cacheContent = null;
@@ -10474,6 +10474,70 @@ function callWasAborted(err) {
10474
10474
  const name = "name" in err ? String(err.name) : "";
10475
10475
  return name === "AbortError" || name === "APIUserAbortError";
10476
10476
  }
10477
+ var SAFE_ERROR_IDENT = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
10478
+ var SAFE_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,47}$/;
10479
+ function safeIdent(value) {
10480
+ return typeof value === "string" && SAFE_ERROR_IDENT.test(value) ? value : null;
10481
+ }
10482
+ function errorClassChain(err) {
10483
+ const names = [];
10484
+ let proto = Object.getPrototypeOf(err);
10485
+ for (let depth = 0; proto && depth < 8; depth++) {
10486
+ const ctor = proto.constructor;
10487
+ const name = safeIdent(ctor?.name);
10488
+ if (name && name !== "Object") names.push(name);
10489
+ proto = Object.getPrototypeOf(proto);
10490
+ }
10491
+ return names;
10492
+ }
10493
+ function causeLabel(err) {
10494
+ const cause = err.cause;
10495
+ if (!cause || typeof cause !== "object") return null;
10496
+ const chain = errorClassChain(cause);
10497
+ const name = chain[0] ?? safeIdent(cause.name);
10498
+ let code = null;
10499
+ let node = cause;
10500
+ for (let depth = 0; node && typeof node === "object" && depth < 3 && !code; depth++) {
10501
+ const raw = node.code;
10502
+ if (typeof raw === "string" && SAFE_ERROR_CODE.test(raw)) code = raw;
10503
+ node = node.cause;
10504
+ }
10505
+ if (!name && !code) return null;
10506
+ return code ? `${name ?? "unknown"}/${code}` : name;
10507
+ }
10508
+ function classifyModelError(err) {
10509
+ if (!err || typeof err !== "object") {
10510
+ return { name: "unknown", category: "unknown", status: null, cause: null };
10511
+ }
10512
+ const chain = errorClassChain(err);
10513
+ const ownName = safeIdent(err.name);
10514
+ const specific = chain.find((name2) => name2 !== "Error");
10515
+ const name = specific ?? (ownName && ownName !== "Error" ? ownName : chain[0] ?? ownName ?? "unknown");
10516
+ const status = errorHttpStatus(err);
10517
+ const names = new Set(chain);
10518
+ if (ownName) names.add(ownName);
10519
+ let category = "unknown";
10520
+ if (status === 401 || status === 403) category = "auth";
10521
+ else if (status === 400) category = "bad_request";
10522
+ else if (status === 429) category = "rate_limit";
10523
+ else if (status != null && status >= 500) category = "server";
10524
+ else if (status != null && status >= 400) category = "client";
10525
+ else if (names.has("APIConnectionTimeoutError") || names.has("TimeoutError")) category = "timeout";
10526
+ else if (names.has("APIUserAbortError") || names.has("AbortError")) category = "abort";
10527
+ else if (names.has("APIConnectionError")) category = "connection";
10528
+ const cause = causeLabel(err);
10529
+ if (category === "unknown" && cause && cause.includes("/")) category = "connection";
10530
+ return { name, category, status, cause };
10531
+ }
10532
+ function isRetryableModelError(info) {
10533
+ if (info.category === "timeout" || info.category === "abort") return false;
10534
+ if (info.status == null) return true;
10535
+ if (info.status === 408 || info.status === 409 || info.status === 429) return true;
10536
+ return info.status >= 500;
10537
+ }
10538
+ var MODEL_RETRY_DELAY_MS = 300;
10539
+ var HOSTED_RETRY_SURFACES = /* @__PURE__ */ new Set(["api", "web", "app"]);
10540
+ var MAX_MODEL_THROW_LOGS = 3;
10477
10541
  var SEVERITY_PRIORITY = {
10478
10542
  critical: 0,
10479
10543
  high: 1,
@@ -10765,6 +10829,7 @@ function parseReviewResponse(text) {
10765
10829
  }
10766
10830
  async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS, options) {
10767
10831
  const surface = options?.surface ?? "cli";
10832
+ const retryTransient = options?.retryTransient === true && HOSTED_RETRY_SURFACES.has(surface);
10768
10833
  const emptyMask = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
10769
10834
  const early = (status2, reason2, extra) => ({
10770
10835
  findings,
@@ -10840,6 +10905,14 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
10840
10905
  let fenceDropCount = 0;
10841
10906
  let timedOutCount = 0;
10842
10907
  let missingContentCount = 0;
10908
+ let modelThrowLogs = 0;
10909
+ const logModelThrow = (info, action) => {
10910
+ if (modelThrowLogs >= MAX_MODEL_THROW_LOGS) return;
10911
+ modelThrowLogs += 1;
10912
+ console.error(
10913
+ `[ai-fp-filter] model call threw: class ${info.name}, category ${info.category}, status ${info.status ?? "none"}, cause ${info.cause ?? "none"}, model ${MODEL_TRIAGE}; ${action}`
10914
+ );
10915
+ };
10843
10916
  const detectionCaches = /* @__PURE__ */ new Map();
10844
10917
  const cacheFor = (file) => {
10845
10918
  let cache2 = detectionCaches.get(file);
@@ -10972,34 +11045,53 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
10972
11045
  );
10973
11046
  }
10974
11047
  const perCall = perCallTimeoutMs(budgetMs);
10975
- const callTimeout = Math.min(perCall, remaining);
10976
- const callAbort = new AbortController();
10977
- const onParentAbort = () => callAbort.abort();
10978
- if (abortController.signal.aborted) callAbort.abort();
10979
- else abortController.signal.addEventListener("abort", onParentAbort, { once: true });
10980
- const callTimer = setTimeout(() => callAbort.abort(), callTimeout);
11048
+ let callAborted = false;
11049
+ const send = async (callTimeout) => {
11050
+ const callAbort = new AbortController();
11051
+ const onParentAbort = () => callAbort.abort();
11052
+ if (abortController.signal.aborted) callAbort.abort();
11053
+ else abortController.signal.addEventListener("abort", onParentAbort, { once: true });
11054
+ const callTimer = setTimeout(() => callAbort.abort(), callTimeout);
11055
+ try {
11056
+ return await client.messages.create(
11057
+ {
11058
+ model: MODEL_TRIAGE,
11059
+ max_tokens: 2048,
11060
+ // Haiku 5.5 rejects non-default sampling params with HTTP 400
11061
+ // ("temperature is deprecated for this model"). Omit temperature /
11062
+ // top_p / top_k entirely — do NOT send MODEL_TEMPERATURE (0).
11063
+ // Adaptive thinking is on by default for 5.5; disable it here: this
11064
+ // is binary FP classification, not open-ended analysis, and thinking
11065
+ // burns the shared AI budget (Isobar rescan: every call 400'd on
11066
+ // temperature, then timed_out with aiReviewed:false → grade D).
11067
+ thinking: { type: "disabled" },
11068
+ system: REVIEW_SYSTEM_PROMPT,
11069
+ messages: [{ role: "user", content: prompt }]
11070
+ },
11071
+ { timeout: callTimeout, signal: callAbort.signal }
11072
+ );
11073
+ } finally {
11074
+ callAborted = callAbort.signal.aborted;
11075
+ clearTimeout(callTimer);
11076
+ abortController.signal.removeEventListener("abort", onParentAbort);
11077
+ }
11078
+ };
10981
11079
  let response;
10982
11080
  try {
10983
- response = await client.messages.create(
10984
- {
10985
- model: MODEL_TRIAGE,
10986
- max_tokens: 2048,
10987
- // Haiku 5.5 rejects non-default sampling params with HTTP 400
10988
- // ("temperature is deprecated for this model"). Omit temperature /
10989
- // top_p / top_k entirely — do NOT send MODEL_TEMPERATURE (0).
10990
- // Adaptive thinking is on by default for 5.5; disable it here: this
10991
- // is binary FP classification, not open-ended analysis, and thinking
10992
- // burns the shared AI budget (Isobar rescan: every call 400'd on
10993
- // temperature, then timed_out with aiReviewed:false → grade D).
10994
- thinking: { type: "disabled" },
10995
- system: REVIEW_SYSTEM_PROMPT,
10996
- messages: [{ role: "user", content: prompt }]
10997
- },
10998
- { timeout: callTimeout, signal: callAbort.signal }
10999
- );
11000
- } finally {
11001
- clearTimeout(callTimer);
11002
- abortController.signal.removeEventListener("abort", onParentAbort);
11081
+ response = await send(Math.min(perCall, remaining));
11082
+ } catch (err) {
11083
+ const info = classifyModelError(err);
11084
+ const budgetAbort = abortController.signal.aborted;
11085
+ const retry = retryTransient && !callAborted && !budgetAbort && !authFailed && isRetryableModelError(info) && deadlineMs - Date.now() - MODEL_RETRY_DELAY_MS >= perCall;
11086
+ if (!budgetAbort) logModelThrow(info, retry ? "retrying once" : "not retried");
11087
+ if (!retry) throw err;
11088
+ await new Promise((resolve) => setTimeout(resolve, MODEL_RETRY_DELAY_MS));
11089
+ try {
11090
+ response = await send(Math.min(perCall, Math.max(1, deadlineMs - Date.now())));
11091
+ } catch (retryErr) {
11092
+ if (!abortController.signal.aborted) logModelThrow(classifyModelError(retryErr), "retry failed");
11093
+ throw retryErr;
11094
+ }
11003
11095
  }
11004
11096
  const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
11005
11097
  const results = parseReviewResponse(text);