xploitscan-shared-rules 1.14.2 → 1.14.4

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.d.cts CHANGED
@@ -364,6 +364,15 @@ interface AIFilterResult {
364
364
  aiReviewed: boolean;
365
365
  removedCount: number;
366
366
  totalBefore: number;
367
+ /**
368
+ * Findings that were NOT AI-reviewed because their batch's model call
369
+ * failed (e.g. a burst of 429s), even though other batches succeeded.
370
+ * 0 on a full review. Lets the UI honestly say "partially reviewed"
371
+ * instead of labeling unreviewed findings as AI-verified. Does NOT count
372
+ * findings skipped by the MAX_TOTAL_FINDINGS cap — that's by design, not
373
+ * a failure.
374
+ */
375
+ unreviewedCount: number;
367
376
  }
368
377
  /**
369
378
  * Filter false positives from findings using Claude Haiku.
package/dist/index.d.ts CHANGED
@@ -364,6 +364,15 @@ interface AIFilterResult {
364
364
  aiReviewed: boolean;
365
365
  removedCount: number;
366
366
  totalBefore: number;
367
+ /**
368
+ * Findings that were NOT AI-reviewed because their batch's model call
369
+ * failed (e.g. a burst of 429s), even though other batches succeeded.
370
+ * 0 on a full review. Lets the UI honestly say "partially reviewed"
371
+ * instead of labeling unreviewed findings as AI-verified. Does NOT count
372
+ * findings skipped by the MAX_TOTAL_FINDINGS cap — that's by design, not
373
+ * a failure.
374
+ */
375
+ unreviewedCount: number;
367
376
  }
368
377
  /**
369
378
  * Filter false positives from findings using Claude Haiku.
package/dist/index.js CHANGED
@@ -8573,6 +8573,14 @@ var MAX_TOTAL_FINDINGS = (() => {
8573
8573
  if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_TOTAL_FINDINGS;
8574
8574
  return Math.min(n, 1e3);
8575
8575
  })();
8576
+ var DEFAULT_MAX_CONCURRENT = 6;
8577
+ var MAX_CONCURRENT = (() => {
8578
+ const raw = process.env.XPLOITSCAN_AI_CONCURRENCY;
8579
+ if (!raw) return DEFAULT_MAX_CONCURRENT;
8580
+ const n = parseInt(raw, 10);
8581
+ if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_CONCURRENT;
8582
+ return Math.min(n, 20);
8583
+ })();
8576
8584
  var SEVERITY_PRIORITY = {
8577
8585
  critical: 0,
8578
8586
  high: 1,
@@ -8624,7 +8632,7 @@ function parseReviewResponse(text) {
8624
8632
  }
8625
8633
  }
8626
8634
  async function filterFalsePositives(findings, fileContents) {
8627
- const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length };
8635
+ const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length, unreviewedCount: 0 };
8628
8636
  if (!process.env.ANTHROPIC_API_KEY) return empty;
8629
8637
  if (findings.length === 0) return empty;
8630
8638
  const prioritized = [...findings].sort((a, b) => {
@@ -8650,41 +8658,73 @@ async function filterFalsePositives(findings, fileContents) {
8650
8658
  const fpMap = /* @__PURE__ */ new Map();
8651
8659
  let reviewedAny = false;
8652
8660
  let firstError = null;
8661
+ let failedBatches = 0;
8662
+ let unreviewedCount = 0;
8663
+ const tasks = [];
8653
8664
  for (const [file, fileFindings] of byFile) {
8654
8665
  const content = fileContents.get(file);
8655
8666
  if (!content) continue;
8656
8667
  for (let i = 0; i < fileFindings.length; i += MAX_FINDINGS_PER_BATCH) {
8657
- const batch = fileFindings.slice(i, i + MAX_FINDINGS_PER_BATCH);
8668
+ tasks.push({ batch: fileFindings.slice(i, i + MAX_FINDINGS_PER_BATCH), content });
8669
+ }
8670
+ }
8671
+ const reviewBatch = async (task) => {
8672
+ const { batch, content } = task;
8673
+ try {
8658
8674
  const prompt = buildReviewPrompt(batch, content);
8659
- try {
8660
- const response = await client.messages.create({
8675
+ const response = await client.messages.create(
8676
+ {
8661
8677
  model: "claude-haiku-4-5-20251001",
8662
8678
  max_tokens: 1024,
8663
8679
  system: REVIEW_SYSTEM_PROMPT,
8664
8680
  messages: [{ role: "user", content: prompt }]
8665
- });
8666
- const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
8667
- const results = parseReviewResponse(text);
8668
- reviewedAny = true;
8669
- for (const r of results) {
8670
- if (r.verdict === "fp" && r.index >= 0 && r.index < batch.length) {
8671
- const globalIndex = toReview.indexOf(batch[r.index]);
8672
- if (globalIndex !== -1) {
8673
- fpMap.set(globalIndex, r.reason);
8674
- }
8681
+ },
8682
+ // Cap a single call well under any serverless function timeout — the
8683
+ // SDK default is 10 minutes, long enough for one hung connection to
8684
+ // hold a worker until the platform SIGKILLs the whole scan request
8685
+ // (which would skip the graceful-degradation fallback). A timeout
8686
+ // turns a stuck batch into an unreviewed batch, handled below.
8687
+ { timeout: 2e4 }
8688
+ );
8689
+ const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
8690
+ const results = parseReviewResponse(text);
8691
+ reviewedAny = true;
8692
+ for (const r of results) {
8693
+ if (r.verdict === "fp" && r.index >= 0 && r.index < batch.length) {
8694
+ const globalIndex = toReview.indexOf(batch[r.index]);
8695
+ if (globalIndex !== -1) {
8696
+ fpMap.set(globalIndex, r.reason);
8675
8697
  }
8676
8698
  }
8677
- } catch (err) {
8678
- if (!firstError) firstError = err;
8679
- continue;
8680
8699
  }
8700
+ } catch (err) {
8701
+ failedBatches++;
8702
+ unreviewedCount += batch.length;
8703
+ if (!firstError) firstError = err;
8704
+ }
8705
+ };
8706
+ let next = 0;
8707
+ const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
8708
+ const workers = Array.from({ length: workerCount }, async () => {
8709
+ while (next < tasks.length) {
8710
+ const cur = next++;
8711
+ await reviewBatch(tasks[cur]);
8712
+ }
8713
+ });
8714
+ await Promise.all(workers);
8715
+ if (firstError) {
8716
+ const msg = firstError instanceof Error ? firstError.message : String(firstError);
8717
+ if (!reviewedAny) {
8718
+ console.error(
8719
+ "[ai-fp-filter] AI review unavailable \u2014 every model call failed; returning unreviewed findings:",
8720
+ msg
8721
+ );
8722
+ } else {
8723
+ console.warn(
8724
+ `[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed; those findings were not reviewed:`,
8725
+ msg
8726
+ );
8681
8727
  }
8682
- }
8683
- if (!reviewedAny && firstError) {
8684
- console.error(
8685
- "[ai-fp-filter] AI review unavailable \u2014 every model call failed; returning unreviewed findings:",
8686
- firstError instanceof Error ? firstError.message : String(firstError)
8687
- );
8688
8728
  }
8689
8729
  const filtered = toReview.filter((_, i) => !fpMap.has(i));
8690
8730
  const filteredFindings = [];
@@ -8696,7 +8736,8 @@ async function filterFalsePositives(findings, fileContents) {
8696
8736
  filteredFindings,
8697
8737
  aiReviewed: reviewedAny,
8698
8738
  removedCount: fpMap.size,
8699
- totalBefore
8739
+ totalBefore,
8740
+ unreviewedCount
8700
8741
  };
8701
8742
  }
8702
8743