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.cjs
CHANGED
|
@@ -8841,6 +8841,14 @@ var MAX_TOTAL_FINDINGS = (() => {
|
|
|
8841
8841
|
if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_TOTAL_FINDINGS;
|
|
8842
8842
|
return Math.min(n, 1e3);
|
|
8843
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
|
+
})();
|
|
8844
8852
|
var SEVERITY_PRIORITY = {
|
|
8845
8853
|
critical: 0,
|
|
8846
8854
|
high: 1,
|
|
@@ -8918,41 +8926,71 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
8918
8926
|
const fpMap = /* @__PURE__ */ new Map();
|
|
8919
8927
|
let reviewedAny = false;
|
|
8920
8928
|
let firstError = null;
|
|
8929
|
+
let failedBatches = 0;
|
|
8930
|
+
const tasks = [];
|
|
8921
8931
|
for (const [file, fileFindings] of byFile) {
|
|
8922
8932
|
const content = fileContents.get(file);
|
|
8923
8933
|
if (!content) continue;
|
|
8924
8934
|
for (let i = 0; i < fileFindings.length; i += MAX_FINDINGS_PER_BATCH) {
|
|
8925
|
-
|
|
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;
|
|
8926
8941
|
const prompt = buildReviewPrompt(batch, content);
|
|
8927
|
-
|
|
8928
|
-
|
|
8942
|
+
const response = await client.messages.create(
|
|
8943
|
+
{
|
|
8929
8944
|
model: "claude-haiku-4-5-20251001",
|
|
8930
8945
|
max_tokens: 1024,
|
|
8931
8946
|
system: REVIEW_SYSTEM_PROMPT,
|
|
8932
8947
|
messages: [{ role: "user", content: prompt }]
|
|
8933
|
-
}
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
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);
|
|
8943
8964
|
}
|
|
8944
8965
|
}
|
|
8945
|
-
} catch (err) {
|
|
8946
|
-
if (!firstError) firstError = err;
|
|
8947
|
-
continue;
|
|
8948
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
|
+
);
|
|
8949
8993
|
}
|
|
8950
|
-
}
|
|
8951
|
-
if (!reviewedAny && firstError) {
|
|
8952
|
-
console.error(
|
|
8953
|
-
"[ai-fp-filter] AI review unavailable \u2014 every model call failed; returning unreviewed findings:",
|
|
8954
|
-
firstError instanceof Error ? firstError.message : String(firstError)
|
|
8955
|
-
);
|
|
8956
8994
|
}
|
|
8957
8995
|
const filtered = toReview.filter((_, i) => !fpMap.has(i));
|
|
8958
8996
|
const filteredFindings = [];
|