xploitscan-shared-rules 1.14.2 → 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 +60 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -8650,41 +8658,71 @@ 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
|
+
const tasks = [];
|
|
8653
8663
|
for (const [file, fileFindings] of byFile) {
|
|
8654
8664
|
const content = fileContents.get(file);
|
|
8655
8665
|
if (!content) continue;
|
|
8656
8666
|
for (let i = 0; i < fileFindings.length; i += MAX_FINDINGS_PER_BATCH) {
|
|
8657
|
-
|
|
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;
|
|
8658
8673
|
const prompt = buildReviewPrompt(batch, content);
|
|
8659
|
-
|
|
8660
|
-
|
|
8674
|
+
const response = await client.messages.create(
|
|
8675
|
+
{
|
|
8661
8676
|
model: "claude-haiku-4-5-20251001",
|
|
8662
8677
|
max_tokens: 1024,
|
|
8663
8678
|
system: REVIEW_SYSTEM_PROMPT,
|
|
8664
8679
|
messages: [{ role: "user", content: prompt }]
|
|
8665
|
-
}
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
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);
|
|
8675
8696
|
}
|
|
8676
8697
|
}
|
|
8677
|
-
} catch (err) {
|
|
8678
|
-
if (!firstError) firstError = err;
|
|
8679
|
-
continue;
|
|
8680
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
|
+
);
|
|
8681
8725
|
}
|
|
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
8726
|
}
|
|
8689
8727
|
const filtered = toReview.filter((_, i) => !fpMap.has(i));
|
|
8690
8728
|
const filteredFindings = [];
|