xploitscan-shared-rules 2.4.20 → 2.4.22
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/ai-status-constants.cjs +99 -0
- package/dist/ai-status-constants.cjs.map +1 -0
- package/dist/ai-status-constants.d.cts +12 -0
- package/dist/ai-status-constants.d.ts +12 -0
- package/dist/ai-status-constants.js +69 -0
- package/dist/ai-status-constants.js.map +1 -0
- package/dist/index.cjs +1320 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -5
- package/dist/index.d.ts +91 -5
- package/dist/index.js +1271 -82
- package/dist/index.js.map +1 -1
- package/dist/suppression.cjs +878 -0
- package/dist/suppression.cjs.map +1 -0
- package/dist/suppression.d.cts +163 -0
- package/dist/suppression.d.ts +163 -0
- package/dist/suppression.js +807 -0
- package/dist/suppression.js.map +1 -0
- package/package.json +13 -2
package/dist/index.cjs
CHANGED
|
@@ -30,35 +30,61 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
AI_REASONS: () => AI_REASONS,
|
|
34
|
+
AI_STATUSES: () => AI_STATUSES,
|
|
35
|
+
AI_SURFACES: () => AI_SURFACES,
|
|
36
|
+
BILLING_WEBHOOK_UNMATCHED_KEYS: () => BILLING_WEBHOOK_UNMATCHED_KEYS,
|
|
33
37
|
CHECKABLE_CLAIMS: () => CHECKABLE_CLAIMS,
|
|
34
38
|
DOTENV_ASSIGN_RE: () => DOTENV_ASSIGN_RE,
|
|
35
39
|
FREE_RULE_COUNT: () => FREE_RULE_COUNT,
|
|
36
40
|
GRADE_FINDINGS_PER_RULE: () => GRADE_FINDINGS_PER_RULE,
|
|
37
41
|
INTENT_EXPECTATIONS: () => INTENT_EXPECTATIONS,
|
|
42
|
+
MAX_IGNORE_BYTES: () => MAX_IGNORE_BYTES,
|
|
43
|
+
MAX_IGNORE_LINES: () => MAX_IGNORE_LINES,
|
|
44
|
+
MAX_SUPPRESSED_LIST: () => MAX_SUPPRESSED_LIST,
|
|
45
|
+
MAX_WARNING_CAP: () => MAX_WARNING_CAP,
|
|
38
46
|
MODEL_ANALYSIS: () => MODEL_ANALYSIS,
|
|
39
47
|
MODEL_POLICY_REVIEWED: () => MODEL_POLICY_REVIEWED,
|
|
40
48
|
MODEL_REVIEW_INTERVAL_DAYS: () => MODEL_REVIEW_INTERVAL_DAYS,
|
|
41
49
|
MODEL_TEMPERATURE: () => MODEL_TEMPERATURE,
|
|
42
50
|
MODEL_TRIAGE: () => MODEL_TRIAGE,
|
|
51
|
+
NESTED_IGNORE_WARNING: () => NESTED_IGNORE_WARNING,
|
|
43
52
|
NON_APP_PATH_PATTERNS: () => NON_APP_PATH_PATTERNS,
|
|
53
|
+
PLAN_CAUSES: () => PLAN_CAUSES,
|
|
54
|
+
PLAN_UNVERIFIED_NOTICE: () => PLAN_UNVERIFIED_NOTICE,
|
|
44
55
|
PRO_RULE_COUNT: () => PRO_RULE_COUNT,
|
|
45
56
|
PUBLIC_ENV_PREFIX_RE: () => PUBLIC_ENV_PREFIX_RE,
|
|
46
57
|
QUALITY_EXAMPLES: () => QUALITY_EXAMPLES,
|
|
58
|
+
RULE_ID_PATTERN: () => RULE_ID_PATTERN,
|
|
47
59
|
RULE_IMPACTS: () => RULE_IMPACTS,
|
|
48
60
|
SCANNER_VERSION: () => SCANNER_VERSION,
|
|
61
|
+
SCAN_AI_DEGRADED_KEYS: () => SCAN_AI_DEGRADED_KEYS,
|
|
62
|
+
SCAN_TOKEN_NULL_KEYS: () => SCAN_TOKEN_NULL_KEYS,
|
|
49
63
|
SERVER_ACTION_WRITE_RE: () => SERVER_ACTION_WRITE_RE,
|
|
64
|
+
SUPPRESSION_REGEXES: () => SUPPRESSION_REGEXES,
|
|
50
65
|
TEST_FILE_PATTERN: () => TEST_FILE_PATTERN,
|
|
51
66
|
TOTAL_RULE_COUNT: () => TOTAL_RULE_COUNT,
|
|
67
|
+
WEBHOOK_EVENT_TYPES: () => WEBHOOK_EVENT_TYPES,
|
|
68
|
+
WEBHOOK_REASONS: () => WEBHOOK_REASONS,
|
|
69
|
+
aiStatusLine: () => aiStatusLine,
|
|
52
70
|
allRules: () => allRules,
|
|
71
|
+
applySuppressions: () => applySuppressions,
|
|
53
72
|
assessHeaders: () => assessHeaders,
|
|
54
73
|
astMatch: () => astMatch,
|
|
74
|
+
attachInlineSuppressed: () => attachInlineSuppressed,
|
|
75
|
+
attachScanSuppression: () => attachScanSuppression,
|
|
76
|
+
billingWebhookUnmatchedProps: () => billingWebhookUnmatchedProps,
|
|
77
|
+
bucketFiles: () => bucketFiles,
|
|
78
|
+
buildMarkerIndex: () => buildMarkerIndex,
|
|
55
79
|
buildProjectContext: () => buildProjectContext,
|
|
56
80
|
buildQualityContext: () => buildQualityContext,
|
|
57
81
|
buildReviewPrompt: () => buildReviewPrompt,
|
|
58
82
|
buildTaintMap: () => buildTaintMap,
|
|
59
83
|
calculateGrade: () => calculateGrade,
|
|
60
84
|
callSpreads: () => callSpreads,
|
|
85
|
+
capWarnings: () => capWarnings,
|
|
61
86
|
checkIntent: () => checkIntent,
|
|
87
|
+
clampCount: () => clampCount,
|
|
62
88
|
classifyExposure: () => classifyExposure,
|
|
63
89
|
classifyPublicEnvVar: () => classifyPublicEnvVar,
|
|
64
90
|
classifyStatement: () => classifyStatement,
|
|
@@ -66,6 +92,7 @@ __export(index_exports, {
|
|
|
66
92
|
complianceMap: () => complianceMap,
|
|
67
93
|
consoleLogProduction: () => consoleLogProduction,
|
|
68
94
|
corsWildcard: () => corsWildcard,
|
|
95
|
+
countPass: () => countPass,
|
|
69
96
|
dangerousInnerHTML: () => dangerousInnerHTML,
|
|
70
97
|
deduplicateFindings: () => deduplicateFindings,
|
|
71
98
|
detectBuilder: () => detectBuilder,
|
|
@@ -110,19 +137,26 @@ __export(index_exports, {
|
|
|
110
137
|
isMethodCall: () => isMethodCall,
|
|
111
138
|
isPrivateAddress: () => isPrivateAddress,
|
|
112
139
|
isProtectedFromAiRemoval: () => isProtectedFromAiRemoval,
|
|
140
|
+
isRootIgnorePath: () => isRootIgnorePath,
|
|
141
|
+
isRuleScopedIgnoreLine: () => isRuleScopedIgnoreLine,
|
|
113
142
|
isSbomPath: () => isSbomPath,
|
|
114
143
|
isServerSideFile: () => isServerSideFile,
|
|
115
144
|
isServerTarget: () => isServerTarget,
|
|
116
145
|
isTestFile: () => isTestFile,
|
|
117
146
|
isTestPath: () => isTestPath,
|
|
118
147
|
isUngradedFinding: () => isUngradedFinding,
|
|
148
|
+
isUnscopedOverBroadLine: () => isUnscopedOverBroadLine,
|
|
119
149
|
isVendoredFinding: () => isVendoredFinding,
|
|
120
150
|
isVendoredPath: () => isVendoredPath,
|
|
151
|
+
isWellFormedRuleId: () => isWellFormedRuleId,
|
|
121
152
|
lineNumberAt: () => lineNumberAt,
|
|
122
153
|
lineTextAt: () => lineTextAt,
|
|
154
|
+
markerCoversLine: () => markerCoversLine,
|
|
123
155
|
maskComments: () => maskComments,
|
|
124
156
|
maskOutboundAuthNoise: () => maskOutboundAuthNoise,
|
|
125
157
|
maskSecretValue: () => maskSecretValue,
|
|
158
|
+
maskStringLiterals: () => maskStringLiterals,
|
|
159
|
+
matchIgnore: () => matchIgnore,
|
|
126
160
|
missingAuthMiddleware: () => missingAuthMiddleware,
|
|
127
161
|
missingCSP: () => missingCSP,
|
|
128
162
|
missingErrorBoundary: () => missingErrorBoundary,
|
|
@@ -134,36 +168,51 @@ __export(index_exports, {
|
|
|
134
168
|
normalizeScanPath: () => normalizeScanPath,
|
|
135
169
|
packReviewBatches: () => packReviewBatches,
|
|
136
170
|
parseFile: () => parseFile,
|
|
171
|
+
parseIgnoreFile: () => parseIgnoreFile,
|
|
172
|
+
parseIgnoreSources: () => parseIgnoreSources,
|
|
173
|
+
parseMarkers: () => parseMarkers,
|
|
137
174
|
parseScanTarget: () => parseScanTarget,
|
|
138
175
|
parseSupabaseConfig: () => parseSupabaseConfig,
|
|
176
|
+
perCallTimeoutMs: () => perCallTimeoutMs,
|
|
177
|
+
planCause: () => planCause,
|
|
178
|
+
publicSuppressedRecord: () => publicSuppressedRecord,
|
|
139
179
|
qualityRules: () => qualityRules,
|
|
180
|
+
readInlineSuppressed: () => readInlineSuppressed,
|
|
181
|
+
readScanSuppression: () => readScanSuppression,
|
|
140
182
|
replaceBlockComments: () => replaceBlockComments,
|
|
141
183
|
routeForFile: () => routeForFile,
|
|
142
184
|
runCustomRules: () => runCustomRules,
|
|
185
|
+
scanAiDegradedProps: () => scanAiDegradedProps,
|
|
143
186
|
scanConfigs: () => scanConfigs,
|
|
144
187
|
scanDependencies: () => scanDependencies,
|
|
145
188
|
scanEntropy: () => scanEntropy,
|
|
146
189
|
scanMultiFile: () => scanMultiFile,
|
|
147
190
|
scanQuality: () => scanQuality,
|
|
191
|
+
scanTokenNullProps: () => scanTokenNullProps,
|
|
148
192
|
sqlInjection: () => sqlInjection,
|
|
149
193
|
stripeWebhookUnprotected: () => stripeWebhookUnprotected,
|
|
150
194
|
supabaseFunctionName: () => supabaseFunctionName,
|
|
151
195
|
supabaseNoRLS: () => supabaseNoRLS,
|
|
196
|
+
suppressionSummary: () => suppressionSummary,
|
|
197
|
+
toAiDegraded: () => toAiDegraded,
|
|
152
198
|
todoLeftInCode: () => todoLeftInCode,
|
|
153
199
|
tryParse: () => tryParse,
|
|
200
|
+
unknownAiStatus: () => unknownAiStatus,
|
|
154
201
|
unmeasuredQualityRules: () => unmeasuredQualityRules,
|
|
155
202
|
unvalidatedRedirect: () => unvalidatedRedirect,
|
|
156
203
|
vc001TestFixtureSeverity: () => vc001TestFixtureSeverity,
|
|
157
204
|
vendoredReason: () => vendoredReason,
|
|
158
205
|
visitBinary: () => visitBinary,
|
|
159
206
|
visitCalls: () => visitCalls,
|
|
207
|
+
warningForUpload: () => warningForUpload,
|
|
208
|
+
warningLine: () => warningLine,
|
|
160
209
|
weakHashing: () => weakHashing,
|
|
161
210
|
xssVulnerability: () => xssVulnerability
|
|
162
211
|
});
|
|
163
212
|
module.exports = __toCommonJS(index_exports);
|
|
164
213
|
|
|
165
214
|
// src/version.ts
|
|
166
|
-
var SCANNER_VERSION = "2.4.
|
|
215
|
+
var SCANNER_VERSION = "2.4.22";
|
|
167
216
|
|
|
168
217
|
// src/snippet.ts
|
|
169
218
|
var cacheContent = null;
|
|
@@ -235,18 +284,16 @@ function deduplicateFindings(findings) {
|
|
|
235
284
|
}
|
|
236
285
|
|
|
237
286
|
// src/silencing.ts
|
|
238
|
-
function isInlineSilenced(
|
|
239
|
-
|
|
240
|
-
const matchLineNum = content.substring(0, matchIndex).split("\n").length - 1;
|
|
241
|
-
return isLineSilenced(lines, matchLineNum, ruleId);
|
|
287
|
+
function isInlineSilenced(_content, _matchIndex, _ruleId) {
|
|
288
|
+
return false;
|
|
242
289
|
}
|
|
243
290
|
function isLineSilenced(lines, lineIdx, ruleId) {
|
|
244
291
|
const matchLine = lines[lineIdx] ?? "";
|
|
245
292
|
const marker = new RegExp(`(?://|/\\*|#|--)\\s*(?:${ruleId}|scanner)-OK\\b`, "i");
|
|
246
293
|
if (marker.test(matchLine)) return true;
|
|
247
294
|
const COMMENT_LINE = /^\s*[{(]?\s*(?:\/\/|#|\/\*|\*|--)/;
|
|
248
|
-
const
|
|
249
|
-
for (let i = lineIdx - 1, seen = 0; i >= 0 && seen <
|
|
295
|
+
const MAX_BLOCK_LINES2 = 20;
|
|
296
|
+
for (let i = lineIdx - 1, seen = 0; i >= 0 && seen < MAX_BLOCK_LINES2; i--, seen++) {
|
|
250
297
|
const line = lines[i] ?? "";
|
|
251
298
|
if (marker.test(line)) return true;
|
|
252
299
|
if (!COMMENT_LINE.test(line)) break;
|
|
@@ -254,6 +301,774 @@ function isLineSilenced(lines, lineIdx, ruleId) {
|
|
|
254
301
|
return false;
|
|
255
302
|
}
|
|
256
303
|
|
|
304
|
+
// src/suppression.ts
|
|
305
|
+
var import_ignore = __toESM(require("ignore"), 1);
|
|
306
|
+
var MAX_IGNORE_BYTES = 64 * 1024;
|
|
307
|
+
var MAX_IGNORE_LINES = 2e3;
|
|
308
|
+
var MAX_IGNORE_LINE_LEN = 1024;
|
|
309
|
+
var MAX_JUSTIFICATION = 200;
|
|
310
|
+
var MAX_WARNING_CAP = 20;
|
|
311
|
+
var MAX_SUPPRESSED_LIST = 500;
|
|
312
|
+
var MAX_COUNT = 1e3;
|
|
313
|
+
var MAX_BLOCK_LINES = 20;
|
|
314
|
+
var NESTED_IGNORE_WARNING = "nested .xploitscanignore ignored (only the root file is read here)";
|
|
315
|
+
var MARKER_SYNTAX = "use <ID>-OK inside a comment";
|
|
316
|
+
var RULE_ID_PATTERN = /^(?:[A-Za-z]{2,8}\d{0,4}|GL:[A-Za-z0-9-]{1,64}|scanner)$/i;
|
|
317
|
+
var SUPPRESSION_REGEXES = [RULE_ID_PATTERN];
|
|
318
|
+
var INLINE = /* @__PURE__ */ Symbol.for("xploitscan.inlineSuppressed");
|
|
319
|
+
function utf8ByteLength(text) {
|
|
320
|
+
return new TextEncoder().encode(text).length;
|
|
321
|
+
}
|
|
322
|
+
function isWellFormedRuleId(id) {
|
|
323
|
+
return RULE_ID_PATTERN.test(id);
|
|
324
|
+
}
|
|
325
|
+
function isBuiltinRuleId(id) {
|
|
326
|
+
if (!isWellFormedRuleId(id)) return false;
|
|
327
|
+
const u = id.toUpperCase();
|
|
328
|
+
if (u === "ENTROPY" || u === "SCANNER" || u === "AI") return true;
|
|
329
|
+
if (/^CFG\d{1,4}$/.test(u)) return true;
|
|
330
|
+
if (/^MFA\d{1,4}$/.test(u)) return true;
|
|
331
|
+
if (/^QA\d{1,4}$/.test(u)) return true;
|
|
332
|
+
if (/^GL:/i.test(id)) return true;
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
function clampCount(value, max = MAX_COUNT) {
|
|
336
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
337
|
+
if (!Number.isFinite(n) || n < 0) return 0;
|
|
338
|
+
return Math.min(max, Math.floor(n));
|
|
339
|
+
}
|
|
340
|
+
function capWarnings(warnings, cap = MAX_WARNING_CAP) {
|
|
341
|
+
if (warnings.length <= cap) return { shown: warnings, extra: 0 };
|
|
342
|
+
return { shown: warnings.slice(0, cap), extra: warnings.length - cap };
|
|
343
|
+
}
|
|
344
|
+
function suppressionSummary(inline, ignoreFile) {
|
|
345
|
+
const n = inline + ignoreFile;
|
|
346
|
+
const noun = n === 1 ? "finding" : "findings";
|
|
347
|
+
return `${n} ${noun} suppressed (${inline} inline marker, ${ignoreFile} ignore file)`;
|
|
348
|
+
}
|
|
349
|
+
function warningForUpload(w) {
|
|
350
|
+
return { code: w.code, ruleIds: [...w.ruleIds], count: w.count };
|
|
351
|
+
}
|
|
352
|
+
function warningLine(w) {
|
|
353
|
+
if (w.code === "nested_ignored") return `${w.file} ${NESTED_IGNORE_WARNING}`;
|
|
354
|
+
const where = w.file ? `${w.file}:${w.line}` : `line ${w.line}`;
|
|
355
|
+
const ids = w.ruleIds.length ? ` ${w.ruleIds.join(",")}` : "";
|
|
356
|
+
const syntax = w.code === "unrecognized_marker" || w.code === "space_before_ok" ? ` ${MARKER_SYNTAX}` : "";
|
|
357
|
+
const more = w.code === "over_broad" ? ` suppresses all findings in ${w.count} files` : "";
|
|
358
|
+
return `${where} ${w.code}${ids}${more}${syntax}`;
|
|
359
|
+
}
|
|
360
|
+
function attachInlineSuppressed(findings, suppressed) {
|
|
361
|
+
Object.defineProperty(findings, INLINE, { value: suppressed, enumerable: false });
|
|
362
|
+
return findings;
|
|
363
|
+
}
|
|
364
|
+
function readInlineSuppressed(findings) {
|
|
365
|
+
if (!findings || typeof findings !== "object") return [];
|
|
366
|
+
const value = findings[INLINE];
|
|
367
|
+
return Array.isArray(value) ? value : [];
|
|
368
|
+
}
|
|
369
|
+
function publicSuppressedRecord(finding) {
|
|
370
|
+
const suppression = finding.suppression;
|
|
371
|
+
const info = suppression && typeof suppression === "object" ? {
|
|
372
|
+
kind: suppression.kind,
|
|
373
|
+
source: suppression.source,
|
|
374
|
+
ruleToken: suppression.ruleToken,
|
|
375
|
+
justification: String(suppression.justification ?? "").slice(
|
|
376
|
+
0,
|
|
377
|
+
MAX_JUSTIFICATION
|
|
378
|
+
),
|
|
379
|
+
declaredIn: suppression.declaredIn
|
|
380
|
+
} : void 0;
|
|
381
|
+
return {
|
|
382
|
+
rule: finding.rule,
|
|
383
|
+
file: finding.file,
|
|
384
|
+
line: finding.line,
|
|
385
|
+
severity: finding.severity,
|
|
386
|
+
...info ? { suppression: info } : {}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function warn(file, line, code, ruleIds = [], count = 1) {
|
|
390
|
+
return { code, file, line, ruleIds, count };
|
|
391
|
+
}
|
|
392
|
+
function fateOf(id, opts) {
|
|
393
|
+
if (isBuiltinRuleId(id)) return "ok";
|
|
394
|
+
const upper = id.toUpperCase();
|
|
395
|
+
const pro = opts?.proIds;
|
|
396
|
+
if (pro && (pro.has(upper) || pro.has(id))) {
|
|
397
|
+
return opts?.tier === "pro" ? "ok" : "pro-silent";
|
|
398
|
+
}
|
|
399
|
+
if (!opts?.knownIds) return "ok";
|
|
400
|
+
if (opts.knownIds.has(upper) || opts.knownIds.has(id)) return "ok";
|
|
401
|
+
return "unknown";
|
|
402
|
+
}
|
|
403
|
+
function idEndingAt(text, end) {
|
|
404
|
+
const window = text.slice(Math.max(0, end - 80), end);
|
|
405
|
+
const gl = window.match(/GL:[A-Za-z0-9-]{1,64}$/i);
|
|
406
|
+
if (gl) {
|
|
407
|
+
const id2 = gl[0];
|
|
408
|
+
if (isWellFormedRuleId(id2)) return { id: id2, start: end - id2.length };
|
|
409
|
+
}
|
|
410
|
+
const plain = window.match(/[A-Za-z]{2,8}\d{0,4}$/);
|
|
411
|
+
if (!plain) return null;
|
|
412
|
+
const id = plain[0];
|
|
413
|
+
if (id.toLowerCase() === "ok") return null;
|
|
414
|
+
if (!isWellFormedRuleId(id)) return null;
|
|
415
|
+
return { id, start: end - id.length };
|
|
416
|
+
}
|
|
417
|
+
function idListBefore(text, end) {
|
|
418
|
+
const first = idEndingAt(text, end);
|
|
419
|
+
if (!first) return null;
|
|
420
|
+
const ids = [first.id];
|
|
421
|
+
let cursor = first.start;
|
|
422
|
+
while (cursor > 0) {
|
|
423
|
+
let j = cursor;
|
|
424
|
+
while (j > 0 && (text[j - 1] === " " || text[j - 1] === " ")) j--;
|
|
425
|
+
if (j > 0 && text[j - 1] === ",") {
|
|
426
|
+
j--;
|
|
427
|
+
while (j > 0 && (text[j - 1] === " " || text[j - 1] === " ")) j--;
|
|
428
|
+
} else if (j === cursor) {
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
const prev = idEndingAt(text, j);
|
|
432
|
+
if (!prev || prev.start + prev.id.length !== j) break;
|
|
433
|
+
ids.unshift(prev.id);
|
|
434
|
+
cursor = prev.start;
|
|
435
|
+
}
|
|
436
|
+
return { ids, start: cursor };
|
|
437
|
+
}
|
|
438
|
+
function nextMarkerStart(rest) {
|
|
439
|
+
const lower = rest.toLowerCase();
|
|
440
|
+
let from = 0;
|
|
441
|
+
while (from < lower.length) {
|
|
442
|
+
const at = lower.indexOf("-ok", from);
|
|
443
|
+
if (at < 0) return -1;
|
|
444
|
+
const after = at + 3;
|
|
445
|
+
const next = lower[after];
|
|
446
|
+
if (next !== void 0 && /[A-Za-z0-9_]/.test(next)) {
|
|
447
|
+
from = at + 1;
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
let i = at - 1;
|
|
451
|
+
while (i >= 0 && /[A-Za-z0-9:-]/.test(lower[i] ?? "")) i--;
|
|
452
|
+
let start = i + 1;
|
|
453
|
+
while (start < at && !/[A-Za-z0-9]/.test(lower[start] ?? "")) start++;
|
|
454
|
+
if (start < at) return start;
|
|
455
|
+
from = at + 1;
|
|
456
|
+
}
|
|
457
|
+
return -1;
|
|
458
|
+
}
|
|
459
|
+
function parseCommentMarkers(comment, file, line, opts) {
|
|
460
|
+
const warnings = [];
|
|
461
|
+
const ids = [];
|
|
462
|
+
let justification = "";
|
|
463
|
+
const lower = comment.toLowerCase();
|
|
464
|
+
if (lower.includes("xploitscan") || lower.includes("ignore-line")) {
|
|
465
|
+
warnings.push(warn(file, line, "unrecognized_marker"));
|
|
466
|
+
}
|
|
467
|
+
let from = 0;
|
|
468
|
+
while (from < comment.length) {
|
|
469
|
+
const okAt = lower.indexOf("-ok", from);
|
|
470
|
+
const typoAt = lower.indexOf("-0k", from);
|
|
471
|
+
if (okAt < 0 && typoAt < 0) break;
|
|
472
|
+
const useTypo = typoAt >= 0 && (okAt < 0 || typoAt < okAt);
|
|
473
|
+
const at = useTypo ? typoAt : okAt;
|
|
474
|
+
const after = at + 3;
|
|
475
|
+
const boundary = after >= comment.length || !/[A-Za-z0-9]/.test(comment[after]);
|
|
476
|
+
if (!boundary) {
|
|
477
|
+
from = at + 1;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (useTypo) {
|
|
481
|
+
const listed2 = idListBefore(comment, at);
|
|
482
|
+
warnings.push(
|
|
483
|
+
warn(
|
|
484
|
+
file,
|
|
485
|
+
line,
|
|
486
|
+
"unrecognized_marker",
|
|
487
|
+
listed2 ? listed2.ids.map((id) => id.toUpperCase()) : []
|
|
488
|
+
)
|
|
489
|
+
);
|
|
490
|
+
from = after;
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
const prev = at > 0 ? comment[at - 1] : "";
|
|
494
|
+
if (prev === " " || prev === " ") {
|
|
495
|
+
const listed2 = idListBefore(
|
|
496
|
+
comment.slice(0, at).trimEnd(),
|
|
497
|
+
comment.slice(0, at).trimEnd().length
|
|
498
|
+
);
|
|
499
|
+
warnings.push(
|
|
500
|
+
warn(file, line, "space_before_ok", listed2 ? listed2.ids.map((id) => id.toUpperCase()) : [])
|
|
501
|
+
);
|
|
502
|
+
from = after;
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
const listed = idListBefore(comment, at);
|
|
506
|
+
if (!listed) {
|
|
507
|
+
warnings.push(warn(file, line, "unrecognized_marker"));
|
|
508
|
+
from = after;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
let just = "";
|
|
512
|
+
if (comment[after] === ":") {
|
|
513
|
+
const rest = comment.slice(after + 1);
|
|
514
|
+
const next = nextMarkerStart(rest);
|
|
515
|
+
just = (next >= 0 ? rest.slice(0, next) : rest).trim().slice(0, MAX_JUSTIFICATION);
|
|
516
|
+
}
|
|
517
|
+
if (!justification && just) justification = just;
|
|
518
|
+
for (const id of listed.ids) {
|
|
519
|
+
const fate = fateOf(id, opts);
|
|
520
|
+
if (fate === "unknown") {
|
|
521
|
+
warnings.push(warn(file, line, "unknown_rule_id", [id.toUpperCase()]));
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (fate === "pro-silent") continue;
|
|
525
|
+
ids.push(id.toUpperCase());
|
|
526
|
+
}
|
|
527
|
+
from = after;
|
|
528
|
+
}
|
|
529
|
+
return { ids, justification, warnings };
|
|
530
|
+
}
|
|
531
|
+
function commentOpenerAt(chars, i) {
|
|
532
|
+
const a = chars[i] ?? "";
|
|
533
|
+
const b = chars[i + 1] ?? "";
|
|
534
|
+
const two = a + b;
|
|
535
|
+
if (two === "//") return { kind: "line", len: 2 };
|
|
536
|
+
if (two === "/*") return { kind: "block", len: 2 };
|
|
537
|
+
if (two + (chars[i + 2] ?? "") + (chars[i + 3] ?? "") === "<!--") return { kind: "html", len: 4 };
|
|
538
|
+
if (a === "#" && (i === 0 || /\s/.test(chars[i - 1] ?? ""))) return { kind: "line", len: 1 };
|
|
539
|
+
if (two === "--" && (i === 0 || /\s/.test(chars[i - 1] ?? ""))) return { kind: "line", len: 2 };
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
function maskStringLiterals(line) {
|
|
543
|
+
const chars = line.split("");
|
|
544
|
+
const n = chars.length;
|
|
545
|
+
let i = 0;
|
|
546
|
+
while (i < n) {
|
|
547
|
+
const opener = commentOpenerAt(chars, i);
|
|
548
|
+
if (opener) {
|
|
549
|
+
if (opener.kind === "line") break;
|
|
550
|
+
if (opener.kind === "block") {
|
|
551
|
+
const end2 = line.indexOf("*/", i + opener.len);
|
|
552
|
+
i = end2 < 0 ? n : end2 + 2;
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
const end = line.indexOf("-->", i + opener.len);
|
|
556
|
+
i = end < 0 ? n : end + 3;
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
const c = chars[i];
|
|
560
|
+
if (c === '"' || c === "'") {
|
|
561
|
+
const q = c;
|
|
562
|
+
chars[i] = " ";
|
|
563
|
+
i++;
|
|
564
|
+
while (i < n) {
|
|
565
|
+
if (chars[i] === "\\") {
|
|
566
|
+
chars[i] = " ";
|
|
567
|
+
if (i + 1 < n) chars[i + 1] = " ";
|
|
568
|
+
i += 2;
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
if (chars[i] === q) {
|
|
572
|
+
chars[i] = " ";
|
|
573
|
+
i++;
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
chars[i] = " ";
|
|
577
|
+
i++;
|
|
578
|
+
}
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
if (c === "`") {
|
|
582
|
+
chars[i] = " ";
|
|
583
|
+
i++;
|
|
584
|
+
let expr = 0;
|
|
585
|
+
while (i < n) {
|
|
586
|
+
if (expr === 0 && chars[i] === "\\") {
|
|
587
|
+
chars[i] = " ";
|
|
588
|
+
if (i + 1 < n) chars[i + 1] = " ";
|
|
589
|
+
i += 2;
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (expr === 0 && chars[i] === "`") {
|
|
593
|
+
chars[i] = " ";
|
|
594
|
+
i++;
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
if (expr === 0 && chars[i] === "$" && chars[i + 1] === "{") {
|
|
598
|
+
chars[i] = " ";
|
|
599
|
+
chars[i + 1] = " ";
|
|
600
|
+
expr = 1;
|
|
601
|
+
i += 2;
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
if (expr > 0 && chars[i] === "{") {
|
|
605
|
+
expr++;
|
|
606
|
+
i++;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (expr > 0 && chars[i] === "}") {
|
|
610
|
+
expr--;
|
|
611
|
+
if (expr === 0) chars[i] = " ";
|
|
612
|
+
i++;
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
if (expr === 0) chars[i] = " ";
|
|
616
|
+
i++;
|
|
617
|
+
}
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
i++;
|
|
621
|
+
}
|
|
622
|
+
return chars.join("");
|
|
623
|
+
}
|
|
624
|
+
function commentSpans(masked) {
|
|
625
|
+
const spans = [];
|
|
626
|
+
const n = masked.length;
|
|
627
|
+
let i = 0;
|
|
628
|
+
const code = true;
|
|
629
|
+
while (i < n) {
|
|
630
|
+
if (!code) {
|
|
631
|
+
i++;
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
const two = masked.slice(i, i + 2);
|
|
635
|
+
const four = masked.slice(i, i + 4);
|
|
636
|
+
if (four === "<!--") {
|
|
637
|
+
const end = masked.indexOf("-->", i + 4);
|
|
638
|
+
const stop = end < 0 ? n : end + 3;
|
|
639
|
+
spans.push([i, stop]);
|
|
640
|
+
i = stop;
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (two === "//") {
|
|
644
|
+
spans.push([i, n]);
|
|
645
|
+
break;
|
|
646
|
+
}
|
|
647
|
+
if (two === "/*") {
|
|
648
|
+
const end = masked.indexOf("*/", i + 2);
|
|
649
|
+
const stop = end < 0 ? n : end + 2;
|
|
650
|
+
spans.push([i, stop]);
|
|
651
|
+
i = stop;
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
if (masked[i] === "#" && (i === 0 || /\s/.test(masked[i - 1]))) {
|
|
655
|
+
spans.push([i, n]);
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
if (two === "--" && (i === 0 || /\s/.test(masked[i - 1]))) {
|
|
659
|
+
spans.push([i, n]);
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
i++;
|
|
663
|
+
}
|
|
664
|
+
const trimmed = masked.trim();
|
|
665
|
+
if (spans.length === 0 && (/^\*/.test(trimmed) || trimmed === "*/" || trimmed === "*/}" || trimmed === "-->")) {
|
|
666
|
+
spans.push([0, n]);
|
|
667
|
+
}
|
|
668
|
+
return spans;
|
|
669
|
+
}
|
|
670
|
+
function isBlankLine(line) {
|
|
671
|
+
return line.trim() === "";
|
|
672
|
+
}
|
|
673
|
+
function isCommentOnly(masked) {
|
|
674
|
+
const spans = commentSpans(masked);
|
|
675
|
+
if (spans.length === 0) return false;
|
|
676
|
+
const chars = masked.split("");
|
|
677
|
+
for (const [start, end] of spans) {
|
|
678
|
+
for (let i = start; i < end; i++) chars[i] = " ";
|
|
679
|
+
}
|
|
680
|
+
return /^[{}()\s]*$/.test(chars.join(""));
|
|
681
|
+
}
|
|
682
|
+
function targetLineFor(lines, maskedLines, markerLine) {
|
|
683
|
+
if (!isCommentOnly(maskedLines[markerLine] ?? "")) return markerLine;
|
|
684
|
+
let blanks = 0;
|
|
685
|
+
let comments = 0;
|
|
686
|
+
for (let i = markerLine + 1; i < lines.length; i++) {
|
|
687
|
+
if (isBlankLine(lines[i] ?? "")) {
|
|
688
|
+
blanks++;
|
|
689
|
+
if (blanks > 1) return null;
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
if (isCommentOnly(maskedLines[i] ?? "")) {
|
|
693
|
+
if (blanks > 0) return null;
|
|
694
|
+
comments++;
|
|
695
|
+
if (comments > MAX_BLOCK_LINES) return null;
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
return i;
|
|
699
|
+
}
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
function parseMarkers(lines, filePath = "", opts) {
|
|
703
|
+
const maskedLines = lines.map((line) => maskStringLiterals(line));
|
|
704
|
+
const markers = [];
|
|
705
|
+
const warnings = [];
|
|
706
|
+
for (let i = 0; i < lines.length; i++) {
|
|
707
|
+
const spans = commentSpans(maskedLines[i] ?? "");
|
|
708
|
+
if (spans.length === 0) continue;
|
|
709
|
+
const pieces = spans.map(([a, b]) => (maskedLines[i] ?? "").slice(a, b));
|
|
710
|
+
const parsed = parseCommentMarkers(pieces.join("\n"), filePath, i + 1, opts);
|
|
711
|
+
warnings.push(...parsed.warnings);
|
|
712
|
+
if (parsed.ids.length === 0) continue;
|
|
713
|
+
const target = targetLineFor(lines, maskedLines, i);
|
|
714
|
+
if (target === null) continue;
|
|
715
|
+
markers.push({
|
|
716
|
+
markerLine: i,
|
|
717
|
+
targetLine: target,
|
|
718
|
+
ruleIds: parsed.ids,
|
|
719
|
+
justification: parsed.justification,
|
|
720
|
+
declaredIn: `${filePath}:${i + 1}`
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
return { markers, warnings };
|
|
724
|
+
}
|
|
725
|
+
function buildMarkerIndex(lines, filePath = "", opts) {
|
|
726
|
+
const { markers, warnings } = parseMarkers(lines, filePath, opts);
|
|
727
|
+
const covers = (lineIdx, ruleId) => {
|
|
728
|
+
const want = ruleId.toUpperCase();
|
|
729
|
+
for (const marker of markers) {
|
|
730
|
+
if (marker.targetLine !== lineIdx) continue;
|
|
731
|
+
if (marker.ruleIds.includes("SCANNER") || marker.ruleIds.includes(want)) return marker;
|
|
732
|
+
}
|
|
733
|
+
return null;
|
|
734
|
+
};
|
|
735
|
+
return {
|
|
736
|
+
markers,
|
|
737
|
+
warnings,
|
|
738
|
+
covers(lineIdx, ruleId) {
|
|
739
|
+
return covers(lineIdx, ruleId) !== null;
|
|
740
|
+
},
|
|
741
|
+
info(lineIdx, ruleId) {
|
|
742
|
+
const hit = covers(lineIdx, ruleId);
|
|
743
|
+
if (!hit) return null;
|
|
744
|
+
const token = hit.ruleIds.includes(ruleId.toUpperCase()) ? ruleId.toUpperCase() : "SCANNER";
|
|
745
|
+
return { ruleToken: token, justification: hit.justification, declaredIn: hit.declaredIn };
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
function markerCoversLine(lines, lineIdx, ruleId) {
|
|
750
|
+
return buildMarkerIndex(lines, "").covers(lineIdx, ruleId);
|
|
751
|
+
}
|
|
752
|
+
function posix(p) {
|
|
753
|
+
return p.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
754
|
+
}
|
|
755
|
+
function isRootIgnorePath(filePath) {
|
|
756
|
+
return posix(filePath) === ".xploitscanignore";
|
|
757
|
+
}
|
|
758
|
+
function splitIgnoreLine(line) {
|
|
759
|
+
let i = 0;
|
|
760
|
+
while (i < line.length && (line[i] === " " || line[i] === " ")) i++;
|
|
761
|
+
if (i < line.length && line[i] === "#") {
|
|
762
|
+
return { code: "", comment: line.slice(i + 1).trim(), escaped: false };
|
|
763
|
+
}
|
|
764
|
+
let code = "";
|
|
765
|
+
let escaped = false;
|
|
766
|
+
for (let k = 0; k < line.length; k++) {
|
|
767
|
+
const c = line[k] ?? "";
|
|
768
|
+
if (c === "\\") {
|
|
769
|
+
escaped = true;
|
|
770
|
+
code += c;
|
|
771
|
+
if (k + 1 < line.length) {
|
|
772
|
+
code += line[k + 1] ?? "";
|
|
773
|
+
k++;
|
|
774
|
+
}
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
if (c === "#" && k > 0 && (line[k - 1] === " " || line[k - 1] === " ")) {
|
|
778
|
+
return { code: code.trimEnd(), comment: line.slice(k + 1).trim(), escaped };
|
|
779
|
+
}
|
|
780
|
+
code += c;
|
|
781
|
+
}
|
|
782
|
+
return { code: code.trim(), comment: "", escaped };
|
|
783
|
+
}
|
|
784
|
+
function peelRules(code) {
|
|
785
|
+
const parts = code.split(/[ \t]+/).filter(Boolean);
|
|
786
|
+
const rules = [];
|
|
787
|
+
while (parts.length > 1) {
|
|
788
|
+
const last = parts[parts.length - 1] ?? "";
|
|
789
|
+
const ids = last.split(",").map((s) => s.trim()).filter(Boolean);
|
|
790
|
+
if (ids.length === 0 || !ids.every((id) => isWellFormedRuleId(id))) break;
|
|
791
|
+
rules.unshift(...ids);
|
|
792
|
+
parts.pop();
|
|
793
|
+
}
|
|
794
|
+
const pattern = parts.join(" ");
|
|
795
|
+
const unscoped = rules.length === 0 && /\s/.test(code.trim());
|
|
796
|
+
return { pattern, rules: rules.length ? rules : null, unscoped };
|
|
797
|
+
}
|
|
798
|
+
function patternRejected(pattern) {
|
|
799
|
+
if (pattern.includes("\0")) return true;
|
|
800
|
+
if (/^[A-Za-z]:/.test(pattern)) return true;
|
|
801
|
+
const norm = pattern.replace(/\\/g, "/");
|
|
802
|
+
if (/^[A-Za-z]:/.test(norm)) return true;
|
|
803
|
+
const body = norm.replace(/^!/, "");
|
|
804
|
+
if (body.split("/").includes("..")) return true;
|
|
805
|
+
const bare = body.replace(/^\.\//, "");
|
|
806
|
+
if (/^\/[^/*?\]]+$/.test(bare) && !bare.slice(1).includes("/")) return true;
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
function isOverBroad(pattern, rules) {
|
|
810
|
+
if (pattern.startsWith("!")) return false;
|
|
811
|
+
const body = pattern.replace(/^\.\//, "").replace(/^\//, "");
|
|
812
|
+
const broad = body === "*" || body === "**" || body === "**/*";
|
|
813
|
+
const all = rules === null || rules.some((r) => r.toUpperCase() === "SCANNER");
|
|
814
|
+
return broad && all;
|
|
815
|
+
}
|
|
816
|
+
function compilePattern(pattern) {
|
|
817
|
+
const neg = pattern.startsWith("!");
|
|
818
|
+
const body = (neg ? pattern.slice(1) : pattern).replace(/^\.\//, "");
|
|
819
|
+
return (0, import_ignore.default)().add(body);
|
|
820
|
+
}
|
|
821
|
+
function parseIgnoreFile(text, dirRel = "", opts) {
|
|
822
|
+
const declared = opts?.declaredPath ?? (dirRel ? `${posix(dirRel)}/.xploitscanignore` : ".xploitscanignore");
|
|
823
|
+
const dir = posix(dirRel).replace(/\/$/, "");
|
|
824
|
+
if (text.includes("\0")) {
|
|
825
|
+
return { entries: [], warnings: [warn(declared, 1, "binary")], ignoredWhole: true };
|
|
826
|
+
}
|
|
827
|
+
const bytes = utf8ByteLength(text);
|
|
828
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
829
|
+
let rawLines = normalized.split("\n");
|
|
830
|
+
if (rawLines.length > 0 && rawLines[rawLines.length - 1] === "" && normalized.endsWith("\n")) {
|
|
831
|
+
rawLines = rawLines.slice(0, -1);
|
|
832
|
+
}
|
|
833
|
+
if (bytes > MAX_IGNORE_BYTES || rawLines.length > MAX_IGNORE_LINES) {
|
|
834
|
+
return { entries: [], warnings: [warn(declared, 1, "over_cap")], ignoredWhole: true };
|
|
835
|
+
}
|
|
836
|
+
const entries = [];
|
|
837
|
+
const warnings = [];
|
|
838
|
+
rawLines.forEach((raw, idx) => {
|
|
839
|
+
const lineNo = idx + 1;
|
|
840
|
+
if (raw.length > MAX_IGNORE_LINE_LEN) {
|
|
841
|
+
warnings.push(warn(declared, lineNo, "line_too_long"));
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const split = splitIgnoreLine(raw);
|
|
845
|
+
if (split.escaped) {
|
|
846
|
+
warnings.push(warn(declared, lineNo, "path_rejected"));
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const { code, comment } = split;
|
|
850
|
+
if (!code.trim() || code.trimStart().startsWith("#")) return;
|
|
851
|
+
const peeled = peelRules(code.trim());
|
|
852
|
+
if (!peeled.pattern) {
|
|
853
|
+
warnings.push(warn(declared, lineNo, "unrecognized_marker"));
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
if (patternRejected(peeled.pattern)) {
|
|
857
|
+
warnings.push(warn(declared, lineNo, "path_rejected"));
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
if (peeled.unscoped) {
|
|
861
|
+
warnings.push(warn(declared, lineNo, "unscoped_whitespace"));
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
const accepted = [];
|
|
865
|
+
for (const id of peeled.rules ?? []) {
|
|
866
|
+
const fate = fateOf(id, opts);
|
|
867
|
+
if (fate === "unknown") {
|
|
868
|
+
warnings.push(warn(declared, lineNo, "unknown_rule_id", [id.toUpperCase()]));
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
871
|
+
if (fate === "pro-silent") continue;
|
|
872
|
+
accepted.push(id.toUpperCase());
|
|
873
|
+
}
|
|
874
|
+
if (peeled.rules && accepted.length === 0) return;
|
|
875
|
+
const pattern = peeled.pattern.replace(/\\/g, "/");
|
|
876
|
+
let matcher;
|
|
877
|
+
try {
|
|
878
|
+
matcher = compilePattern(pattern);
|
|
879
|
+
} catch {
|
|
880
|
+
warnings.push(warn(declared, lineNo, "path_rejected"));
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
entries.push({
|
|
884
|
+
dirRel: dir,
|
|
885
|
+
pattern,
|
|
886
|
+
negated: pattern.startsWith("!"),
|
|
887
|
+
rules: peeled.rules ? new Set(accepted) : null,
|
|
888
|
+
justification: comment.slice(0, MAX_JUSTIFICATION),
|
|
889
|
+
declaredIn: `${declared}:${lineNo}`,
|
|
890
|
+
line: lineNo,
|
|
891
|
+
overBroad: isOverBroad(pattern, peeled.rules),
|
|
892
|
+
matcher
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
return { entries, warnings, ignoredWhole: false };
|
|
896
|
+
}
|
|
897
|
+
function parseIgnoreSources(sources, mode, opts) {
|
|
898
|
+
const entries = [];
|
|
899
|
+
const warnings = [];
|
|
900
|
+
const ordered = [...sources].sort((a, b) => posix(a.path).length - posix(b.path).length);
|
|
901
|
+
for (const source of ordered) {
|
|
902
|
+
const path = posix(source.path);
|
|
903
|
+
const root = isRootIgnorePath(path);
|
|
904
|
+
if (mode === "root-only" && !root) {
|
|
905
|
+
warnings.push(warn(path, 1, "nested_ignored"));
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
const dir = root ? "" : path.slice(0, Math.max(0, path.lastIndexOf("/")));
|
|
909
|
+
const parsed = parseIgnoreFile(source.text, dir, { ...opts, declaredPath: path });
|
|
910
|
+
entries.push(...parsed.entries);
|
|
911
|
+
warnings.push(...parsed.warnings);
|
|
912
|
+
}
|
|
913
|
+
return { entries, warnings };
|
|
914
|
+
}
|
|
915
|
+
function relativeTo(filePath, dirRel) {
|
|
916
|
+
const path = posix(filePath);
|
|
917
|
+
if (!dirRel) return path;
|
|
918
|
+
if (path === dirRel) return null;
|
|
919
|
+
if (path.startsWith(`${dirRel}/`)) return path.slice(dirRel.length + 1);
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
function matcherFor(entry) {
|
|
923
|
+
if (entry.matcher) return entry.matcher;
|
|
924
|
+
try {
|
|
925
|
+
entry.matcher = compilePattern(entry.pattern);
|
|
926
|
+
return entry.matcher;
|
|
927
|
+
} catch {
|
|
928
|
+
return null;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
function entryMatches(entry, filePath) {
|
|
932
|
+
const rel = relativeTo(filePath, entry.dirRel);
|
|
933
|
+
if (rel === null || rel === "") return false;
|
|
934
|
+
const matcher = matcherFor(entry);
|
|
935
|
+
if (!matcher) return false;
|
|
936
|
+
try {
|
|
937
|
+
return matcher.ignores(rel);
|
|
938
|
+
} catch {
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function matchIgnore(entries, filePath, ruleId) {
|
|
943
|
+
const rule = ruleId.toUpperCase();
|
|
944
|
+
let winner = null;
|
|
945
|
+
for (const entry of entries) {
|
|
946
|
+
if (!entryMatches(entry, filePath)) continue;
|
|
947
|
+
const applies = entry.rules === null || entry.rules.has("SCANNER") || entry.rules.has(rule);
|
|
948
|
+
if (!applies) continue;
|
|
949
|
+
winner = entry.negated ? null : entry;
|
|
950
|
+
}
|
|
951
|
+
return winner;
|
|
952
|
+
}
|
|
953
|
+
function filesMap(input) {
|
|
954
|
+
if (input instanceof Map) return input;
|
|
955
|
+
return new Map(Object.entries(input).map(([k, v]) => [posix(k), v]));
|
|
956
|
+
}
|
|
957
|
+
function applySuppressions(findings, input) {
|
|
958
|
+
const files = filesMap(input.filesByPath);
|
|
959
|
+
const opts = { knownIds: input.knownIds, proIds: input.proIds, tier: input.tier };
|
|
960
|
+
const entries = input.ignoreEntries ?? [];
|
|
961
|
+
const warnings = [];
|
|
962
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
963
|
+
const indexFor = (file) => {
|
|
964
|
+
const key = posix(file);
|
|
965
|
+
const cached = indexes.get(key);
|
|
966
|
+
if (cached) return cached;
|
|
967
|
+
const text = files.get(key) ?? "";
|
|
968
|
+
const folded = text.toLowerCase();
|
|
969
|
+
if (!folded.includes("-ok") && !folded.includes("-0k")) {
|
|
970
|
+
const empty = {
|
|
971
|
+
markers: [],
|
|
972
|
+
warnings: [],
|
|
973
|
+
covers: () => false,
|
|
974
|
+
info: () => null
|
|
975
|
+
};
|
|
976
|
+
indexes.set(key, empty);
|
|
977
|
+
return empty;
|
|
978
|
+
}
|
|
979
|
+
const built = buildMarkerIndex(text.split("\n"), key, opts);
|
|
980
|
+
indexes.set(key, built);
|
|
981
|
+
warnings.push(...built.warnings);
|
|
982
|
+
return built;
|
|
983
|
+
};
|
|
984
|
+
const direct = /* @__PURE__ */ new Map();
|
|
985
|
+
for (const finding of findings) {
|
|
986
|
+
const info = indexFor(finding.file).info(finding.line - 1, finding.rule);
|
|
987
|
+
if (!info) continue;
|
|
988
|
+
direct.set(finding, {
|
|
989
|
+
kind: "inSource",
|
|
990
|
+
source: "marker",
|
|
991
|
+
ruleToken: info.ruleToken,
|
|
992
|
+
justification: info.justification,
|
|
993
|
+
declaredIn: info.declaredIn
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
997
|
+
for (const file of files.keys()) seenFiles.add(posix(file));
|
|
998
|
+
for (const finding of findings) seenFiles.add(posix(finding.file));
|
|
999
|
+
for (const entry of entries) {
|
|
1000
|
+
if (!entry.overBroad) continue;
|
|
1001
|
+
let count = 0;
|
|
1002
|
+
for (const file of seenFiles) if (entryMatches(entry, file)) count++;
|
|
1003
|
+
if (count > 0)
|
|
1004
|
+
warnings.push(
|
|
1005
|
+
warn(entry.declaredIn.split(":")[0] ?? "", entry.line, "over_broad", [], count)
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
const kept = [];
|
|
1009
|
+
const suppressed = [];
|
|
1010
|
+
for (const finding of findings) {
|
|
1011
|
+
const marker = direct.get(finding);
|
|
1012
|
+
if (marker) {
|
|
1013
|
+
suppressed.push({ ...finding, suppression: marker });
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
const hit = matchIgnore(entries, finding.file, finding.rule);
|
|
1017
|
+
if (hit) {
|
|
1018
|
+
suppressed.push({
|
|
1019
|
+
...finding,
|
|
1020
|
+
suppression: {
|
|
1021
|
+
kind: "external",
|
|
1022
|
+
source: "ignore-file",
|
|
1023
|
+
ruleToken: finding.rule.toUpperCase(),
|
|
1024
|
+
justification: hit.justification,
|
|
1025
|
+
declaredIn: hit.declaredIn
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
kept.push(finding);
|
|
1031
|
+
}
|
|
1032
|
+
return { kept, suppressed, warnings };
|
|
1033
|
+
}
|
|
1034
|
+
function isRuleScopedIgnoreLine(line) {
|
|
1035
|
+
const split = splitIgnoreLine(line.replace(/\r$/, ""));
|
|
1036
|
+
if (split.escaped) return false;
|
|
1037
|
+
const { code } = split;
|
|
1038
|
+
if (!code.trim() || code.trimStart().startsWith("#")) return false;
|
|
1039
|
+
const peeled = peelRules(code.trim());
|
|
1040
|
+
return peeled.rules !== null && peeled.rules.length > 0 && !patternRejected(peeled.pattern);
|
|
1041
|
+
}
|
|
1042
|
+
function isUnscopedOverBroadLine(line) {
|
|
1043
|
+
const split = splitIgnoreLine(line.replace(/\r$/, ""));
|
|
1044
|
+
if (split.escaped) return false;
|
|
1045
|
+
const { code } = split;
|
|
1046
|
+
if (!code.trim() || code.trimStart().startsWith("#")) return false;
|
|
1047
|
+
const peeled = peelRules(code.trim());
|
|
1048
|
+
if (peeled.rules && peeled.rules.length > 0) return false;
|
|
1049
|
+
return isOverBroad(peeled.pattern, null);
|
|
1050
|
+
}
|
|
1051
|
+
var SCAN_META = /* @__PURE__ */ Symbol.for("xploitscan.scanSuppression");
|
|
1052
|
+
function attachScanSuppression(findings, meta) {
|
|
1053
|
+
Object.defineProperty(findings, SCAN_META, { value: meta, enumerable: false });
|
|
1054
|
+
return findings;
|
|
1055
|
+
}
|
|
1056
|
+
function readScanSuppression(findings) {
|
|
1057
|
+
if (!findings || typeof findings !== "object") return null;
|
|
1058
|
+
const value = findings[SCAN_META];
|
|
1059
|
+
if (!value || typeof value !== "object") return null;
|
|
1060
|
+
return value;
|
|
1061
|
+
}
|
|
1062
|
+
function countPass(inlineAlready, suppressed) {
|
|
1063
|
+
let ignoreFile = 0;
|
|
1064
|
+
let inline = inlineAlready;
|
|
1065
|
+
for (const item of suppressed) {
|
|
1066
|
+
if (item.suppression.source === "ignore-file") ignoreFile++;
|
|
1067
|
+
else inline++;
|
|
1068
|
+
}
|
|
1069
|
+
return { inline, ignoreFile };
|
|
1070
|
+
}
|
|
1071
|
+
|
|
257
1072
|
// src/models.ts
|
|
258
1073
|
var MODEL_ANALYSIS = "claude-sonnet-5";
|
|
259
1074
|
var MODEL_TRIAGE = "claude-haiku-5-5";
|
|
@@ -2037,18 +2852,8 @@ function isInsideFixMessage(content, matchIndex) {
|
|
|
2037
2852
|
const lineText = lineTextAt(content, matchIndex);
|
|
2038
2853
|
return /(?:fix|description|message|suggestion|hint|help|example|doc|comment)\s*[:=]\s*["'`]/i.test(lineText) || /return\s*["'`].*\b(?:Use|Replace|Add|Move|Set|Enable|Disable|Never|Don't|Do not|Instead)\b/i.test(lineText);
|
|
2039
2854
|
}
|
|
2040
|
-
function filterSilenced(matches,
|
|
2041
|
-
|
|
2042
|
-
const lines = content.split("\n");
|
|
2043
|
-
const silencedByLine = /* @__PURE__ */ new Map();
|
|
2044
|
-
return matches.filter((m) => {
|
|
2045
|
-
let silenced = silencedByLine.get(m.line);
|
|
2046
|
-
if (silenced === void 0) {
|
|
2047
|
-
silenced = isLineSilenced(lines, m.line - 1, ruleId);
|
|
2048
|
-
silencedByLine.set(m.line, silenced);
|
|
2049
|
-
}
|
|
2050
|
-
return !silenced;
|
|
2051
|
-
});
|
|
2855
|
+
function filterSilenced(matches, _content, _ruleId) {
|
|
2856
|
+
return matches;
|
|
2052
2857
|
}
|
|
2053
2858
|
function lineStartOffsets(content) {
|
|
2054
2859
|
const starts = [0];
|
|
@@ -4098,7 +4903,6 @@ var unvalidatedRedirect = {
|
|
|
4098
4903
|
let m;
|
|
4099
4904
|
let commentLineStart = -1;
|
|
4100
4905
|
let commentLine = false;
|
|
4101
|
-
let silenceLines;
|
|
4102
4906
|
while ((m = navPattern.exec(content)) !== null) {
|
|
4103
4907
|
const navLineStart = content.lastIndexOf("\n", m.index - 1) + 1;
|
|
4104
4908
|
if (navLineStart !== commentLineStart) {
|
|
@@ -4111,7 +4915,6 @@ var unvalidatedRedirect = {
|
|
|
4111
4915
|
const isPureLiteral = /^["'`][^"'`]*["'`]$/.test(value);
|
|
4112
4916
|
if (!hasInterpolation && isPureLiteral) continue;
|
|
4113
4917
|
const line = lineNumberAt(content, m.index);
|
|
4114
|
-
if (isLineSilenced(silenceLines ??= content.split("\n"), line - 1, "VC016")) continue;
|
|
4115
4918
|
matches.push({
|
|
4116
4919
|
rule: "VC016",
|
|
4117
4920
|
title: unvalidatedRedirect.title,
|
|
@@ -5340,7 +6143,6 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
5340
6143
|
const sbomFile = isSbomPath(filePath);
|
|
5341
6144
|
const vendoredFile = isVendoredPath(filePath);
|
|
5342
6145
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
5343
|
-
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
5344
6146
|
for (const rule of ruleset) {
|
|
5345
6147
|
if (disabledRules.includes(rule.id)) continue;
|
|
5346
6148
|
if (sbomFile && rule.category !== "Secrets") continue;
|
|
@@ -5349,9 +6151,6 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
5349
6151
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
5350
6152
|
const onTestPath = isTestPath(filePath);
|
|
5351
6153
|
for (const match of matches) {
|
|
5352
|
-
if (silenceableLines && isLineSilenced(silenceableLines, match.line - 1, match.rule)) {
|
|
5353
|
-
continue;
|
|
5354
|
-
}
|
|
5355
6154
|
const live = isLive({
|
|
5356
6155
|
rule: match.rule,
|
|
5357
6156
|
category: match.category,
|
|
@@ -5380,7 +6179,10 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
5380
6179
|
});
|
|
5381
6180
|
}
|
|
5382
6181
|
}
|
|
5383
|
-
|
|
6182
|
+
const deduped = deduplicateFindings(findings);
|
|
6183
|
+
if (!/-OK\b/i.test(content)) return deduped;
|
|
6184
|
+
const applied = applySuppressions(deduped, { filesByPath: { [filePath]: content } });
|
|
6185
|
+
return attachInlineSuppressed(applied.kept, applied.suppressed);
|
|
5384
6186
|
}
|
|
5385
6187
|
|
|
5386
6188
|
// src/rule-counts.ts
|
|
@@ -5847,6 +6649,7 @@ function entropySecretValues(filePath, content) {
|
|
|
5847
6649
|
}
|
|
5848
6650
|
function scanEntropyFiles(files, collect) {
|
|
5849
6651
|
const findings = [];
|
|
6652
|
+
const inlineDropped = [];
|
|
5850
6653
|
for (const { path: filePath, content } of files) {
|
|
5851
6654
|
if (SKIP_FILES.test(filePath)) continue;
|
|
5852
6655
|
if (SKIP_FILENAMES.test(filePath)) continue;
|
|
@@ -5860,6 +6663,8 @@ function scanEntropyFiles(files, collect) {
|
|
|
5860
6663
|
const vendored = isVendoredPath(filePath);
|
|
5861
6664
|
const dotenv = isDotenvPath(filePath) && !DOTENV_EXAMPLE_RE.test(filePath);
|
|
5862
6665
|
const lines = content.split("\n");
|
|
6666
|
+
const folded = content.toLowerCase();
|
|
6667
|
+
const markerIndex = folded.includes("-ok") || folded.includes("-0k") ? buildMarkerIndex(lines, filePath) : null;
|
|
5863
6668
|
let verificationDepth = -1;
|
|
5864
6669
|
let braceDepth = 0;
|
|
5865
6670
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -5958,7 +6763,6 @@ function scanEntropyFiles(files, collect) {
|
|
|
5958
6763
|
}
|
|
5959
6764
|
let safeWords;
|
|
5960
6765
|
let verificationMeta;
|
|
5961
|
-
let silenced;
|
|
5962
6766
|
let snippet;
|
|
5963
6767
|
const seenValues = /* @__PURE__ */ new Set();
|
|
5964
6768
|
for (const { value, beforeAssign, dotenvName, variableName, contextFrom, contextTo } of candidates) {
|
|
@@ -6002,8 +6806,21 @@ function scanEntropyFiles(files, collect) {
|
|
|
6002
6806
|
if (dotenvName && /(?:^|_)IDS?$/i.test(dotenvName) && !isSecretVariableName(dotenvName)) continue;
|
|
6003
6807
|
const isLikelySecret = isSecretVariableName(varName) || publicEnv?.secret === true;
|
|
6004
6808
|
if (entropy < 4.5 && !isLikelySecret) continue;
|
|
6005
|
-
if (
|
|
6006
|
-
|
|
6809
|
+
if (markerIndex?.covers(i, "ENTROPY")) {
|
|
6810
|
+
inlineDropped.push({
|
|
6811
|
+
id: `ENTROPY-${filePath}:${i + 1}`,
|
|
6812
|
+
rule: "ENTROPY",
|
|
6813
|
+
severity: "high",
|
|
6814
|
+
title: "High-Entropy String Detected (Possible Secret)",
|
|
6815
|
+
description: "",
|
|
6816
|
+
file: filePath,
|
|
6817
|
+
line: i + 1,
|
|
6818
|
+
snippet: "",
|
|
6819
|
+
category: "Secrets",
|
|
6820
|
+
source: "custom"
|
|
6821
|
+
});
|
|
6822
|
+
continue;
|
|
6823
|
+
}
|
|
6007
6824
|
collect?.push(value);
|
|
6008
6825
|
const masked = maskSecretValue(value);
|
|
6009
6826
|
if (snippet === void 0) snippet = getSnippet2(lines, i + 1);
|
|
@@ -6029,7 +6846,256 @@ function scanEntropyFiles(files, collect) {
|
|
|
6029
6846
|
}
|
|
6030
6847
|
}
|
|
6031
6848
|
}
|
|
6032
|
-
return findings;
|
|
6849
|
+
return attachInlineSuppressed(findings, inlineDropped);
|
|
6850
|
+
}
|
|
6851
|
+
|
|
6852
|
+
// src/ai-status-constants.ts
|
|
6853
|
+
var AI_STATUSES = ["reviewed", "partial", "skipped", "failed", "unknown"];
|
|
6854
|
+
var AI_REASONS = [
|
|
6855
|
+
"no_api_key",
|
|
6856
|
+
"client_init",
|
|
6857
|
+
"capped",
|
|
6858
|
+
"budget_timeout",
|
|
6859
|
+
"model_bad_output",
|
|
6860
|
+
"model_error",
|
|
6861
|
+
"missing_content",
|
|
6862
|
+
"exception",
|
|
6863
|
+
"opted_out",
|
|
6864
|
+
"auth_failed",
|
|
6865
|
+
"jti_missing",
|
|
6866
|
+
"token_unverified",
|
|
6867
|
+
"pro_rules_unavailable",
|
|
6868
|
+
"engine_unavailable",
|
|
6869
|
+
"upload_failed",
|
|
6870
|
+
"upload_blocked",
|
|
6871
|
+
"upload_duplicate",
|
|
6872
|
+
"persist_failed",
|
|
6873
|
+
"quality_unavailable",
|
|
6874
|
+
"intent_unavailable",
|
|
6875
|
+
"not_supported",
|
|
6876
|
+
"token_secret_missing",
|
|
6877
|
+
"rate_limited",
|
|
6878
|
+
"jti_unavailable",
|
|
6879
|
+
"credit_error",
|
|
6880
|
+
"daily_limit",
|
|
6881
|
+
"signed_out"
|
|
6882
|
+
];
|
|
6883
|
+
var AI_SURFACES = ["upload", "cli", "action", "app", "api", "mcp", "web", "save"];
|
|
6884
|
+
var PLAN_CAUSES = [
|
|
6885
|
+
"missing",
|
|
6886
|
+
"malformed",
|
|
6887
|
+
"expired",
|
|
6888
|
+
"revoked",
|
|
6889
|
+
"network",
|
|
6890
|
+
"upstream_5xx",
|
|
6891
|
+
"unknown"
|
|
6892
|
+
];
|
|
6893
|
+
var WEBHOOK_REASONS = [
|
|
6894
|
+
"no_metadata_user",
|
|
6895
|
+
"malformed_user",
|
|
6896
|
+
"unknown_user",
|
|
6897
|
+
"user_bound_other_customer",
|
|
6898
|
+
"race_no_row",
|
|
6899
|
+
"deleted_unmatched",
|
|
6900
|
+
"clerk_lookup_failed"
|
|
6901
|
+
];
|
|
6902
|
+
var WEBHOOK_EVENT_TYPES = [
|
|
6903
|
+
"checkout.session.completed",
|
|
6904
|
+
"customer.subscription.created",
|
|
6905
|
+
"customer.subscription.updated",
|
|
6906
|
+
"customer.subscription.deleted",
|
|
6907
|
+
"invoice.paid",
|
|
6908
|
+
"invoice.payment_failed",
|
|
6909
|
+
"created",
|
|
6910
|
+
"updated"
|
|
6911
|
+
];
|
|
6912
|
+
|
|
6913
|
+
// src/ai-status.ts
|
|
6914
|
+
var PLAN_UNVERIFIED_NOTICE = "Couldn't verify your plan, scanned with free rules only.";
|
|
6915
|
+
var FAIL_REASONS = /* @__PURE__ */ new Set([
|
|
6916
|
+
"budget_timeout",
|
|
6917
|
+
"model_error",
|
|
6918
|
+
"model_bad_output",
|
|
6919
|
+
"auth_failed",
|
|
6920
|
+
"exception",
|
|
6921
|
+
"client_init"
|
|
6922
|
+
]);
|
|
6923
|
+
function clampCount2(raw) {
|
|
6924
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) return 0;
|
|
6925
|
+
return Math.min(Math.trunc(raw), 1e6);
|
|
6926
|
+
}
|
|
6927
|
+
function isStatus(raw) {
|
|
6928
|
+
return typeof raw === "string" && AI_STATUSES.includes(raw);
|
|
6929
|
+
}
|
|
6930
|
+
function isReason(raw) {
|
|
6931
|
+
return typeof raw === "string" && AI_REASONS.includes(raw);
|
|
6932
|
+
}
|
|
6933
|
+
function isSurface(raw) {
|
|
6934
|
+
return typeof raw === "string" && AI_SURFACES.includes(raw);
|
|
6935
|
+
}
|
|
6936
|
+
function bucketFiles(n) {
|
|
6937
|
+
if (typeof n !== "number" || !Number.isFinite(n) || n <= 0) return "0";
|
|
6938
|
+
const v = Math.trunc(n);
|
|
6939
|
+
if (v < 5) return "1-4";
|
|
6940
|
+
if (v < 20) return "5-19";
|
|
6941
|
+
return "20+";
|
|
6942
|
+
}
|
|
6943
|
+
function planCause(specific) {
|
|
6944
|
+
switch (specific) {
|
|
6945
|
+
case "secret_missing":
|
|
6946
|
+
return "missing";
|
|
6947
|
+
case "bad_shape":
|
|
6948
|
+
case "sig_mismatch":
|
|
6949
|
+
case "sig_length_mismatch":
|
|
6950
|
+
case "hmac_error":
|
|
6951
|
+
case "payload_parse_error":
|
|
6952
|
+
case "uid_or_tier_wrong_type":
|
|
6953
|
+
return "malformed";
|
|
6954
|
+
case "expired":
|
|
6955
|
+
case "exp_missing_or_nan":
|
|
6956
|
+
return "expired";
|
|
6957
|
+
case "tier_not_paid_unknown_value":
|
|
6958
|
+
case "http_401":
|
|
6959
|
+
case "http_403":
|
|
6960
|
+
return "revoked";
|
|
6961
|
+
case "no_cached_bundle_and_network_error":
|
|
6962
|
+
case "timeout":
|
|
6963
|
+
case "network":
|
|
6964
|
+
return "network";
|
|
6965
|
+
case "http_5xx":
|
|
6966
|
+
case "upstream_5xx":
|
|
6967
|
+
return "upstream_5xx";
|
|
6968
|
+
default:
|
|
6969
|
+
return "unknown";
|
|
6970
|
+
}
|
|
6971
|
+
}
|
|
6972
|
+
function toAiDegraded(input = {}) {
|
|
6973
|
+
const total = clampCount2(input.total);
|
|
6974
|
+
let reviewed = clampCount2(input.reviewed);
|
|
6975
|
+
let capped = clampCount2(input.capped);
|
|
6976
|
+
if (reviewed > total) reviewed = total;
|
|
6977
|
+
if (reviewed + capped > total) capped = total - reviewed;
|
|
6978
|
+
const unreviewed = total - reviewed - capped;
|
|
6979
|
+
let status = isStatus(input.status) ? input.status : "unknown";
|
|
6980
|
+
let reason = isReason(input.reason) ? input.reason : null;
|
|
6981
|
+
const eligible = total - capped;
|
|
6982
|
+
if (status === "reviewed" && reviewed !== eligible) {
|
|
6983
|
+
status = reviewed === 0 && reason != null && FAIL_REASONS.has(reason) ? "failed" : "partial";
|
|
6984
|
+
}
|
|
6985
|
+
if (status === "reviewed" && unreviewed > 0) status = "partial";
|
|
6986
|
+
if (status === "skipped" && reason != null && FAIL_REASONS.has(reason)) status = "failed";
|
|
6987
|
+
if (status === "reviewed" || status === "unknown") {
|
|
6988
|
+
if (status === "unknown") reason = null;
|
|
6989
|
+
}
|
|
6990
|
+
const modelStatus = reason === "model_error" && typeof input.modelStatus === "number" && Number.isFinite(input.modelStatus) ? Math.trunc(input.modelStatus) : null;
|
|
6991
|
+
return {
|
|
6992
|
+
status,
|
|
6993
|
+
reason,
|
|
6994
|
+
surface: isSurface(input.surface) ? input.surface : "cli",
|
|
6995
|
+
total,
|
|
6996
|
+
reviewed,
|
|
6997
|
+
unreviewed,
|
|
6998
|
+
capped,
|
|
6999
|
+
modelStatus
|
|
7000
|
+
};
|
|
7001
|
+
}
|
|
7002
|
+
function unknownAiStatus(surface = "save") {
|
|
7003
|
+
return toAiDegraded({ status: "unknown", reason: null, surface, total: 0, reviewed: 0, unreviewed: 0, capped: 0 });
|
|
7004
|
+
}
|
|
7005
|
+
function aiStatusLine(d) {
|
|
7006
|
+
const shown = Math.max(0, d.total - d.capped);
|
|
7007
|
+
switch (d.reason) {
|
|
7008
|
+
case "no_api_key":
|
|
7009
|
+
return "AI review skipped: no Anthropic API key is set.";
|
|
7010
|
+
case "opted_out":
|
|
7011
|
+
return "AI review skipped: user opted out.";
|
|
7012
|
+
case "not_supported":
|
|
7013
|
+
return "AI review not run on MCP scans.";
|
|
7014
|
+
case "auth_failed":
|
|
7015
|
+
return "AI review failed: the Anthropic API key was rejected.";
|
|
7016
|
+
case "capped":
|
|
7017
|
+
return `AI review covered the first ${shown} of ${d.total} findings.`;
|
|
7018
|
+
case "budget_timeout":
|
|
7019
|
+
return d.status === "failed" ? `AI review failed: every batch timed out (${d.reviewed} reviewed, ${d.unreviewed} unreviewed, ${d.capped} capped, ${d.total} total).` : `AI review was partial: the time limit ran out (${d.reviewed} reviewed of ${d.total}).`;
|
|
7020
|
+
case "client_init":
|
|
7021
|
+
return "AI review failed: the AI client could not start.";
|
|
7022
|
+
case "model_bad_output":
|
|
7023
|
+
return "AI review failed: the model returned unusable output.";
|
|
7024
|
+
case "model_error":
|
|
7025
|
+
return `AI review failed: the model request was rejected (HTTP ${d.modelStatus ?? "error"}).`;
|
|
7026
|
+
case "missing_content":
|
|
7027
|
+
return "AI review was partial: source content was missing for some findings.";
|
|
7028
|
+
case "exception":
|
|
7029
|
+
return "AI review failed: an unexpected error occurred.";
|
|
7030
|
+
case "token_secret_missing":
|
|
7031
|
+
return "AI review skipped: scan token verification is not configured.";
|
|
7032
|
+
case "rate_limited":
|
|
7033
|
+
return "AI review skipped: rate limited.";
|
|
7034
|
+
case "jti_unavailable":
|
|
7035
|
+
return "AI review skipped: the review token could not be checked in time.";
|
|
7036
|
+
case "jti_missing":
|
|
7037
|
+
return "AI review skipped: the review token had no single-use id.";
|
|
7038
|
+
case "credit_error":
|
|
7039
|
+
return "AI review skipped: the review credit could not be spent.";
|
|
7040
|
+
case "daily_limit":
|
|
7041
|
+
return "AI review skipped: daily limit reached.";
|
|
7042
|
+
case "signed_out":
|
|
7043
|
+
return "AI review skipped: signed out.";
|
|
7044
|
+
case "quality_unavailable":
|
|
7045
|
+
return "Quality checks were unavailable for this scan.";
|
|
7046
|
+
case "intent_unavailable":
|
|
7047
|
+
return "Intent check was unavailable for this scan.";
|
|
7048
|
+
case "engine_unavailable":
|
|
7049
|
+
return "A scan engine was unavailable.";
|
|
7050
|
+
case "upload_failed":
|
|
7051
|
+
return "The scan could not be uploaded.";
|
|
7052
|
+
case "upload_blocked":
|
|
7053
|
+
return "The scan was not uploaded: the plan limit blocked it.";
|
|
7054
|
+
case "upload_duplicate":
|
|
7055
|
+
return "The scan was already uploaded for this job.";
|
|
7056
|
+
case "persist_failed":
|
|
7057
|
+
return "The scan status could not be stored.";
|
|
7058
|
+
case "token_unverified":
|
|
7059
|
+
case "pro_rules_unavailable":
|
|
7060
|
+
return PLAN_UNVERIFIED_NOTICE;
|
|
7061
|
+
default:
|
|
7062
|
+
if (d.status === "reviewed") return "AI review completed.";
|
|
7063
|
+
if (d.status === "unknown") return "AI review status is unknown.";
|
|
7064
|
+
if (d.status === "partial") return `AI review was partial: ${d.reviewed} of ${d.total} findings reviewed.`;
|
|
7065
|
+
if (d.status === "failed") return "AI review failed.";
|
|
7066
|
+
return "AI review skipped.";
|
|
7067
|
+
}
|
|
7068
|
+
}
|
|
7069
|
+
var SCAN_AI_DEGRADED_KEYS = [
|
|
7070
|
+
"status",
|
|
7071
|
+
"reason",
|
|
7072
|
+
"surface",
|
|
7073
|
+
"total",
|
|
7074
|
+
"reviewed",
|
|
7075
|
+
"capped",
|
|
7076
|
+
"files_received_bucket"
|
|
7077
|
+
];
|
|
7078
|
+
function scanAiDegradedProps(d, filesReceived) {
|
|
7079
|
+
return {
|
|
7080
|
+
status: d.status,
|
|
7081
|
+
reason: d.reason,
|
|
7082
|
+
surface: d.surface,
|
|
7083
|
+
total: d.total,
|
|
7084
|
+
reviewed: d.reviewed,
|
|
7085
|
+
capped: d.capped,
|
|
7086
|
+
files_received_bucket: bucketFiles(filesReceived)
|
|
7087
|
+
};
|
|
7088
|
+
}
|
|
7089
|
+
var SCAN_TOKEN_NULL_KEYS = ["cause", "surface", "tier_expected"];
|
|
7090
|
+
function scanTokenNullProps(cause, surface) {
|
|
7091
|
+
const safeSurface = isSurface(surface) ? surface : "api";
|
|
7092
|
+
return { cause, surface: safeSurface, tier_expected: "paid" };
|
|
7093
|
+
}
|
|
7094
|
+
var BILLING_WEBHOOK_UNMATCHED_KEYS = ["type", "reason", "final"];
|
|
7095
|
+
function billingWebhookUnmatchedProps(input) {
|
|
7096
|
+
const reason = typeof input.reason === "string" && WEBHOOK_REASONS.includes(input.reason) ? input.reason : "race_no_row";
|
|
7097
|
+
const type = typeof input.type === "string" && input.type.length > 0 && input.type.length < 80 ? input.type : "unknown";
|
|
7098
|
+
return { type, reason, final: input.final === true };
|
|
6033
7099
|
}
|
|
6034
7100
|
|
|
6035
7101
|
// src/ai-fp-filter.ts
|
|
@@ -6091,6 +7157,15 @@ var AI_FILTER_BUDGET_MS = (() => {
|
|
|
6091
7157
|
return Math.min(n, 6e4);
|
|
6092
7158
|
})();
|
|
6093
7159
|
var PER_CALL_TIMEOUT_MS = 8e3;
|
|
7160
|
+
function perCallTimeoutMs(budgetMs) {
|
|
7161
|
+
const budget = Number.isFinite(budgetMs) && budgetMs >= 1 ? Math.min(Math.trunc(budgetMs), 6e4) : DEFAULT_AI_FILTER_BUDGET_MS;
|
|
7162
|
+
const scaled = Math.floor(budget * 0.6);
|
|
7163
|
+
const perCall = Math.min(PER_CALL_TIMEOUT_MS, scaled);
|
|
7164
|
+
return perCall;
|
|
7165
|
+
}
|
|
7166
|
+
if (!(perCallTimeoutMs(AI_FILTER_BUDGET_MS) < AI_FILTER_BUDGET_MS)) {
|
|
7167
|
+
throw new Error("per-call AI timeout must be strictly below the filter budget");
|
|
7168
|
+
}
|
|
6094
7169
|
function isAbortError(err) {
|
|
6095
7170
|
if (!err || typeof err !== "object") return false;
|
|
6096
7171
|
const name = "name" in err ? String(err.name) : "";
|
|
@@ -6103,6 +7178,16 @@ function isTimeoutError(err) {
|
|
|
6103
7178
|
const message = err instanceof Error ? err.message : String(err);
|
|
6104
7179
|
return /\b(?:request|connection|operation|model call)\s+(?:has\s+)?timed out\b/i.test(message) || /\bETIMEDOUT\b/i.test(message);
|
|
6105
7180
|
}
|
|
7181
|
+
function errorHttpStatus(err) {
|
|
7182
|
+
if (!err || typeof err !== "object") return null;
|
|
7183
|
+
const status = err.status;
|
|
7184
|
+
return typeof status === "number" && Number.isFinite(status) ? Math.trunc(status) : null;
|
|
7185
|
+
}
|
|
7186
|
+
function callWasAborted(err) {
|
|
7187
|
+
if (!err || typeof err !== "object") return false;
|
|
7188
|
+
const name = "name" in err ? String(err.name) : "";
|
|
7189
|
+
return name === "AbortError" || name === "APIUserAbortError";
|
|
7190
|
+
}
|
|
6106
7191
|
var SEVERITY_PRIORITY = {
|
|
6107
7192
|
critical: 0,
|
|
6108
7193
|
high: 1,
|
|
@@ -6252,8 +7337,10 @@ function parseReviewResponse(text) {
|
|
|
6252
7337
|
return null;
|
|
6253
7338
|
}
|
|
6254
7339
|
}
|
|
6255
|
-
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS) {
|
|
6256
|
-
const
|
|
7340
|
+
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS, options) {
|
|
7341
|
+
const surface = options?.surface ?? "cli";
|
|
7342
|
+
const emptyMask = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
|
|
7343
|
+
const early = (status2, reason2, extra) => ({
|
|
6257
7344
|
findings,
|
|
6258
7345
|
filteredFindings: [],
|
|
6259
7346
|
policyRetainedFindings: [],
|
|
@@ -6261,15 +7348,27 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6261
7348
|
removedCount: 0,
|
|
6262
7349
|
policyRetainedCount: 0,
|
|
6263
7350
|
totalBefore: findings.length,
|
|
6264
|
-
reviewedCount: 0,
|
|
6265
|
-
unreviewedCount: findings.length,
|
|
6266
|
-
cappedCount: 0,
|
|
7351
|
+
reviewedCount: extra?.reviewed ?? 0,
|
|
7352
|
+
unreviewedCount: extra?.unreviewed ?? findings.length,
|
|
7353
|
+
cappedCount: extra?.capped ?? 0,
|
|
6267
7354
|
missingContentCount: 0,
|
|
6268
7355
|
timedOut: false,
|
|
6269
|
-
maskStats:
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
7356
|
+
maskStats: emptyMask,
|
|
7357
|
+
aiDegraded: toAiDegraded({
|
|
7358
|
+
status: status2,
|
|
7359
|
+
reason: reason2,
|
|
7360
|
+
surface,
|
|
7361
|
+
total: findings.length,
|
|
7362
|
+
reviewed: extra?.reviewed ?? 0,
|
|
7363
|
+
unreviewed: extra?.unreviewed ?? findings.length,
|
|
7364
|
+
capped: extra?.capped ?? 0,
|
|
7365
|
+
modelStatus: extra?.modelStatus ?? null
|
|
7366
|
+
})
|
|
7367
|
+
});
|
|
7368
|
+
if (findings.length === 0) {
|
|
7369
|
+
return early("reviewed", null, { reviewed: 0, unreviewed: 0, capped: 0 });
|
|
7370
|
+
}
|
|
7371
|
+
if (!process.env.ANTHROPIC_API_KEY) return early("skipped", "no_api_key");
|
|
6273
7372
|
const deadlineMs = Date.now() + Math.max(0, budgetMs);
|
|
6274
7373
|
const abortController = new AbortController();
|
|
6275
7374
|
let budgetExpired = budgetMs <= 0;
|
|
@@ -6299,12 +7398,20 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6299
7398
|
try {
|
|
6300
7399
|
client = new import_sdk.default();
|
|
6301
7400
|
} catch {
|
|
6302
|
-
|
|
7401
|
+
if (budgetTimer) clearTimeout(budgetTimer);
|
|
7402
|
+
return early("failed", "client_init", {
|
|
7403
|
+
reviewed: 0,
|
|
7404
|
+
capped: overflow.length,
|
|
7405
|
+
unreviewed: findings.length - overflow.length
|
|
7406
|
+
});
|
|
6303
7407
|
}
|
|
6304
7408
|
const fpMap = /* @__PURE__ */ new Map();
|
|
6305
7409
|
const policyRetainedMap = /* @__PURE__ */ new Map();
|
|
6306
7410
|
const reviewedIndices = /* @__PURE__ */ new Set();
|
|
6307
7411
|
let firstError = null;
|
|
7412
|
+
let firstErrorStatus = null;
|
|
7413
|
+
let authFailed = false;
|
|
7414
|
+
let badOutput = false;
|
|
6308
7415
|
const maskStats = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
|
|
6309
7416
|
let failedBatches = 0;
|
|
6310
7417
|
let timedOutCount = 0;
|
|
@@ -6330,9 +7437,11 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6330
7437
|
const reviewBatch = async (task) => {
|
|
6331
7438
|
const { targets, content, detections } = task;
|
|
6332
7439
|
const batch = targets.map((target) => target.finding);
|
|
6333
|
-
if (abortController.signal.aborted || Date.now() >= deadlineMs) {
|
|
6334
|
-
|
|
6335
|
-
|
|
7440
|
+
if (authFailed || abortController.signal.aborted || Date.now() >= deadlineMs) {
|
|
7441
|
+
if (!authFailed) {
|
|
7442
|
+
budgetExpired = true;
|
|
7443
|
+
timedOutCount += batch.length;
|
|
7444
|
+
}
|
|
6336
7445
|
return;
|
|
6337
7446
|
}
|
|
6338
7447
|
try {
|
|
@@ -6344,7 +7453,7 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6344
7453
|
maskStats.masked_count += proof.detected - proof.raw;
|
|
6345
7454
|
maskStats.raw_after_mask += proof.raw;
|
|
6346
7455
|
if (proof.detected > 0) maskStats.had_secret_pattern = true;
|
|
6347
|
-
console.
|
|
7456
|
+
console.error(
|
|
6348
7457
|
`[ai-fp-filter] batch prompt ${prompt.length} chars (~${Math.ceil(prompt.length / 4)} tokens), ${batch.length} finding(s)`
|
|
6349
7458
|
);
|
|
6350
7459
|
if (prompt.length > MAX_BATCH_PROMPT_CHARS) {
|
|
@@ -6352,38 +7461,52 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6352
7461
|
`[ai-fp-filter] batch prompt ${prompt.length} chars exceeds ${MAX_BATCH_PROMPT_CHARS} cap (single oversized finding after truncation)`
|
|
6353
7462
|
);
|
|
6354
7463
|
}
|
|
6355
|
-
const
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
7464
|
+
const perCall = perCallTimeoutMs(budgetMs);
|
|
7465
|
+
const callTimeout = Math.min(perCall, remaining);
|
|
7466
|
+
const callAbort = new AbortController();
|
|
7467
|
+
const onParentAbort = () => callAbort.abort();
|
|
7468
|
+
if (abortController.signal.aborted) callAbort.abort();
|
|
7469
|
+
else abortController.signal.addEventListener("abort", onParentAbort, { once: true });
|
|
7470
|
+
const callTimer = setTimeout(() => callAbort.abort(), callTimeout);
|
|
7471
|
+
let response;
|
|
7472
|
+
try {
|
|
7473
|
+
response = await client.messages.create(
|
|
7474
|
+
{
|
|
7475
|
+
model: MODEL_TRIAGE,
|
|
7476
|
+
max_tokens: 2048,
|
|
7477
|
+
// Haiku 5.5 rejects non-default sampling params with HTTP 400
|
|
7478
|
+
// ("temperature is deprecated for this model"). Omit temperature /
|
|
7479
|
+
// top_p / top_k entirely — do NOT send MODEL_TEMPERATURE (0).
|
|
7480
|
+
// Adaptive thinking is on by default for 5.5; disable it here: this
|
|
7481
|
+
// is binary FP classification, not open-ended analysis, and thinking
|
|
7482
|
+
// burns the shared AI budget (Isobar rescan: every call 400'd on
|
|
7483
|
+
// temperature, then timed_out with aiReviewed:false → grade D).
|
|
7484
|
+
thinking: { type: "disabled" },
|
|
7485
|
+
system: REVIEW_SYSTEM_PROMPT,
|
|
7486
|
+
messages: [{ role: "user", content: prompt }]
|
|
7487
|
+
},
|
|
7488
|
+
{ timeout: callTimeout, signal: callAbort.signal }
|
|
7489
|
+
);
|
|
7490
|
+
} finally {
|
|
7491
|
+
clearTimeout(callTimer);
|
|
7492
|
+
abortController.signal.removeEventListener("abort", onParentAbort);
|
|
7493
|
+
}
|
|
6374
7494
|
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
6375
7495
|
const results = parseReviewResponse(text);
|
|
6376
|
-
if (!results)
|
|
7496
|
+
if (!results) {
|
|
7497
|
+
badOutput = true;
|
|
7498
|
+
throw new Error("AI review returned malformed JSON");
|
|
7499
|
+
}
|
|
6377
7500
|
for (const r of results) {
|
|
6378
7501
|
if (r.index >= batch.length) continue;
|
|
6379
7502
|
const target = targets[r.index];
|
|
6380
7503
|
reviewedIndices.add(target.originalIndex);
|
|
6381
7504
|
if (r.verdict !== "fp") continue;
|
|
6382
|
-
const
|
|
7505
|
+
const reason2 = truncateChars(applySecretMasks(r.reason, secrets), MAX_FIELD_CHARS);
|
|
6383
7506
|
if (isProtectedFromAiRemoval(target.finding)) {
|
|
6384
|
-
policyRetainedMap.set(target.originalIndex,
|
|
7507
|
+
policyRetainedMap.set(target.originalIndex, reason2);
|
|
6385
7508
|
} else {
|
|
6386
|
-
fpMap.set(target.originalIndex,
|
|
7509
|
+
fpMap.set(target.originalIndex, reason2);
|
|
6387
7510
|
}
|
|
6388
7511
|
}
|
|
6389
7512
|
if (results.filter((result) => result.index < batch.length).length < batch.length) {
|
|
@@ -6391,21 +7514,35 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6391
7514
|
if (!firstError) firstError = new Error("AI review returned incomplete verdicts");
|
|
6392
7515
|
}
|
|
6393
7516
|
} catch (err) {
|
|
6394
|
-
const
|
|
7517
|
+
const status2 = errorHttpStatus(err);
|
|
7518
|
+
if (status2 === 401 || status2 === 403) {
|
|
7519
|
+
authFailed = true;
|
|
7520
|
+
failedBatches++;
|
|
7521
|
+
if (!firstError) {
|
|
7522
|
+
firstError = err;
|
|
7523
|
+
firstErrorStatus = status2;
|
|
7524
|
+
}
|
|
7525
|
+
console.error(`[ai-fp-filter] AI review failed: auth status ${status2}`);
|
|
7526
|
+
return;
|
|
7527
|
+
}
|
|
7528
|
+
const callTimedOut = isAbortError(err) || isTimeoutError(err) || abortController.signal.aborted || callWasAborted(err);
|
|
6395
7529
|
if (callTimedOut) {
|
|
6396
7530
|
timedOutCount += batch.length;
|
|
6397
7531
|
budgetExpired = true;
|
|
6398
7532
|
return;
|
|
6399
7533
|
}
|
|
6400
7534
|
failedBatches++;
|
|
6401
|
-
if (!firstError)
|
|
7535
|
+
if (!firstError) {
|
|
7536
|
+
firstError = err;
|
|
7537
|
+
firstErrorStatus = status2;
|
|
7538
|
+
}
|
|
6402
7539
|
}
|
|
6403
7540
|
};
|
|
6404
7541
|
try {
|
|
6405
7542
|
let next = 0;
|
|
6406
7543
|
const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
|
|
6407
7544
|
const workers = Array.from({ length: workerCount }, async () => {
|
|
6408
|
-
while (next < tasks.length) {
|
|
7545
|
+
while (next < tasks.length && !authFailed) {
|
|
6409
7546
|
const cur = next++;
|
|
6410
7547
|
await reviewBatch(tasks[cur]);
|
|
6411
7548
|
}
|
|
@@ -6423,28 +7560,70 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6423
7560
|
`[ai-fp-filter] budget expired or model call timed out \u2014 ${timedOutCount} finding(s) not reviewed; returning them unchanged`
|
|
6424
7561
|
);
|
|
6425
7562
|
}
|
|
6426
|
-
if (firstError) {
|
|
6427
|
-
const
|
|
7563
|
+
if (firstError && !authFailed) {
|
|
7564
|
+
const statusLabel = firstErrorStatus == null ? "none" : String(firstErrorStatus);
|
|
6428
7565
|
if (!reviewedAny) {
|
|
6429
7566
|
console.error(
|
|
6430
|
-
|
|
6431
|
-
msg
|
|
7567
|
+
`[ai-fp-filter] AI review unavailable \u2014 every model call failed; status ${statusLabel}`
|
|
6432
7568
|
);
|
|
6433
7569
|
} else {
|
|
6434
7570
|
console.warn(
|
|
6435
|
-
`[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed;
|
|
6436
|
-
msg
|
|
7571
|
+
`[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed; status ${statusLabel}`
|
|
6437
7572
|
);
|
|
6438
7573
|
}
|
|
6439
7574
|
}
|
|
6440
7575
|
const filtered = findings.filter((_, index) => !fpMap.has(index));
|
|
6441
7576
|
const filteredFindings = [];
|
|
6442
|
-
for (const [index,
|
|
6443
|
-
filteredFindings.push({ finding: findings[index], reason });
|
|
7577
|
+
for (const [index, reason2] of [...fpMap].sort((a, b) => a[0] - b[0])) {
|
|
7578
|
+
filteredFindings.push({ finding: findings[index], reason: reason2 });
|
|
6444
7579
|
}
|
|
6445
7580
|
const policyRetainedFindings = [];
|
|
6446
|
-
for (const [index,
|
|
6447
|
-
policyRetainedFindings.push({ finding: findings[index], reason });
|
|
7581
|
+
for (const [index, reason2] of [...policyRetainedMap].sort((a, b) => a[0] - b[0])) {
|
|
7582
|
+
policyRetainedFindings.push({ finding: findings[index], reason: reason2 });
|
|
7583
|
+
}
|
|
7584
|
+
const cappedCount = overflow.length;
|
|
7585
|
+
const eligible = totalBefore - cappedCount;
|
|
7586
|
+
let reason = null;
|
|
7587
|
+
let status = "reviewed";
|
|
7588
|
+
let modelStatus = null;
|
|
7589
|
+
if (authFailed) {
|
|
7590
|
+
status = "failed";
|
|
7591
|
+
reason = "auth_failed";
|
|
7592
|
+
} else if (reviewedCount === 0 && (timedOut || budgetExpired && tasks.length > 0)) {
|
|
7593
|
+
status = "failed";
|
|
7594
|
+
reason = "budget_timeout";
|
|
7595
|
+
} else if (reviewedCount === 0 && badOutput) {
|
|
7596
|
+
status = "failed";
|
|
7597
|
+
reason = "model_bad_output";
|
|
7598
|
+
} else if (reviewedCount === 0 && firstErrorStatus != null) {
|
|
7599
|
+
status = "failed";
|
|
7600
|
+
reason = "model_error";
|
|
7601
|
+
modelStatus = firstErrorStatus;
|
|
7602
|
+
} else if (reviewedCount === 0 && firstError) {
|
|
7603
|
+
status = "failed";
|
|
7604
|
+
reason = "exception";
|
|
7605
|
+
} else if (reviewedCount === eligible && cappedCount > 0 && missingContentCount === 0) {
|
|
7606
|
+
status = "partial";
|
|
7607
|
+
reason = "capped";
|
|
7608
|
+
} else if (reviewedCount === eligible && missingContentCount === 0 && !firstError && !timedOut) {
|
|
7609
|
+
status = "reviewed";
|
|
7610
|
+
reason = null;
|
|
7611
|
+
} else if (timedOut) {
|
|
7612
|
+
status = reviewedCount === 0 ? "failed" : "partial";
|
|
7613
|
+
reason = "budget_timeout";
|
|
7614
|
+
} else if (missingContentCount > 0 && !firstError && !badOutput) {
|
|
7615
|
+
status = reviewedCount === 0 ? "partial" : "partial";
|
|
7616
|
+
reason = "missing_content";
|
|
7617
|
+
} else if (badOutput) {
|
|
7618
|
+
status = reviewedCount === 0 ? "failed" : "partial";
|
|
7619
|
+
reason = "model_bad_output";
|
|
7620
|
+
} else if (firstErrorStatus != null) {
|
|
7621
|
+
status = "partial";
|
|
7622
|
+
reason = "model_error";
|
|
7623
|
+
modelStatus = firstErrorStatus;
|
|
7624
|
+
} else if (firstError || reviewedCount < eligible) {
|
|
7625
|
+
status = reviewedCount === 0 ? "failed" : "partial";
|
|
7626
|
+
reason = "exception";
|
|
6448
7627
|
}
|
|
6449
7628
|
return {
|
|
6450
7629
|
findings: filtered,
|
|
@@ -6456,10 +7635,20 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
6456
7635
|
totalBefore,
|
|
6457
7636
|
reviewedCount,
|
|
6458
7637
|
unreviewedCount,
|
|
6459
|
-
cappedCount
|
|
7638
|
+
cappedCount,
|
|
6460
7639
|
missingContentCount,
|
|
6461
7640
|
timedOut,
|
|
6462
|
-
maskStats
|
|
7641
|
+
maskStats,
|
|
7642
|
+
aiDegraded: toAiDegraded({
|
|
7643
|
+
status,
|
|
7644
|
+
reason,
|
|
7645
|
+
surface,
|
|
7646
|
+
total: totalBefore,
|
|
7647
|
+
reviewed: reviewedCount,
|
|
7648
|
+
unreviewed: totalBefore - reviewedCount - cappedCount,
|
|
7649
|
+
capped: cappedCount,
|
|
7650
|
+
modelStatus
|
|
7651
|
+
})
|
|
6463
7652
|
};
|
|
6464
7653
|
}
|
|
6465
7654
|
|
|
@@ -11102,35 +12291,61 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
11102
12291
|
}
|
|
11103
12292
|
// Annotate the CommonJS export names for ESM import in node:
|
|
11104
12293
|
0 && (module.exports = {
|
|
12294
|
+
AI_REASONS,
|
|
12295
|
+
AI_STATUSES,
|
|
12296
|
+
AI_SURFACES,
|
|
12297
|
+
BILLING_WEBHOOK_UNMATCHED_KEYS,
|
|
11105
12298
|
CHECKABLE_CLAIMS,
|
|
11106
12299
|
DOTENV_ASSIGN_RE,
|
|
11107
12300
|
FREE_RULE_COUNT,
|
|
11108
12301
|
GRADE_FINDINGS_PER_RULE,
|
|
11109
12302
|
INTENT_EXPECTATIONS,
|
|
12303
|
+
MAX_IGNORE_BYTES,
|
|
12304
|
+
MAX_IGNORE_LINES,
|
|
12305
|
+
MAX_SUPPRESSED_LIST,
|
|
12306
|
+
MAX_WARNING_CAP,
|
|
11110
12307
|
MODEL_ANALYSIS,
|
|
11111
12308
|
MODEL_POLICY_REVIEWED,
|
|
11112
12309
|
MODEL_REVIEW_INTERVAL_DAYS,
|
|
11113
12310
|
MODEL_TEMPERATURE,
|
|
11114
12311
|
MODEL_TRIAGE,
|
|
12312
|
+
NESTED_IGNORE_WARNING,
|
|
11115
12313
|
NON_APP_PATH_PATTERNS,
|
|
12314
|
+
PLAN_CAUSES,
|
|
12315
|
+
PLAN_UNVERIFIED_NOTICE,
|
|
11116
12316
|
PRO_RULE_COUNT,
|
|
11117
12317
|
PUBLIC_ENV_PREFIX_RE,
|
|
11118
12318
|
QUALITY_EXAMPLES,
|
|
12319
|
+
RULE_ID_PATTERN,
|
|
11119
12320
|
RULE_IMPACTS,
|
|
11120
12321
|
SCANNER_VERSION,
|
|
12322
|
+
SCAN_AI_DEGRADED_KEYS,
|
|
12323
|
+
SCAN_TOKEN_NULL_KEYS,
|
|
11121
12324
|
SERVER_ACTION_WRITE_RE,
|
|
12325
|
+
SUPPRESSION_REGEXES,
|
|
11122
12326
|
TEST_FILE_PATTERN,
|
|
11123
12327
|
TOTAL_RULE_COUNT,
|
|
12328
|
+
WEBHOOK_EVENT_TYPES,
|
|
12329
|
+
WEBHOOK_REASONS,
|
|
12330
|
+
aiStatusLine,
|
|
11124
12331
|
allRules,
|
|
12332
|
+
applySuppressions,
|
|
11125
12333
|
assessHeaders,
|
|
11126
12334
|
astMatch,
|
|
12335
|
+
attachInlineSuppressed,
|
|
12336
|
+
attachScanSuppression,
|
|
12337
|
+
billingWebhookUnmatchedProps,
|
|
12338
|
+
bucketFiles,
|
|
12339
|
+
buildMarkerIndex,
|
|
11127
12340
|
buildProjectContext,
|
|
11128
12341
|
buildQualityContext,
|
|
11129
12342
|
buildReviewPrompt,
|
|
11130
12343
|
buildTaintMap,
|
|
11131
12344
|
calculateGrade,
|
|
11132
12345
|
callSpreads,
|
|
12346
|
+
capWarnings,
|
|
11133
12347
|
checkIntent,
|
|
12348
|
+
clampCount,
|
|
11134
12349
|
classifyExposure,
|
|
11135
12350
|
classifyPublicEnvVar,
|
|
11136
12351
|
classifyStatement,
|
|
@@ -11138,6 +12353,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
11138
12353
|
complianceMap,
|
|
11139
12354
|
consoleLogProduction,
|
|
11140
12355
|
corsWildcard,
|
|
12356
|
+
countPass,
|
|
11141
12357
|
dangerousInnerHTML,
|
|
11142
12358
|
deduplicateFindings,
|
|
11143
12359
|
detectBuilder,
|
|
@@ -11182,19 +12398,26 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
11182
12398
|
isMethodCall,
|
|
11183
12399
|
isPrivateAddress,
|
|
11184
12400
|
isProtectedFromAiRemoval,
|
|
12401
|
+
isRootIgnorePath,
|
|
12402
|
+
isRuleScopedIgnoreLine,
|
|
11185
12403
|
isSbomPath,
|
|
11186
12404
|
isServerSideFile,
|
|
11187
12405
|
isServerTarget,
|
|
11188
12406
|
isTestFile,
|
|
11189
12407
|
isTestPath,
|
|
11190
12408
|
isUngradedFinding,
|
|
12409
|
+
isUnscopedOverBroadLine,
|
|
11191
12410
|
isVendoredFinding,
|
|
11192
12411
|
isVendoredPath,
|
|
12412
|
+
isWellFormedRuleId,
|
|
11193
12413
|
lineNumberAt,
|
|
11194
12414
|
lineTextAt,
|
|
12415
|
+
markerCoversLine,
|
|
11195
12416
|
maskComments,
|
|
11196
12417
|
maskOutboundAuthNoise,
|
|
11197
12418
|
maskSecretValue,
|
|
12419
|
+
maskStringLiterals,
|
|
12420
|
+
matchIgnore,
|
|
11198
12421
|
missingAuthMiddleware,
|
|
11199
12422
|
missingCSP,
|
|
11200
12423
|
missingErrorBoundary,
|
|
@@ -11206,29 +12429,44 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
11206
12429
|
normalizeScanPath,
|
|
11207
12430
|
packReviewBatches,
|
|
11208
12431
|
parseFile,
|
|
12432
|
+
parseIgnoreFile,
|
|
12433
|
+
parseIgnoreSources,
|
|
12434
|
+
parseMarkers,
|
|
11209
12435
|
parseScanTarget,
|
|
11210
12436
|
parseSupabaseConfig,
|
|
12437
|
+
perCallTimeoutMs,
|
|
12438
|
+
planCause,
|
|
12439
|
+
publicSuppressedRecord,
|
|
11211
12440
|
qualityRules,
|
|
12441
|
+
readInlineSuppressed,
|
|
12442
|
+
readScanSuppression,
|
|
11212
12443
|
replaceBlockComments,
|
|
11213
12444
|
routeForFile,
|
|
11214
12445
|
runCustomRules,
|
|
12446
|
+
scanAiDegradedProps,
|
|
11215
12447
|
scanConfigs,
|
|
11216
12448
|
scanDependencies,
|
|
11217
12449
|
scanEntropy,
|
|
11218
12450
|
scanMultiFile,
|
|
11219
12451
|
scanQuality,
|
|
12452
|
+
scanTokenNullProps,
|
|
11220
12453
|
sqlInjection,
|
|
11221
12454
|
stripeWebhookUnprotected,
|
|
11222
12455
|
supabaseFunctionName,
|
|
11223
12456
|
supabaseNoRLS,
|
|
12457
|
+
suppressionSummary,
|
|
12458
|
+
toAiDegraded,
|
|
11224
12459
|
todoLeftInCode,
|
|
11225
12460
|
tryParse,
|
|
12461
|
+
unknownAiStatus,
|
|
11226
12462
|
unmeasuredQualityRules,
|
|
11227
12463
|
unvalidatedRedirect,
|
|
11228
12464
|
vc001TestFixtureSeverity,
|
|
11229
12465
|
vendoredReason,
|
|
11230
12466
|
visitBinary,
|
|
11231
12467
|
visitCalls,
|
|
12468
|
+
warningForUpload,
|
|
12469
|
+
warningLine,
|
|
11232
12470
|
weakHashing,
|
|
11233
12471
|
xssVulnerability
|
|
11234
12472
|
});
|