xploitscan-shared-rules 2.4.2 → 2.4.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 +42 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +40 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,7 @@ __export(index_exports, {
|
|
|
52
52
|
astMatch: () => astMatch,
|
|
53
53
|
buildProjectContext: () => buildProjectContext,
|
|
54
54
|
buildQualityContext: () => buildQualityContext,
|
|
55
|
+
buildReviewPrompt: () => buildReviewPrompt,
|
|
55
56
|
buildTaintMap: () => buildTaintMap,
|
|
56
57
|
calculateGrade: () => calculateGrade,
|
|
57
58
|
callSpreads: () => callSpreads,
|
|
@@ -124,6 +125,7 @@ __export(index_exports, {
|
|
|
124
125
|
nextPublicSecret: () => nextPublicSecret,
|
|
125
126
|
noRateLimiting: () => noRateLimiting,
|
|
126
127
|
normalizeScanPath: () => normalizeScanPath,
|
|
128
|
+
packReviewBatches: () => packReviewBatches,
|
|
127
129
|
parseFile: () => parseFile,
|
|
128
130
|
parseScanTarget: () => parseScanTarget,
|
|
129
131
|
parseSupabaseConfig: () => parseSupabaseConfig,
|
|
@@ -4671,6 +4673,9 @@ For each finding, respond ONLY with a JSON array. No other text.
|
|
|
4671
4673
|
Each element: {"index": <number>, "verdict": "real" or "fp", "reason": "<1 sentence>"}`;
|
|
4672
4674
|
var MAX_FINDINGS_PER_BATCH = 15;
|
|
4673
4675
|
var MAX_CONTEXT_LINES = 10;
|
|
4676
|
+
var MAX_CONTEXT_LINE_CHARS = 300;
|
|
4677
|
+
var MAX_BATCH_PROMPT_CHARS = 2e4;
|
|
4678
|
+
var MAX_FIELD_CHARS = 500;
|
|
4674
4679
|
var DEFAULT_MAX_TOTAL_FINDINGS = 200;
|
|
4675
4680
|
var MAX_TOTAL_FINDINGS = (() => {
|
|
4676
4681
|
const raw = process.env.XPLOITSCAN_AI_FILTER_MAX;
|
|
@@ -4708,6 +4713,11 @@ var SEVERITY_PRIORITY = {
|
|
|
4708
4713
|
low: 3,
|
|
4709
4714
|
info: 4
|
|
4710
4715
|
};
|
|
4716
|
+
function truncateChars(text, max) {
|
|
4717
|
+
if (text.length <= max) return text;
|
|
4718
|
+
if (max <= 1) return "\u2026";
|
|
4719
|
+
return `${text.slice(0, max - 1)}\u2026`;
|
|
4720
|
+
}
|
|
4711
4721
|
function getExpandedContext(content, line, contextLines = MAX_CONTEXT_LINES) {
|
|
4712
4722
|
const lines = content.split("\n");
|
|
4713
4723
|
const start = Math.max(0, line - 1 - contextLines);
|
|
@@ -4715,7 +4725,7 @@ function getExpandedContext(content, line, contextLines = MAX_CONTEXT_LINES) {
|
|
|
4715
4725
|
return lines.slice(start, end).map((l, i) => {
|
|
4716
4726
|
const lineNum = start + i + 1;
|
|
4717
4727
|
const marker = lineNum === line ? ">>>" : " ";
|
|
4718
|
-
return `${marker} ${lineNum} | ${l}`;
|
|
4728
|
+
return `${marker} ${lineNum} | ${truncateChars(l, MAX_CONTEXT_LINE_CHARS)}`;
|
|
4719
4729
|
}).join("\n");
|
|
4720
4730
|
}
|
|
4721
4731
|
function buildReviewPrompt(findings, fileContent) {
|
|
@@ -4728,8 +4738,8 @@ Rule: ${f.rule} (${f.title})
|
|
|
4728
4738
|
Severity: ${f.severity}
|
|
4729
4739
|
File: ${f.file}
|
|
4730
4740
|
Line: ${f.line}
|
|
4731
|
-
Description: ${f.description}
|
|
4732
|
-
Suggested fix: ${f.fix || "N/A"}
|
|
4741
|
+
Description: ${truncateChars(f.description || "", MAX_FIELD_CHARS)}
|
|
4742
|
+
Suggested fix: ${truncateChars(f.fix || "N/A", MAX_FIELD_CHARS)}
|
|
4733
4743
|
|
|
4734
4744
|
Code context:
|
|
4735
4745
|
${context}
|
|
@@ -4739,6 +4749,23 @@ ${context}
|
|
|
4739
4749
|
|
|
4740
4750
|
${parts.join("\n")}`;
|
|
4741
4751
|
}
|
|
4752
|
+
function packReviewBatches(fileFindings, content) {
|
|
4753
|
+
const batches = [];
|
|
4754
|
+
let current = [];
|
|
4755
|
+
for (const f of fileFindings) {
|
|
4756
|
+
const candidate = [...current, f];
|
|
4757
|
+
const overCount = candidate.length > MAX_FINDINGS_PER_BATCH;
|
|
4758
|
+
const overChars = current.length > 0 && buildReviewPrompt(candidate, content).length > MAX_BATCH_PROMPT_CHARS;
|
|
4759
|
+
if (overCount || overChars) {
|
|
4760
|
+
if (current.length > 0) batches.push(current);
|
|
4761
|
+
current = [f];
|
|
4762
|
+
continue;
|
|
4763
|
+
}
|
|
4764
|
+
current = candidate;
|
|
4765
|
+
}
|
|
4766
|
+
if (current.length > 0) batches.push(current);
|
|
4767
|
+
return batches;
|
|
4768
|
+
}
|
|
4742
4769
|
function parseReviewResponse(text) {
|
|
4743
4770
|
try {
|
|
4744
4771
|
const cleaned = text.replace(/```json\n?/g, "").replace(/```\n?/g, "").trim();
|
|
@@ -4792,8 +4819,8 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
4792
4819
|
for (const [file, fileFindings] of byFile) {
|
|
4793
4820
|
const content = fileContents.get(file);
|
|
4794
4821
|
if (!content) continue;
|
|
4795
|
-
for (
|
|
4796
|
-
tasks.push({ batch
|
|
4822
|
+
for (const batch of packReviewBatches(fileFindings, content)) {
|
|
4823
|
+
tasks.push({ batch, content });
|
|
4797
4824
|
}
|
|
4798
4825
|
}
|
|
4799
4826
|
const reviewBatch = async (task) => {
|
|
@@ -4806,6 +4833,14 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
4806
4833
|
try {
|
|
4807
4834
|
const remaining = Math.max(1, deadlineMs - Date.now());
|
|
4808
4835
|
const prompt = buildReviewPrompt(batch, content);
|
|
4836
|
+
console.info(
|
|
4837
|
+
`[ai-fp-filter] batch prompt ${prompt.length} chars (~${Math.ceil(prompt.length / 4)} tokens), ${batch.length} finding(s)`
|
|
4838
|
+
);
|
|
4839
|
+
if (prompt.length > MAX_BATCH_PROMPT_CHARS) {
|
|
4840
|
+
console.warn(
|
|
4841
|
+
`[ai-fp-filter] batch prompt ${prompt.length} chars exceeds ${MAX_BATCH_PROMPT_CHARS} cap (single oversized finding after truncation)`
|
|
4842
|
+
);
|
|
4843
|
+
}
|
|
4809
4844
|
const response = await client.messages.create(
|
|
4810
4845
|
{
|
|
4811
4846
|
model: MODEL_TRIAGE,
|
|
@@ -9619,6 +9654,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
9619
9654
|
astMatch,
|
|
9620
9655
|
buildProjectContext,
|
|
9621
9656
|
buildQualityContext,
|
|
9657
|
+
buildReviewPrompt,
|
|
9622
9658
|
buildTaintMap,
|
|
9623
9659
|
calculateGrade,
|
|
9624
9660
|
callSpreads,
|
|
@@ -9691,6 +9727,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
9691
9727
|
nextPublicSecret,
|
|
9692
9728
|
noRateLimiting,
|
|
9693
9729
|
normalizeScanPath,
|
|
9730
|
+
packReviewBatches,
|
|
9694
9731
|
parseFile,
|
|
9695
9732
|
parseScanTarget,
|
|
9696
9733
|
parseSupabaseConfig,
|