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.cjs +65 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +65 -24
- 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,
|
|
@@ -8892,7 +8900,7 @@ function parseReviewResponse(text) {
|
|
|
8892
8900
|
}
|
|
8893
8901
|
}
|
|
8894
8902
|
async function filterFalsePositives(findings, fileContents) {
|
|
8895
|
-
const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length };
|
|
8903
|
+
const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length, unreviewedCount: 0 };
|
|
8896
8904
|
if (!process.env.ANTHROPIC_API_KEY) return empty;
|
|
8897
8905
|
if (findings.length === 0) return empty;
|
|
8898
8906
|
const prioritized = [...findings].sort((a, b) => {
|
|
@@ -8918,41 +8926,73 @@ 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
|
+
let unreviewedCount = 0;
|
|
8931
|
+
const tasks = [];
|
|
8921
8932
|
for (const [file, fileFindings] of byFile) {
|
|
8922
8933
|
const content = fileContents.get(file);
|
|
8923
8934
|
if (!content) continue;
|
|
8924
8935
|
for (let i = 0; i < fileFindings.length; i += MAX_FINDINGS_PER_BATCH) {
|
|
8925
|
-
|
|
8936
|
+
tasks.push({ batch: fileFindings.slice(i, i + MAX_FINDINGS_PER_BATCH), content });
|
|
8937
|
+
}
|
|
8938
|
+
}
|
|
8939
|
+
const reviewBatch = async (task) => {
|
|
8940
|
+
const { batch, content } = task;
|
|
8941
|
+
try {
|
|
8926
8942
|
const prompt = buildReviewPrompt(batch, content);
|
|
8927
|
-
|
|
8928
|
-
|
|
8943
|
+
const response = await client.messages.create(
|
|
8944
|
+
{
|
|
8929
8945
|
model: "claude-haiku-4-5-20251001",
|
|
8930
8946
|
max_tokens: 1024,
|
|
8931
8947
|
system: REVIEW_SYSTEM_PROMPT,
|
|
8932
8948
|
messages: [{ role: "user", content: prompt }]
|
|
8933
|
-
}
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8949
|
+
},
|
|
8950
|
+
// Cap a single call well under any serverless function timeout — the
|
|
8951
|
+
// SDK default is 10 minutes, long enough for one hung connection to
|
|
8952
|
+
// hold a worker until the platform SIGKILLs the whole scan request
|
|
8953
|
+
// (which would skip the graceful-degradation fallback). A timeout
|
|
8954
|
+
// turns a stuck batch into an unreviewed batch, handled below.
|
|
8955
|
+
{ timeout: 2e4 }
|
|
8956
|
+
);
|
|
8957
|
+
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
8958
|
+
const results = parseReviewResponse(text);
|
|
8959
|
+
reviewedAny = true;
|
|
8960
|
+
for (const r of results) {
|
|
8961
|
+
if (r.verdict === "fp" && r.index >= 0 && r.index < batch.length) {
|
|
8962
|
+
const globalIndex = toReview.indexOf(batch[r.index]);
|
|
8963
|
+
if (globalIndex !== -1) {
|
|
8964
|
+
fpMap.set(globalIndex, r.reason);
|
|
8943
8965
|
}
|
|
8944
8966
|
}
|
|
8945
|
-
} catch (err) {
|
|
8946
|
-
if (!firstError) firstError = err;
|
|
8947
|
-
continue;
|
|
8948
8967
|
}
|
|
8968
|
+
} catch (err) {
|
|
8969
|
+
failedBatches++;
|
|
8970
|
+
unreviewedCount += batch.length;
|
|
8971
|
+
if (!firstError) firstError = err;
|
|
8972
|
+
}
|
|
8973
|
+
};
|
|
8974
|
+
let next = 0;
|
|
8975
|
+
const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
|
|
8976
|
+
const workers = Array.from({ length: workerCount }, async () => {
|
|
8977
|
+
while (next < tasks.length) {
|
|
8978
|
+
const cur = next++;
|
|
8979
|
+
await reviewBatch(tasks[cur]);
|
|
8980
|
+
}
|
|
8981
|
+
});
|
|
8982
|
+
await Promise.all(workers);
|
|
8983
|
+
if (firstError) {
|
|
8984
|
+
const msg = firstError instanceof Error ? firstError.message : String(firstError);
|
|
8985
|
+
if (!reviewedAny) {
|
|
8986
|
+
console.error(
|
|
8987
|
+
"[ai-fp-filter] AI review unavailable \u2014 every model call failed; returning unreviewed findings:",
|
|
8988
|
+
msg
|
|
8989
|
+
);
|
|
8990
|
+
} else {
|
|
8991
|
+
console.warn(
|
|
8992
|
+
`[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed; those findings were not reviewed:`,
|
|
8993
|
+
msg
|
|
8994
|
+
);
|
|
8949
8995
|
}
|
|
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
8996
|
}
|
|
8957
8997
|
const filtered = toReview.filter((_, i) => !fpMap.has(i));
|
|
8958
8998
|
const filteredFindings = [];
|
|
@@ -8964,7 +9004,8 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
8964
9004
|
filteredFindings,
|
|
8965
9005
|
aiReviewed: reviewedAny,
|
|
8966
9006
|
removedCount: fpMap.size,
|
|
8967
|
-
totalBefore
|
|
9007
|
+
totalBefore,
|
|
9008
|
+
unreviewedCount
|
|
8968
9009
|
};
|
|
8969
9010
|
}
|
|
8970
9011
|
|