xploitscan-shared-rules 1.14.1 → 1.14.3

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.js CHANGED
@@ -1058,8 +1058,8 @@ var hardcodedSecrets = {
1058
1058
  if (valMatch && nameMatch) {
1059
1059
  const value = valMatch[1];
1060
1060
  const isKeySuffix = nameMatch[1].endsWith("_KEY");
1061
- const isKebabIdentifier = value.length < 40 && /^[a-z0-9]+(-[a-z0-9]+)+$/.test(value);
1062
- if (isKeySuffix && isKebabIdentifier) continue;
1061
+ const isSlotIdentifier = value.length < 40 && /^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value);
1062
+ if (isKeySuffix && isSlotIdentifier) continue;
1063
1063
  }
1064
1064
  }
1065
1065
  matches.push(rm);
@@ -8554,6 +8554,7 @@ Common false positive patterns you should catch:
8554
8554
  - The comparison is a type check (typeof x === "string") not a secret comparison
8555
8555
  - The file is a test, mock, or fixture file
8556
8556
  - The "secret" is a publishable/public key (pk_test_, NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY) designed to be client-side
8557
+ - The value is a slot/name identifier, not a credential: a SCREAMING_CASE *_KEY constant assigned a short lowercase word string (e.g. INDEX_KEY = "mc_saves_index", CACHE_KEY = "user-prefs-v2") is a localStorage/cookie/cache key NAME, not a secret. Real secrets are high-entropy and mixed-case (sk_live_aBcD\u2026), not dictionary words joined by - or _
8557
8558
  - The innerHTML/dangerouslySetInnerHTML uses a static constant or JSON.stringify, not user input
8558
8559
  - The redirect URL has already been validated (isAllowedRedirect, validateRedirect)
8559
8560
  - The webhook endpoint is for a non-Stripe service but flagged as "Stripe webhook"
@@ -8572,6 +8573,14 @@ var MAX_TOTAL_FINDINGS = (() => {
8572
8573
  if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_TOTAL_FINDINGS;
8573
8574
  return Math.min(n, 1e3);
8574
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
+ })();
8575
8584
  var SEVERITY_PRIORITY = {
8576
8585
  critical: 0,
8577
8586
  high: 1,
@@ -8647,32 +8656,72 @@ async function filterFalsePositives(findings, fileContents) {
8647
8656
  return empty;
8648
8657
  }
8649
8658
  const fpMap = /* @__PURE__ */ new Map();
8659
+ let reviewedAny = false;
8660
+ let firstError = null;
8661
+ let failedBatches = 0;
8662
+ const tasks = [];
8650
8663
  for (const [file, fileFindings] of byFile) {
8651
8664
  const content = fileContents.get(file);
8652
8665
  if (!content) continue;
8653
8666
  for (let i = 0; i < fileFindings.length; i += MAX_FINDINGS_PER_BATCH) {
8654
- const batch = fileFindings.slice(i, i + MAX_FINDINGS_PER_BATCH);
8667
+ tasks.push({ batch: fileFindings.slice(i, i + MAX_FINDINGS_PER_BATCH), content });
8668
+ }
8669
+ }
8670
+ const reviewBatch = async (task) => {
8671
+ try {
8672
+ const { batch, content } = task;
8655
8673
  const prompt = buildReviewPrompt(batch, content);
8656
- try {
8657
- const response = await client.messages.create({
8674
+ const response = await client.messages.create(
8675
+ {
8658
8676
  model: "claude-haiku-4-5-20251001",
8659
8677
  max_tokens: 1024,
8660
8678
  system: REVIEW_SYSTEM_PROMPT,
8661
8679
  messages: [{ role: "user", content: prompt }]
8662
- });
8663
- const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
8664
- const results = parseReviewResponse(text);
8665
- for (const r of results) {
8666
- if (r.verdict === "fp" && r.index >= 0 && r.index < batch.length) {
8667
- const globalIndex = toReview.indexOf(batch[r.index]);
8668
- if (globalIndex !== -1) {
8669
- fpMap.set(globalIndex, r.reason);
8670
- }
8680
+ },
8681
+ // Cap a single call well under any serverless function timeout — the
8682
+ // SDK default is 10 minutes, long enough for one hung connection to
8683
+ // hold a worker until the platform SIGKILLs the whole scan request
8684
+ // (which would skip the graceful-degradation fallback). A timeout
8685
+ // turns a stuck batch into an unreviewed batch, handled below.
8686
+ { timeout: 2e4 }
8687
+ );
8688
+ const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
8689
+ const results = parseReviewResponse(text);
8690
+ reviewedAny = true;
8691
+ for (const r of results) {
8692
+ if (r.verdict === "fp" && r.index >= 0 && r.index < batch.length) {
8693
+ const globalIndex = toReview.indexOf(batch[r.index]);
8694
+ if (globalIndex !== -1) {
8695
+ fpMap.set(globalIndex, r.reason);
8671
8696
  }
8672
8697
  }
8673
- } catch {
8674
- continue;
8675
8698
  }
8699
+ } catch (err) {
8700
+ failedBatches++;
8701
+ if (!firstError) firstError = err;
8702
+ }
8703
+ };
8704
+ let next = 0;
8705
+ const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
8706
+ const workers = Array.from({ length: workerCount }, async () => {
8707
+ while (next < tasks.length) {
8708
+ const cur = next++;
8709
+ await reviewBatch(tasks[cur]);
8710
+ }
8711
+ });
8712
+ await Promise.all(workers);
8713
+ if (firstError) {
8714
+ const msg = firstError instanceof Error ? firstError.message : String(firstError);
8715
+ if (!reviewedAny) {
8716
+ console.error(
8717
+ "[ai-fp-filter] AI review unavailable \u2014 every model call failed; returning unreviewed findings:",
8718
+ msg
8719
+ );
8720
+ } else {
8721
+ console.warn(
8722
+ `[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed; those findings were not reviewed:`,
8723
+ msg
8724
+ );
8676
8725
  }
8677
8726
  }
8678
8727
  const filtered = toReview.filter((_, i) => !fpMap.has(i));
@@ -8683,7 +8732,7 @@ async function filterFalsePositives(findings, fileContents) {
8683
8732
  return {
8684
8733
  findings: [...filtered, ...overflow],
8685
8734
  filteredFindings,
8686
- aiReviewed: true,
8735
+ aiReviewed: reviewedAny,
8687
8736
  removedCount: fpMap.size,
8688
8737
  totalBefore
8689
8738
  };