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.cjs CHANGED
@@ -1326,8 +1326,8 @@ var hardcodedSecrets = {
1326
1326
  if (valMatch && nameMatch) {
1327
1327
  const value = valMatch[1];
1328
1328
  const isKeySuffix = nameMatch[1].endsWith("_KEY");
1329
- const isKebabIdentifier = value.length < 40 && /^[a-z0-9]+(-[a-z0-9]+)+$/.test(value);
1330
- if (isKeySuffix && isKebabIdentifier) continue;
1329
+ const isSlotIdentifier = value.length < 40 && /^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value);
1330
+ if (isKeySuffix && isSlotIdentifier) continue;
1331
1331
  }
1332
1332
  }
1333
1333
  matches.push(rm);
@@ -8822,6 +8822,7 @@ Common false positive patterns you should catch:
8822
8822
  - The comparison is a type check (typeof x === "string") not a secret comparison
8823
8823
  - The file is a test, mock, or fixture file
8824
8824
  - The "secret" is a publishable/public key (pk_test_, NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY) designed to be client-side
8825
+ - 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 _
8825
8826
  - The innerHTML/dangerouslySetInnerHTML uses a static constant or JSON.stringify, not user input
8826
8827
  - The redirect URL has already been validated (isAllowedRedirect, validateRedirect)
8827
8828
  - The webhook endpoint is for a non-Stripe service but flagged as "Stripe webhook"
@@ -8840,6 +8841,14 @@ var MAX_TOTAL_FINDINGS = (() => {
8840
8841
  if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_TOTAL_FINDINGS;
8841
8842
  return Math.min(n, 1e3);
8842
8843
  })();
8844
+ var DEFAULT_MAX_CONCURRENT = 6;
8845
+ var MAX_CONCURRENT = (() => {
8846
+ const raw = process.env.XPLOITSCAN_AI_CONCURRENCY;
8847
+ if (!raw) return DEFAULT_MAX_CONCURRENT;
8848
+ const n = parseInt(raw, 10);
8849
+ if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_CONCURRENT;
8850
+ return Math.min(n, 20);
8851
+ })();
8843
8852
  var SEVERITY_PRIORITY = {
8844
8853
  critical: 0,
8845
8854
  high: 1,
@@ -8915,32 +8924,72 @@ async function filterFalsePositives(findings, fileContents) {
8915
8924
  return empty;
8916
8925
  }
8917
8926
  const fpMap = /* @__PURE__ */ new Map();
8927
+ let reviewedAny = false;
8928
+ let firstError = null;
8929
+ let failedBatches = 0;
8930
+ const tasks = [];
8918
8931
  for (const [file, fileFindings] of byFile) {
8919
8932
  const content = fileContents.get(file);
8920
8933
  if (!content) continue;
8921
8934
  for (let i = 0; i < fileFindings.length; i += MAX_FINDINGS_PER_BATCH) {
8922
- const batch = fileFindings.slice(i, i + MAX_FINDINGS_PER_BATCH);
8935
+ tasks.push({ batch: fileFindings.slice(i, i + MAX_FINDINGS_PER_BATCH), content });
8936
+ }
8937
+ }
8938
+ const reviewBatch = async (task) => {
8939
+ try {
8940
+ const { batch, content } = task;
8923
8941
  const prompt = buildReviewPrompt(batch, content);
8924
- try {
8925
- const response = await client.messages.create({
8942
+ const response = await client.messages.create(
8943
+ {
8926
8944
  model: "claude-haiku-4-5-20251001",
8927
8945
  max_tokens: 1024,
8928
8946
  system: REVIEW_SYSTEM_PROMPT,
8929
8947
  messages: [{ role: "user", content: prompt }]
8930
- });
8931
- const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
8932
- const results = parseReviewResponse(text);
8933
- for (const r of results) {
8934
- if (r.verdict === "fp" && r.index >= 0 && r.index < batch.length) {
8935
- const globalIndex = toReview.indexOf(batch[r.index]);
8936
- if (globalIndex !== -1) {
8937
- fpMap.set(globalIndex, r.reason);
8938
- }
8948
+ },
8949
+ // Cap a single call well under any serverless function timeout — the
8950
+ // SDK default is 10 minutes, long enough for one hung connection to
8951
+ // hold a worker until the platform SIGKILLs the whole scan request
8952
+ // (which would skip the graceful-degradation fallback). A timeout
8953
+ // turns a stuck batch into an unreviewed batch, handled below.
8954
+ { timeout: 2e4 }
8955
+ );
8956
+ const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
8957
+ const results = parseReviewResponse(text);
8958
+ reviewedAny = true;
8959
+ for (const r of results) {
8960
+ if (r.verdict === "fp" && r.index >= 0 && r.index < batch.length) {
8961
+ const globalIndex = toReview.indexOf(batch[r.index]);
8962
+ if (globalIndex !== -1) {
8963
+ fpMap.set(globalIndex, r.reason);
8939
8964
  }
8940
8965
  }
8941
- } catch {
8942
- continue;
8943
8966
  }
8967
+ } catch (err) {
8968
+ failedBatches++;
8969
+ if (!firstError) firstError = err;
8970
+ }
8971
+ };
8972
+ let next = 0;
8973
+ const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
8974
+ const workers = Array.from({ length: workerCount }, async () => {
8975
+ while (next < tasks.length) {
8976
+ const cur = next++;
8977
+ await reviewBatch(tasks[cur]);
8978
+ }
8979
+ });
8980
+ await Promise.all(workers);
8981
+ if (firstError) {
8982
+ const msg = firstError instanceof Error ? firstError.message : String(firstError);
8983
+ if (!reviewedAny) {
8984
+ console.error(
8985
+ "[ai-fp-filter] AI review unavailable \u2014 every model call failed; returning unreviewed findings:",
8986
+ msg
8987
+ );
8988
+ } else {
8989
+ console.warn(
8990
+ `[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed; those findings were not reviewed:`,
8991
+ msg
8992
+ );
8944
8993
  }
8945
8994
  }
8946
8995
  const filtered = toReview.filter((_, i) => !fpMap.has(i));
@@ -8951,7 +9000,7 @@ async function filterFalsePositives(findings, fileContents) {
8951
9000
  return {
8952
9001
  findings: [...filtered, ...overflow],
8953
9002
  filteredFindings,
8954
- aiReviewed: true,
9003
+ aiReviewed: reviewedAny,
8955
9004
  removedCount: fpMap.size,
8956
9005
  totalBefore
8957
9006
  };