xploitscan-shared-rules 2.4.21 → 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/index.cjs +862 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +832 -34
- 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 +8 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SCANNER_VERSION = "2.4.
|
|
2
|
+
var SCANNER_VERSION = "2.4.22";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -71,18 +71,16 @@ function deduplicateFindings(findings) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// src/silencing.ts
|
|
74
|
-
function isInlineSilenced(
|
|
75
|
-
|
|
76
|
-
const matchLineNum = content.substring(0, matchIndex).split("\n").length - 1;
|
|
77
|
-
return isLineSilenced(lines, matchLineNum, ruleId);
|
|
74
|
+
function isInlineSilenced(_content, _matchIndex, _ruleId) {
|
|
75
|
+
return false;
|
|
78
76
|
}
|
|
79
77
|
function isLineSilenced(lines, lineIdx, ruleId) {
|
|
80
78
|
const matchLine = lines[lineIdx] ?? "";
|
|
81
79
|
const marker = new RegExp(`(?://|/\\*|#|--)\\s*(?:${ruleId}|scanner)-OK\\b`, "i");
|
|
82
80
|
if (marker.test(matchLine)) return true;
|
|
83
81
|
const COMMENT_LINE = /^\s*[{(]?\s*(?:\/\/|#|\/\*|\*|--)/;
|
|
84
|
-
const
|
|
85
|
-
for (let i = lineIdx - 1, seen = 0; i >= 0 && seen <
|
|
82
|
+
const MAX_BLOCK_LINES2 = 20;
|
|
83
|
+
for (let i = lineIdx - 1, seen = 0; i >= 0 && seen < MAX_BLOCK_LINES2; i--, seen++) {
|
|
86
84
|
const line = lines[i] ?? "";
|
|
87
85
|
if (marker.test(line)) return true;
|
|
88
86
|
if (!COMMENT_LINE.test(line)) break;
|
|
@@ -90,6 +88,774 @@ function isLineSilenced(lines, lineIdx, ruleId) {
|
|
|
90
88
|
return false;
|
|
91
89
|
}
|
|
92
90
|
|
|
91
|
+
// src/suppression.ts
|
|
92
|
+
import ignore from "ignore";
|
|
93
|
+
var MAX_IGNORE_BYTES = 64 * 1024;
|
|
94
|
+
var MAX_IGNORE_LINES = 2e3;
|
|
95
|
+
var MAX_IGNORE_LINE_LEN = 1024;
|
|
96
|
+
var MAX_JUSTIFICATION = 200;
|
|
97
|
+
var MAX_WARNING_CAP = 20;
|
|
98
|
+
var MAX_SUPPRESSED_LIST = 500;
|
|
99
|
+
var MAX_COUNT = 1e3;
|
|
100
|
+
var MAX_BLOCK_LINES = 20;
|
|
101
|
+
var NESTED_IGNORE_WARNING = "nested .xploitscanignore ignored (only the root file is read here)";
|
|
102
|
+
var MARKER_SYNTAX = "use <ID>-OK inside a comment";
|
|
103
|
+
var RULE_ID_PATTERN = /^(?:[A-Za-z]{2,8}\d{0,4}|GL:[A-Za-z0-9-]{1,64}|scanner)$/i;
|
|
104
|
+
var SUPPRESSION_REGEXES = [RULE_ID_PATTERN];
|
|
105
|
+
var INLINE = /* @__PURE__ */ Symbol.for("xploitscan.inlineSuppressed");
|
|
106
|
+
function utf8ByteLength(text) {
|
|
107
|
+
return new TextEncoder().encode(text).length;
|
|
108
|
+
}
|
|
109
|
+
function isWellFormedRuleId(id) {
|
|
110
|
+
return RULE_ID_PATTERN.test(id);
|
|
111
|
+
}
|
|
112
|
+
function isBuiltinRuleId(id) {
|
|
113
|
+
if (!isWellFormedRuleId(id)) return false;
|
|
114
|
+
const u = id.toUpperCase();
|
|
115
|
+
if (u === "ENTROPY" || u === "SCANNER" || u === "AI") return true;
|
|
116
|
+
if (/^CFG\d{1,4}$/.test(u)) return true;
|
|
117
|
+
if (/^MFA\d{1,4}$/.test(u)) return true;
|
|
118
|
+
if (/^QA\d{1,4}$/.test(u)) return true;
|
|
119
|
+
if (/^GL:/i.test(id)) return true;
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
function clampCount(value, max = MAX_COUNT) {
|
|
123
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
124
|
+
if (!Number.isFinite(n) || n < 0) return 0;
|
|
125
|
+
return Math.min(max, Math.floor(n));
|
|
126
|
+
}
|
|
127
|
+
function capWarnings(warnings, cap = MAX_WARNING_CAP) {
|
|
128
|
+
if (warnings.length <= cap) return { shown: warnings, extra: 0 };
|
|
129
|
+
return { shown: warnings.slice(0, cap), extra: warnings.length - cap };
|
|
130
|
+
}
|
|
131
|
+
function suppressionSummary(inline, ignoreFile) {
|
|
132
|
+
const n = inline + ignoreFile;
|
|
133
|
+
const noun = n === 1 ? "finding" : "findings";
|
|
134
|
+
return `${n} ${noun} suppressed (${inline} inline marker, ${ignoreFile} ignore file)`;
|
|
135
|
+
}
|
|
136
|
+
function warningForUpload(w) {
|
|
137
|
+
return { code: w.code, ruleIds: [...w.ruleIds], count: w.count };
|
|
138
|
+
}
|
|
139
|
+
function warningLine(w) {
|
|
140
|
+
if (w.code === "nested_ignored") return `${w.file} ${NESTED_IGNORE_WARNING}`;
|
|
141
|
+
const where = w.file ? `${w.file}:${w.line}` : `line ${w.line}`;
|
|
142
|
+
const ids = w.ruleIds.length ? ` ${w.ruleIds.join(",")}` : "";
|
|
143
|
+
const syntax = w.code === "unrecognized_marker" || w.code === "space_before_ok" ? ` ${MARKER_SYNTAX}` : "";
|
|
144
|
+
const more = w.code === "over_broad" ? ` suppresses all findings in ${w.count} files` : "";
|
|
145
|
+
return `${where} ${w.code}${ids}${more}${syntax}`;
|
|
146
|
+
}
|
|
147
|
+
function attachInlineSuppressed(findings, suppressed) {
|
|
148
|
+
Object.defineProperty(findings, INLINE, { value: suppressed, enumerable: false });
|
|
149
|
+
return findings;
|
|
150
|
+
}
|
|
151
|
+
function readInlineSuppressed(findings) {
|
|
152
|
+
if (!findings || typeof findings !== "object") return [];
|
|
153
|
+
const value = findings[INLINE];
|
|
154
|
+
return Array.isArray(value) ? value : [];
|
|
155
|
+
}
|
|
156
|
+
function publicSuppressedRecord(finding) {
|
|
157
|
+
const suppression = finding.suppression;
|
|
158
|
+
const info = suppression && typeof suppression === "object" ? {
|
|
159
|
+
kind: suppression.kind,
|
|
160
|
+
source: suppression.source,
|
|
161
|
+
ruleToken: suppression.ruleToken,
|
|
162
|
+
justification: String(suppression.justification ?? "").slice(
|
|
163
|
+
0,
|
|
164
|
+
MAX_JUSTIFICATION
|
|
165
|
+
),
|
|
166
|
+
declaredIn: suppression.declaredIn
|
|
167
|
+
} : void 0;
|
|
168
|
+
return {
|
|
169
|
+
rule: finding.rule,
|
|
170
|
+
file: finding.file,
|
|
171
|
+
line: finding.line,
|
|
172
|
+
severity: finding.severity,
|
|
173
|
+
...info ? { suppression: info } : {}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function warn(file, line, code, ruleIds = [], count = 1) {
|
|
177
|
+
return { code, file, line, ruleIds, count };
|
|
178
|
+
}
|
|
179
|
+
function fateOf(id, opts) {
|
|
180
|
+
if (isBuiltinRuleId(id)) return "ok";
|
|
181
|
+
const upper = id.toUpperCase();
|
|
182
|
+
const pro = opts?.proIds;
|
|
183
|
+
if (pro && (pro.has(upper) || pro.has(id))) {
|
|
184
|
+
return opts?.tier === "pro" ? "ok" : "pro-silent";
|
|
185
|
+
}
|
|
186
|
+
if (!opts?.knownIds) return "ok";
|
|
187
|
+
if (opts.knownIds.has(upper) || opts.knownIds.has(id)) return "ok";
|
|
188
|
+
return "unknown";
|
|
189
|
+
}
|
|
190
|
+
function idEndingAt(text, end) {
|
|
191
|
+
const window = text.slice(Math.max(0, end - 80), end);
|
|
192
|
+
const gl = window.match(/GL:[A-Za-z0-9-]{1,64}$/i);
|
|
193
|
+
if (gl) {
|
|
194
|
+
const id2 = gl[0];
|
|
195
|
+
if (isWellFormedRuleId(id2)) return { id: id2, start: end - id2.length };
|
|
196
|
+
}
|
|
197
|
+
const plain = window.match(/[A-Za-z]{2,8}\d{0,4}$/);
|
|
198
|
+
if (!plain) return null;
|
|
199
|
+
const id = plain[0];
|
|
200
|
+
if (id.toLowerCase() === "ok") return null;
|
|
201
|
+
if (!isWellFormedRuleId(id)) return null;
|
|
202
|
+
return { id, start: end - id.length };
|
|
203
|
+
}
|
|
204
|
+
function idListBefore(text, end) {
|
|
205
|
+
const first = idEndingAt(text, end);
|
|
206
|
+
if (!first) return null;
|
|
207
|
+
const ids = [first.id];
|
|
208
|
+
let cursor = first.start;
|
|
209
|
+
while (cursor > 0) {
|
|
210
|
+
let j = cursor;
|
|
211
|
+
while (j > 0 && (text[j - 1] === " " || text[j - 1] === " ")) j--;
|
|
212
|
+
if (j > 0 && text[j - 1] === ",") {
|
|
213
|
+
j--;
|
|
214
|
+
while (j > 0 && (text[j - 1] === " " || text[j - 1] === " ")) j--;
|
|
215
|
+
} else if (j === cursor) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
const prev = idEndingAt(text, j);
|
|
219
|
+
if (!prev || prev.start + prev.id.length !== j) break;
|
|
220
|
+
ids.unshift(prev.id);
|
|
221
|
+
cursor = prev.start;
|
|
222
|
+
}
|
|
223
|
+
return { ids, start: cursor };
|
|
224
|
+
}
|
|
225
|
+
function nextMarkerStart(rest) {
|
|
226
|
+
const lower = rest.toLowerCase();
|
|
227
|
+
let from = 0;
|
|
228
|
+
while (from < lower.length) {
|
|
229
|
+
const at = lower.indexOf("-ok", from);
|
|
230
|
+
if (at < 0) return -1;
|
|
231
|
+
const after = at + 3;
|
|
232
|
+
const next = lower[after];
|
|
233
|
+
if (next !== void 0 && /[A-Za-z0-9_]/.test(next)) {
|
|
234
|
+
from = at + 1;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
let i = at - 1;
|
|
238
|
+
while (i >= 0 && /[A-Za-z0-9:-]/.test(lower[i] ?? "")) i--;
|
|
239
|
+
let start = i + 1;
|
|
240
|
+
while (start < at && !/[A-Za-z0-9]/.test(lower[start] ?? "")) start++;
|
|
241
|
+
if (start < at) return start;
|
|
242
|
+
from = at + 1;
|
|
243
|
+
}
|
|
244
|
+
return -1;
|
|
245
|
+
}
|
|
246
|
+
function parseCommentMarkers(comment, file, line, opts) {
|
|
247
|
+
const warnings = [];
|
|
248
|
+
const ids = [];
|
|
249
|
+
let justification = "";
|
|
250
|
+
const lower = comment.toLowerCase();
|
|
251
|
+
if (lower.includes("xploitscan") || lower.includes("ignore-line")) {
|
|
252
|
+
warnings.push(warn(file, line, "unrecognized_marker"));
|
|
253
|
+
}
|
|
254
|
+
let from = 0;
|
|
255
|
+
while (from < comment.length) {
|
|
256
|
+
const okAt = lower.indexOf("-ok", from);
|
|
257
|
+
const typoAt = lower.indexOf("-0k", from);
|
|
258
|
+
if (okAt < 0 && typoAt < 0) break;
|
|
259
|
+
const useTypo = typoAt >= 0 && (okAt < 0 || typoAt < okAt);
|
|
260
|
+
const at = useTypo ? typoAt : okAt;
|
|
261
|
+
const after = at + 3;
|
|
262
|
+
const boundary = after >= comment.length || !/[A-Za-z0-9]/.test(comment[after]);
|
|
263
|
+
if (!boundary) {
|
|
264
|
+
from = at + 1;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (useTypo) {
|
|
268
|
+
const listed2 = idListBefore(comment, at);
|
|
269
|
+
warnings.push(
|
|
270
|
+
warn(
|
|
271
|
+
file,
|
|
272
|
+
line,
|
|
273
|
+
"unrecognized_marker",
|
|
274
|
+
listed2 ? listed2.ids.map((id) => id.toUpperCase()) : []
|
|
275
|
+
)
|
|
276
|
+
);
|
|
277
|
+
from = after;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const prev = at > 0 ? comment[at - 1] : "";
|
|
281
|
+
if (prev === " " || prev === " ") {
|
|
282
|
+
const listed2 = idListBefore(
|
|
283
|
+
comment.slice(0, at).trimEnd(),
|
|
284
|
+
comment.slice(0, at).trimEnd().length
|
|
285
|
+
);
|
|
286
|
+
warnings.push(
|
|
287
|
+
warn(file, line, "space_before_ok", listed2 ? listed2.ids.map((id) => id.toUpperCase()) : [])
|
|
288
|
+
);
|
|
289
|
+
from = after;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const listed = idListBefore(comment, at);
|
|
293
|
+
if (!listed) {
|
|
294
|
+
warnings.push(warn(file, line, "unrecognized_marker"));
|
|
295
|
+
from = after;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
let just = "";
|
|
299
|
+
if (comment[after] === ":") {
|
|
300
|
+
const rest = comment.slice(after + 1);
|
|
301
|
+
const next = nextMarkerStart(rest);
|
|
302
|
+
just = (next >= 0 ? rest.slice(0, next) : rest).trim().slice(0, MAX_JUSTIFICATION);
|
|
303
|
+
}
|
|
304
|
+
if (!justification && just) justification = just;
|
|
305
|
+
for (const id of listed.ids) {
|
|
306
|
+
const fate = fateOf(id, opts);
|
|
307
|
+
if (fate === "unknown") {
|
|
308
|
+
warnings.push(warn(file, line, "unknown_rule_id", [id.toUpperCase()]));
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (fate === "pro-silent") continue;
|
|
312
|
+
ids.push(id.toUpperCase());
|
|
313
|
+
}
|
|
314
|
+
from = after;
|
|
315
|
+
}
|
|
316
|
+
return { ids, justification, warnings };
|
|
317
|
+
}
|
|
318
|
+
function commentOpenerAt(chars, i) {
|
|
319
|
+
const a = chars[i] ?? "";
|
|
320
|
+
const b = chars[i + 1] ?? "";
|
|
321
|
+
const two = a + b;
|
|
322
|
+
if (two === "//") return { kind: "line", len: 2 };
|
|
323
|
+
if (two === "/*") return { kind: "block", len: 2 };
|
|
324
|
+
if (two + (chars[i + 2] ?? "") + (chars[i + 3] ?? "") === "<!--") return { kind: "html", len: 4 };
|
|
325
|
+
if (a === "#" && (i === 0 || /\s/.test(chars[i - 1] ?? ""))) return { kind: "line", len: 1 };
|
|
326
|
+
if (two === "--" && (i === 0 || /\s/.test(chars[i - 1] ?? ""))) return { kind: "line", len: 2 };
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
function maskStringLiterals(line) {
|
|
330
|
+
const chars = line.split("");
|
|
331
|
+
const n = chars.length;
|
|
332
|
+
let i = 0;
|
|
333
|
+
while (i < n) {
|
|
334
|
+
const opener = commentOpenerAt(chars, i);
|
|
335
|
+
if (opener) {
|
|
336
|
+
if (opener.kind === "line") break;
|
|
337
|
+
if (opener.kind === "block") {
|
|
338
|
+
const end2 = line.indexOf("*/", i + opener.len);
|
|
339
|
+
i = end2 < 0 ? n : end2 + 2;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
const end = line.indexOf("-->", i + opener.len);
|
|
343
|
+
i = end < 0 ? n : end + 3;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const c = chars[i];
|
|
347
|
+
if (c === '"' || c === "'") {
|
|
348
|
+
const q = c;
|
|
349
|
+
chars[i] = " ";
|
|
350
|
+
i++;
|
|
351
|
+
while (i < n) {
|
|
352
|
+
if (chars[i] === "\\") {
|
|
353
|
+
chars[i] = " ";
|
|
354
|
+
if (i + 1 < n) chars[i + 1] = " ";
|
|
355
|
+
i += 2;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (chars[i] === q) {
|
|
359
|
+
chars[i] = " ";
|
|
360
|
+
i++;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
chars[i] = " ";
|
|
364
|
+
i++;
|
|
365
|
+
}
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (c === "`") {
|
|
369
|
+
chars[i] = " ";
|
|
370
|
+
i++;
|
|
371
|
+
let expr = 0;
|
|
372
|
+
while (i < n) {
|
|
373
|
+
if (expr === 0 && chars[i] === "\\") {
|
|
374
|
+
chars[i] = " ";
|
|
375
|
+
if (i + 1 < n) chars[i + 1] = " ";
|
|
376
|
+
i += 2;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (expr === 0 && chars[i] === "`") {
|
|
380
|
+
chars[i] = " ";
|
|
381
|
+
i++;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
if (expr === 0 && chars[i] === "$" && chars[i + 1] === "{") {
|
|
385
|
+
chars[i] = " ";
|
|
386
|
+
chars[i + 1] = " ";
|
|
387
|
+
expr = 1;
|
|
388
|
+
i += 2;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (expr > 0 && chars[i] === "{") {
|
|
392
|
+
expr++;
|
|
393
|
+
i++;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (expr > 0 && chars[i] === "}") {
|
|
397
|
+
expr--;
|
|
398
|
+
if (expr === 0) chars[i] = " ";
|
|
399
|
+
i++;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (expr === 0) chars[i] = " ";
|
|
403
|
+
i++;
|
|
404
|
+
}
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
i++;
|
|
408
|
+
}
|
|
409
|
+
return chars.join("");
|
|
410
|
+
}
|
|
411
|
+
function commentSpans(masked) {
|
|
412
|
+
const spans = [];
|
|
413
|
+
const n = masked.length;
|
|
414
|
+
let i = 0;
|
|
415
|
+
const code = true;
|
|
416
|
+
while (i < n) {
|
|
417
|
+
if (!code) {
|
|
418
|
+
i++;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const two = masked.slice(i, i + 2);
|
|
422
|
+
const four = masked.slice(i, i + 4);
|
|
423
|
+
if (four === "<!--") {
|
|
424
|
+
const end = masked.indexOf("-->", i + 4);
|
|
425
|
+
const stop = end < 0 ? n : end + 3;
|
|
426
|
+
spans.push([i, stop]);
|
|
427
|
+
i = stop;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (two === "//") {
|
|
431
|
+
spans.push([i, n]);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
if (two === "/*") {
|
|
435
|
+
const end = masked.indexOf("*/", i + 2);
|
|
436
|
+
const stop = end < 0 ? n : end + 2;
|
|
437
|
+
spans.push([i, stop]);
|
|
438
|
+
i = stop;
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (masked[i] === "#" && (i === 0 || /\s/.test(masked[i - 1]))) {
|
|
442
|
+
spans.push([i, n]);
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
if (two === "--" && (i === 0 || /\s/.test(masked[i - 1]))) {
|
|
446
|
+
spans.push([i, n]);
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
i++;
|
|
450
|
+
}
|
|
451
|
+
const trimmed = masked.trim();
|
|
452
|
+
if (spans.length === 0 && (/^\*/.test(trimmed) || trimmed === "*/" || trimmed === "*/}" || trimmed === "-->")) {
|
|
453
|
+
spans.push([0, n]);
|
|
454
|
+
}
|
|
455
|
+
return spans;
|
|
456
|
+
}
|
|
457
|
+
function isBlankLine(line) {
|
|
458
|
+
return line.trim() === "";
|
|
459
|
+
}
|
|
460
|
+
function isCommentOnly(masked) {
|
|
461
|
+
const spans = commentSpans(masked);
|
|
462
|
+
if (spans.length === 0) return false;
|
|
463
|
+
const chars = masked.split("");
|
|
464
|
+
for (const [start, end] of spans) {
|
|
465
|
+
for (let i = start; i < end; i++) chars[i] = " ";
|
|
466
|
+
}
|
|
467
|
+
return /^[{}()\s]*$/.test(chars.join(""));
|
|
468
|
+
}
|
|
469
|
+
function targetLineFor(lines, maskedLines, markerLine) {
|
|
470
|
+
if (!isCommentOnly(maskedLines[markerLine] ?? "")) return markerLine;
|
|
471
|
+
let blanks = 0;
|
|
472
|
+
let comments = 0;
|
|
473
|
+
for (let i = markerLine + 1; i < lines.length; i++) {
|
|
474
|
+
if (isBlankLine(lines[i] ?? "")) {
|
|
475
|
+
blanks++;
|
|
476
|
+
if (blanks > 1) return null;
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (isCommentOnly(maskedLines[i] ?? "")) {
|
|
480
|
+
if (blanks > 0) return null;
|
|
481
|
+
comments++;
|
|
482
|
+
if (comments > MAX_BLOCK_LINES) return null;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
return i;
|
|
486
|
+
}
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
function parseMarkers(lines, filePath = "", opts) {
|
|
490
|
+
const maskedLines = lines.map((line) => maskStringLiterals(line));
|
|
491
|
+
const markers = [];
|
|
492
|
+
const warnings = [];
|
|
493
|
+
for (let i = 0; i < lines.length; i++) {
|
|
494
|
+
const spans = commentSpans(maskedLines[i] ?? "");
|
|
495
|
+
if (spans.length === 0) continue;
|
|
496
|
+
const pieces = spans.map(([a, b]) => (maskedLines[i] ?? "").slice(a, b));
|
|
497
|
+
const parsed = parseCommentMarkers(pieces.join("\n"), filePath, i + 1, opts);
|
|
498
|
+
warnings.push(...parsed.warnings);
|
|
499
|
+
if (parsed.ids.length === 0) continue;
|
|
500
|
+
const target = targetLineFor(lines, maskedLines, i);
|
|
501
|
+
if (target === null) continue;
|
|
502
|
+
markers.push({
|
|
503
|
+
markerLine: i,
|
|
504
|
+
targetLine: target,
|
|
505
|
+
ruleIds: parsed.ids,
|
|
506
|
+
justification: parsed.justification,
|
|
507
|
+
declaredIn: `${filePath}:${i + 1}`
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
return { markers, warnings };
|
|
511
|
+
}
|
|
512
|
+
function buildMarkerIndex(lines, filePath = "", opts) {
|
|
513
|
+
const { markers, warnings } = parseMarkers(lines, filePath, opts);
|
|
514
|
+
const covers = (lineIdx, ruleId) => {
|
|
515
|
+
const want = ruleId.toUpperCase();
|
|
516
|
+
for (const marker of markers) {
|
|
517
|
+
if (marker.targetLine !== lineIdx) continue;
|
|
518
|
+
if (marker.ruleIds.includes("SCANNER") || marker.ruleIds.includes(want)) return marker;
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
521
|
+
};
|
|
522
|
+
return {
|
|
523
|
+
markers,
|
|
524
|
+
warnings,
|
|
525
|
+
covers(lineIdx, ruleId) {
|
|
526
|
+
return covers(lineIdx, ruleId) !== null;
|
|
527
|
+
},
|
|
528
|
+
info(lineIdx, ruleId) {
|
|
529
|
+
const hit = covers(lineIdx, ruleId);
|
|
530
|
+
if (!hit) return null;
|
|
531
|
+
const token = hit.ruleIds.includes(ruleId.toUpperCase()) ? ruleId.toUpperCase() : "SCANNER";
|
|
532
|
+
return { ruleToken: token, justification: hit.justification, declaredIn: hit.declaredIn };
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function markerCoversLine(lines, lineIdx, ruleId) {
|
|
537
|
+
return buildMarkerIndex(lines, "").covers(lineIdx, ruleId);
|
|
538
|
+
}
|
|
539
|
+
function posix(p) {
|
|
540
|
+
return p.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
541
|
+
}
|
|
542
|
+
function isRootIgnorePath(filePath) {
|
|
543
|
+
return posix(filePath) === ".xploitscanignore";
|
|
544
|
+
}
|
|
545
|
+
function splitIgnoreLine(line) {
|
|
546
|
+
let i = 0;
|
|
547
|
+
while (i < line.length && (line[i] === " " || line[i] === " ")) i++;
|
|
548
|
+
if (i < line.length && line[i] === "#") {
|
|
549
|
+
return { code: "", comment: line.slice(i + 1).trim(), escaped: false };
|
|
550
|
+
}
|
|
551
|
+
let code = "";
|
|
552
|
+
let escaped = false;
|
|
553
|
+
for (let k = 0; k < line.length; k++) {
|
|
554
|
+
const c = line[k] ?? "";
|
|
555
|
+
if (c === "\\") {
|
|
556
|
+
escaped = true;
|
|
557
|
+
code += c;
|
|
558
|
+
if (k + 1 < line.length) {
|
|
559
|
+
code += line[k + 1] ?? "";
|
|
560
|
+
k++;
|
|
561
|
+
}
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (c === "#" && k > 0 && (line[k - 1] === " " || line[k - 1] === " ")) {
|
|
565
|
+
return { code: code.trimEnd(), comment: line.slice(k + 1).trim(), escaped };
|
|
566
|
+
}
|
|
567
|
+
code += c;
|
|
568
|
+
}
|
|
569
|
+
return { code: code.trim(), comment: "", escaped };
|
|
570
|
+
}
|
|
571
|
+
function peelRules(code) {
|
|
572
|
+
const parts = code.split(/[ \t]+/).filter(Boolean);
|
|
573
|
+
const rules = [];
|
|
574
|
+
while (parts.length > 1) {
|
|
575
|
+
const last = parts[parts.length - 1] ?? "";
|
|
576
|
+
const ids = last.split(",").map((s) => s.trim()).filter(Boolean);
|
|
577
|
+
if (ids.length === 0 || !ids.every((id) => isWellFormedRuleId(id))) break;
|
|
578
|
+
rules.unshift(...ids);
|
|
579
|
+
parts.pop();
|
|
580
|
+
}
|
|
581
|
+
const pattern = parts.join(" ");
|
|
582
|
+
const unscoped = rules.length === 0 && /\s/.test(code.trim());
|
|
583
|
+
return { pattern, rules: rules.length ? rules : null, unscoped };
|
|
584
|
+
}
|
|
585
|
+
function patternRejected(pattern) {
|
|
586
|
+
if (pattern.includes("\0")) return true;
|
|
587
|
+
if (/^[A-Za-z]:/.test(pattern)) return true;
|
|
588
|
+
const norm = pattern.replace(/\\/g, "/");
|
|
589
|
+
if (/^[A-Za-z]:/.test(norm)) return true;
|
|
590
|
+
const body = norm.replace(/^!/, "");
|
|
591
|
+
if (body.split("/").includes("..")) return true;
|
|
592
|
+
const bare = body.replace(/^\.\//, "");
|
|
593
|
+
if (/^\/[^/*?\]]+$/.test(bare) && !bare.slice(1).includes("/")) return true;
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
function isOverBroad(pattern, rules) {
|
|
597
|
+
if (pattern.startsWith("!")) return false;
|
|
598
|
+
const body = pattern.replace(/^\.\//, "").replace(/^\//, "");
|
|
599
|
+
const broad = body === "*" || body === "**" || body === "**/*";
|
|
600
|
+
const all = rules === null || rules.some((r) => r.toUpperCase() === "SCANNER");
|
|
601
|
+
return broad && all;
|
|
602
|
+
}
|
|
603
|
+
function compilePattern(pattern) {
|
|
604
|
+
const neg = pattern.startsWith("!");
|
|
605
|
+
const body = (neg ? pattern.slice(1) : pattern).replace(/^\.\//, "");
|
|
606
|
+
return ignore().add(body);
|
|
607
|
+
}
|
|
608
|
+
function parseIgnoreFile(text, dirRel = "", opts) {
|
|
609
|
+
const declared = opts?.declaredPath ?? (dirRel ? `${posix(dirRel)}/.xploitscanignore` : ".xploitscanignore");
|
|
610
|
+
const dir = posix(dirRel).replace(/\/$/, "");
|
|
611
|
+
if (text.includes("\0")) {
|
|
612
|
+
return { entries: [], warnings: [warn(declared, 1, "binary")], ignoredWhole: true };
|
|
613
|
+
}
|
|
614
|
+
const bytes = utf8ByteLength(text);
|
|
615
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
616
|
+
let rawLines = normalized.split("\n");
|
|
617
|
+
if (rawLines.length > 0 && rawLines[rawLines.length - 1] === "" && normalized.endsWith("\n")) {
|
|
618
|
+
rawLines = rawLines.slice(0, -1);
|
|
619
|
+
}
|
|
620
|
+
if (bytes > MAX_IGNORE_BYTES || rawLines.length > MAX_IGNORE_LINES) {
|
|
621
|
+
return { entries: [], warnings: [warn(declared, 1, "over_cap")], ignoredWhole: true };
|
|
622
|
+
}
|
|
623
|
+
const entries = [];
|
|
624
|
+
const warnings = [];
|
|
625
|
+
rawLines.forEach((raw, idx) => {
|
|
626
|
+
const lineNo = idx + 1;
|
|
627
|
+
if (raw.length > MAX_IGNORE_LINE_LEN) {
|
|
628
|
+
warnings.push(warn(declared, lineNo, "line_too_long"));
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const split = splitIgnoreLine(raw);
|
|
632
|
+
if (split.escaped) {
|
|
633
|
+
warnings.push(warn(declared, lineNo, "path_rejected"));
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const { code, comment } = split;
|
|
637
|
+
if (!code.trim() || code.trimStart().startsWith("#")) return;
|
|
638
|
+
const peeled = peelRules(code.trim());
|
|
639
|
+
if (!peeled.pattern) {
|
|
640
|
+
warnings.push(warn(declared, lineNo, "unrecognized_marker"));
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (patternRejected(peeled.pattern)) {
|
|
644
|
+
warnings.push(warn(declared, lineNo, "path_rejected"));
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
if (peeled.unscoped) {
|
|
648
|
+
warnings.push(warn(declared, lineNo, "unscoped_whitespace"));
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
const accepted = [];
|
|
652
|
+
for (const id of peeled.rules ?? []) {
|
|
653
|
+
const fate = fateOf(id, opts);
|
|
654
|
+
if (fate === "unknown") {
|
|
655
|
+
warnings.push(warn(declared, lineNo, "unknown_rule_id", [id.toUpperCase()]));
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
if (fate === "pro-silent") continue;
|
|
659
|
+
accepted.push(id.toUpperCase());
|
|
660
|
+
}
|
|
661
|
+
if (peeled.rules && accepted.length === 0) return;
|
|
662
|
+
const pattern = peeled.pattern.replace(/\\/g, "/");
|
|
663
|
+
let matcher;
|
|
664
|
+
try {
|
|
665
|
+
matcher = compilePattern(pattern);
|
|
666
|
+
} catch {
|
|
667
|
+
warnings.push(warn(declared, lineNo, "path_rejected"));
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
entries.push({
|
|
671
|
+
dirRel: dir,
|
|
672
|
+
pattern,
|
|
673
|
+
negated: pattern.startsWith("!"),
|
|
674
|
+
rules: peeled.rules ? new Set(accepted) : null,
|
|
675
|
+
justification: comment.slice(0, MAX_JUSTIFICATION),
|
|
676
|
+
declaredIn: `${declared}:${lineNo}`,
|
|
677
|
+
line: lineNo,
|
|
678
|
+
overBroad: isOverBroad(pattern, peeled.rules),
|
|
679
|
+
matcher
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
return { entries, warnings, ignoredWhole: false };
|
|
683
|
+
}
|
|
684
|
+
function parseIgnoreSources(sources, mode, opts) {
|
|
685
|
+
const entries = [];
|
|
686
|
+
const warnings = [];
|
|
687
|
+
const ordered = [...sources].sort((a, b) => posix(a.path).length - posix(b.path).length);
|
|
688
|
+
for (const source of ordered) {
|
|
689
|
+
const path = posix(source.path);
|
|
690
|
+
const root = isRootIgnorePath(path);
|
|
691
|
+
if (mode === "root-only" && !root) {
|
|
692
|
+
warnings.push(warn(path, 1, "nested_ignored"));
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
const dir = root ? "" : path.slice(0, Math.max(0, path.lastIndexOf("/")));
|
|
696
|
+
const parsed = parseIgnoreFile(source.text, dir, { ...opts, declaredPath: path });
|
|
697
|
+
entries.push(...parsed.entries);
|
|
698
|
+
warnings.push(...parsed.warnings);
|
|
699
|
+
}
|
|
700
|
+
return { entries, warnings };
|
|
701
|
+
}
|
|
702
|
+
function relativeTo(filePath, dirRel) {
|
|
703
|
+
const path = posix(filePath);
|
|
704
|
+
if (!dirRel) return path;
|
|
705
|
+
if (path === dirRel) return null;
|
|
706
|
+
if (path.startsWith(`${dirRel}/`)) return path.slice(dirRel.length + 1);
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
function matcherFor(entry) {
|
|
710
|
+
if (entry.matcher) return entry.matcher;
|
|
711
|
+
try {
|
|
712
|
+
entry.matcher = compilePattern(entry.pattern);
|
|
713
|
+
return entry.matcher;
|
|
714
|
+
} catch {
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function entryMatches(entry, filePath) {
|
|
719
|
+
const rel = relativeTo(filePath, entry.dirRel);
|
|
720
|
+
if (rel === null || rel === "") return false;
|
|
721
|
+
const matcher = matcherFor(entry);
|
|
722
|
+
if (!matcher) return false;
|
|
723
|
+
try {
|
|
724
|
+
return matcher.ignores(rel);
|
|
725
|
+
} catch {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function matchIgnore(entries, filePath, ruleId) {
|
|
730
|
+
const rule = ruleId.toUpperCase();
|
|
731
|
+
let winner = null;
|
|
732
|
+
for (const entry of entries) {
|
|
733
|
+
if (!entryMatches(entry, filePath)) continue;
|
|
734
|
+
const applies = entry.rules === null || entry.rules.has("SCANNER") || entry.rules.has(rule);
|
|
735
|
+
if (!applies) continue;
|
|
736
|
+
winner = entry.negated ? null : entry;
|
|
737
|
+
}
|
|
738
|
+
return winner;
|
|
739
|
+
}
|
|
740
|
+
function filesMap(input) {
|
|
741
|
+
if (input instanceof Map) return input;
|
|
742
|
+
return new Map(Object.entries(input).map(([k, v]) => [posix(k), v]));
|
|
743
|
+
}
|
|
744
|
+
function applySuppressions(findings, input) {
|
|
745
|
+
const files = filesMap(input.filesByPath);
|
|
746
|
+
const opts = { knownIds: input.knownIds, proIds: input.proIds, tier: input.tier };
|
|
747
|
+
const entries = input.ignoreEntries ?? [];
|
|
748
|
+
const warnings = [];
|
|
749
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
750
|
+
const indexFor = (file) => {
|
|
751
|
+
const key = posix(file);
|
|
752
|
+
const cached = indexes.get(key);
|
|
753
|
+
if (cached) return cached;
|
|
754
|
+
const text = files.get(key) ?? "";
|
|
755
|
+
const folded = text.toLowerCase();
|
|
756
|
+
if (!folded.includes("-ok") && !folded.includes("-0k")) {
|
|
757
|
+
const empty = {
|
|
758
|
+
markers: [],
|
|
759
|
+
warnings: [],
|
|
760
|
+
covers: () => false,
|
|
761
|
+
info: () => null
|
|
762
|
+
};
|
|
763
|
+
indexes.set(key, empty);
|
|
764
|
+
return empty;
|
|
765
|
+
}
|
|
766
|
+
const built = buildMarkerIndex(text.split("\n"), key, opts);
|
|
767
|
+
indexes.set(key, built);
|
|
768
|
+
warnings.push(...built.warnings);
|
|
769
|
+
return built;
|
|
770
|
+
};
|
|
771
|
+
const direct = /* @__PURE__ */ new Map();
|
|
772
|
+
for (const finding of findings) {
|
|
773
|
+
const info = indexFor(finding.file).info(finding.line - 1, finding.rule);
|
|
774
|
+
if (!info) continue;
|
|
775
|
+
direct.set(finding, {
|
|
776
|
+
kind: "inSource",
|
|
777
|
+
source: "marker",
|
|
778
|
+
ruleToken: info.ruleToken,
|
|
779
|
+
justification: info.justification,
|
|
780
|
+
declaredIn: info.declaredIn
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
784
|
+
for (const file of files.keys()) seenFiles.add(posix(file));
|
|
785
|
+
for (const finding of findings) seenFiles.add(posix(finding.file));
|
|
786
|
+
for (const entry of entries) {
|
|
787
|
+
if (!entry.overBroad) continue;
|
|
788
|
+
let count = 0;
|
|
789
|
+
for (const file of seenFiles) if (entryMatches(entry, file)) count++;
|
|
790
|
+
if (count > 0)
|
|
791
|
+
warnings.push(
|
|
792
|
+
warn(entry.declaredIn.split(":")[0] ?? "", entry.line, "over_broad", [], count)
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
const kept = [];
|
|
796
|
+
const suppressed = [];
|
|
797
|
+
for (const finding of findings) {
|
|
798
|
+
const marker = direct.get(finding);
|
|
799
|
+
if (marker) {
|
|
800
|
+
suppressed.push({ ...finding, suppression: marker });
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
const hit = matchIgnore(entries, finding.file, finding.rule);
|
|
804
|
+
if (hit) {
|
|
805
|
+
suppressed.push({
|
|
806
|
+
...finding,
|
|
807
|
+
suppression: {
|
|
808
|
+
kind: "external",
|
|
809
|
+
source: "ignore-file",
|
|
810
|
+
ruleToken: finding.rule.toUpperCase(),
|
|
811
|
+
justification: hit.justification,
|
|
812
|
+
declaredIn: hit.declaredIn
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
kept.push(finding);
|
|
818
|
+
}
|
|
819
|
+
return { kept, suppressed, warnings };
|
|
820
|
+
}
|
|
821
|
+
function isRuleScopedIgnoreLine(line) {
|
|
822
|
+
const split = splitIgnoreLine(line.replace(/\r$/, ""));
|
|
823
|
+
if (split.escaped) return false;
|
|
824
|
+
const { code } = split;
|
|
825
|
+
if (!code.trim() || code.trimStart().startsWith("#")) return false;
|
|
826
|
+
const peeled = peelRules(code.trim());
|
|
827
|
+
return peeled.rules !== null && peeled.rules.length > 0 && !patternRejected(peeled.pattern);
|
|
828
|
+
}
|
|
829
|
+
function isUnscopedOverBroadLine(line) {
|
|
830
|
+
const split = splitIgnoreLine(line.replace(/\r$/, ""));
|
|
831
|
+
if (split.escaped) return false;
|
|
832
|
+
const { code } = split;
|
|
833
|
+
if (!code.trim() || code.trimStart().startsWith("#")) return false;
|
|
834
|
+
const peeled = peelRules(code.trim());
|
|
835
|
+
if (peeled.rules && peeled.rules.length > 0) return false;
|
|
836
|
+
return isOverBroad(peeled.pattern, null);
|
|
837
|
+
}
|
|
838
|
+
var SCAN_META = /* @__PURE__ */ Symbol.for("xploitscan.scanSuppression");
|
|
839
|
+
function attachScanSuppression(findings, meta) {
|
|
840
|
+
Object.defineProperty(findings, SCAN_META, { value: meta, enumerable: false });
|
|
841
|
+
return findings;
|
|
842
|
+
}
|
|
843
|
+
function readScanSuppression(findings) {
|
|
844
|
+
if (!findings || typeof findings !== "object") return null;
|
|
845
|
+
const value = findings[SCAN_META];
|
|
846
|
+
if (!value || typeof value !== "object") return null;
|
|
847
|
+
return value;
|
|
848
|
+
}
|
|
849
|
+
function countPass(inlineAlready, suppressed) {
|
|
850
|
+
let ignoreFile = 0;
|
|
851
|
+
let inline = inlineAlready;
|
|
852
|
+
for (const item of suppressed) {
|
|
853
|
+
if (item.suppression.source === "ignore-file") ignoreFile++;
|
|
854
|
+
else inline++;
|
|
855
|
+
}
|
|
856
|
+
return { inline, ignoreFile };
|
|
857
|
+
}
|
|
858
|
+
|
|
93
859
|
// src/models.ts
|
|
94
860
|
var MODEL_ANALYSIS = "claude-sonnet-5";
|
|
95
861
|
var MODEL_TRIAGE = "claude-haiku-5-5";
|
|
@@ -1873,18 +2639,8 @@ function isInsideFixMessage(content, matchIndex) {
|
|
|
1873
2639
|
const lineText = lineTextAt(content, matchIndex);
|
|
1874
2640
|
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);
|
|
1875
2641
|
}
|
|
1876
|
-
function filterSilenced(matches,
|
|
1877
|
-
|
|
1878
|
-
const lines = content.split("\n");
|
|
1879
|
-
const silencedByLine = /* @__PURE__ */ new Map();
|
|
1880
|
-
return matches.filter((m) => {
|
|
1881
|
-
let silenced = silencedByLine.get(m.line);
|
|
1882
|
-
if (silenced === void 0) {
|
|
1883
|
-
silenced = isLineSilenced(lines, m.line - 1, ruleId);
|
|
1884
|
-
silencedByLine.set(m.line, silenced);
|
|
1885
|
-
}
|
|
1886
|
-
return !silenced;
|
|
1887
|
-
});
|
|
2642
|
+
function filterSilenced(matches, _content, _ruleId) {
|
|
2643
|
+
return matches;
|
|
1888
2644
|
}
|
|
1889
2645
|
function lineStartOffsets(content) {
|
|
1890
2646
|
const starts = [0];
|
|
@@ -3934,7 +4690,6 @@ var unvalidatedRedirect = {
|
|
|
3934
4690
|
let m;
|
|
3935
4691
|
let commentLineStart = -1;
|
|
3936
4692
|
let commentLine = false;
|
|
3937
|
-
let silenceLines;
|
|
3938
4693
|
while ((m = navPattern.exec(content)) !== null) {
|
|
3939
4694
|
const navLineStart = content.lastIndexOf("\n", m.index - 1) + 1;
|
|
3940
4695
|
if (navLineStart !== commentLineStart) {
|
|
@@ -3947,7 +4702,6 @@ var unvalidatedRedirect = {
|
|
|
3947
4702
|
const isPureLiteral = /^["'`][^"'`]*["'`]$/.test(value);
|
|
3948
4703
|
if (!hasInterpolation && isPureLiteral) continue;
|
|
3949
4704
|
const line = lineNumberAt(content, m.index);
|
|
3950
|
-
if (isLineSilenced(silenceLines ??= content.split("\n"), line - 1, "VC016")) continue;
|
|
3951
4705
|
matches.push({
|
|
3952
4706
|
rule: "VC016",
|
|
3953
4707
|
title: unvalidatedRedirect.title,
|
|
@@ -5176,7 +5930,6 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
5176
5930
|
const sbomFile = isSbomPath(filePath);
|
|
5177
5931
|
const vendoredFile = isVendoredPath(filePath);
|
|
5178
5932
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
5179
|
-
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
5180
5933
|
for (const rule of ruleset) {
|
|
5181
5934
|
if (disabledRules.includes(rule.id)) continue;
|
|
5182
5935
|
if (sbomFile && rule.category !== "Secrets") continue;
|
|
@@ -5185,9 +5938,6 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
5185
5938
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
5186
5939
|
const onTestPath = isTestPath(filePath);
|
|
5187
5940
|
for (const match of matches) {
|
|
5188
|
-
if (silenceableLines && isLineSilenced(silenceableLines, match.line - 1, match.rule)) {
|
|
5189
|
-
continue;
|
|
5190
|
-
}
|
|
5191
5941
|
const live = isLive({
|
|
5192
5942
|
rule: match.rule,
|
|
5193
5943
|
category: match.category,
|
|
@@ -5216,7 +5966,10 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
5216
5966
|
});
|
|
5217
5967
|
}
|
|
5218
5968
|
}
|
|
5219
|
-
|
|
5969
|
+
const deduped = deduplicateFindings(findings);
|
|
5970
|
+
if (!/-OK\b/i.test(content)) return deduped;
|
|
5971
|
+
const applied = applySuppressions(deduped, { filesByPath: { [filePath]: content } });
|
|
5972
|
+
return attachInlineSuppressed(applied.kept, applied.suppressed);
|
|
5220
5973
|
}
|
|
5221
5974
|
|
|
5222
5975
|
// src/rule-counts.ts
|
|
@@ -5683,6 +6436,7 @@ function entropySecretValues(filePath, content) {
|
|
|
5683
6436
|
}
|
|
5684
6437
|
function scanEntropyFiles(files, collect) {
|
|
5685
6438
|
const findings = [];
|
|
6439
|
+
const inlineDropped = [];
|
|
5686
6440
|
for (const { path: filePath, content } of files) {
|
|
5687
6441
|
if (SKIP_FILES.test(filePath)) continue;
|
|
5688
6442
|
if (SKIP_FILENAMES.test(filePath)) continue;
|
|
@@ -5696,6 +6450,8 @@ function scanEntropyFiles(files, collect) {
|
|
|
5696
6450
|
const vendored = isVendoredPath(filePath);
|
|
5697
6451
|
const dotenv = isDotenvPath(filePath) && !DOTENV_EXAMPLE_RE.test(filePath);
|
|
5698
6452
|
const lines = content.split("\n");
|
|
6453
|
+
const folded = content.toLowerCase();
|
|
6454
|
+
const markerIndex = folded.includes("-ok") || folded.includes("-0k") ? buildMarkerIndex(lines, filePath) : null;
|
|
5699
6455
|
let verificationDepth = -1;
|
|
5700
6456
|
let braceDepth = 0;
|
|
5701
6457
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -5794,7 +6550,6 @@ function scanEntropyFiles(files, collect) {
|
|
|
5794
6550
|
}
|
|
5795
6551
|
let safeWords;
|
|
5796
6552
|
let verificationMeta;
|
|
5797
|
-
let silenced;
|
|
5798
6553
|
let snippet;
|
|
5799
6554
|
const seenValues = /* @__PURE__ */ new Set();
|
|
5800
6555
|
for (const { value, beforeAssign, dotenvName, variableName, contextFrom, contextTo } of candidates) {
|
|
@@ -5838,8 +6593,21 @@ function scanEntropyFiles(files, collect) {
|
|
|
5838
6593
|
if (dotenvName && /(?:^|_)IDS?$/i.test(dotenvName) && !isSecretVariableName(dotenvName)) continue;
|
|
5839
6594
|
const isLikelySecret = isSecretVariableName(varName) || publicEnv?.secret === true;
|
|
5840
6595
|
if (entropy < 4.5 && !isLikelySecret) continue;
|
|
5841
|
-
if (
|
|
5842
|
-
|
|
6596
|
+
if (markerIndex?.covers(i, "ENTROPY")) {
|
|
6597
|
+
inlineDropped.push({
|
|
6598
|
+
id: `ENTROPY-${filePath}:${i + 1}`,
|
|
6599
|
+
rule: "ENTROPY",
|
|
6600
|
+
severity: "high",
|
|
6601
|
+
title: "High-Entropy String Detected (Possible Secret)",
|
|
6602
|
+
description: "",
|
|
6603
|
+
file: filePath,
|
|
6604
|
+
line: i + 1,
|
|
6605
|
+
snippet: "",
|
|
6606
|
+
category: "Secrets",
|
|
6607
|
+
source: "custom"
|
|
6608
|
+
});
|
|
6609
|
+
continue;
|
|
6610
|
+
}
|
|
5843
6611
|
collect?.push(value);
|
|
5844
6612
|
const masked = maskSecretValue(value);
|
|
5845
6613
|
if (snippet === void 0) snippet = getSnippet2(lines, i + 1);
|
|
@@ -5865,7 +6633,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5865
6633
|
}
|
|
5866
6634
|
}
|
|
5867
6635
|
}
|
|
5868
|
-
return findings;
|
|
6636
|
+
return attachInlineSuppressed(findings, inlineDropped);
|
|
5869
6637
|
}
|
|
5870
6638
|
|
|
5871
6639
|
// src/ai-status-constants.ts
|
|
@@ -5939,7 +6707,7 @@ var FAIL_REASONS = /* @__PURE__ */ new Set([
|
|
|
5939
6707
|
"exception",
|
|
5940
6708
|
"client_init"
|
|
5941
6709
|
]);
|
|
5942
|
-
function
|
|
6710
|
+
function clampCount2(raw) {
|
|
5943
6711
|
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) return 0;
|
|
5944
6712
|
return Math.min(Math.trunc(raw), 1e6);
|
|
5945
6713
|
}
|
|
@@ -5989,9 +6757,9 @@ function planCause(specific) {
|
|
|
5989
6757
|
}
|
|
5990
6758
|
}
|
|
5991
6759
|
function toAiDegraded(input = {}) {
|
|
5992
|
-
const total =
|
|
5993
|
-
let reviewed =
|
|
5994
|
-
let capped =
|
|
6760
|
+
const total = clampCount2(input.total);
|
|
6761
|
+
let reviewed = clampCount2(input.reviewed);
|
|
6762
|
+
let capped = clampCount2(input.capped);
|
|
5995
6763
|
if (reviewed > total) reviewed = total;
|
|
5996
6764
|
if (reviewed + capped > total) capped = total - reviewed;
|
|
5997
6765
|
const unreviewed = total - reviewed - capped;
|
|
@@ -11318,39 +12086,52 @@ export {
|
|
|
11318
12086
|
FREE_RULE_COUNT,
|
|
11319
12087
|
GRADE_FINDINGS_PER_RULE,
|
|
11320
12088
|
INTENT_EXPECTATIONS,
|
|
12089
|
+
MAX_IGNORE_BYTES,
|
|
12090
|
+
MAX_IGNORE_LINES,
|
|
12091
|
+
MAX_SUPPRESSED_LIST,
|
|
12092
|
+
MAX_WARNING_CAP,
|
|
11321
12093
|
MODEL_ANALYSIS,
|
|
11322
12094
|
MODEL_POLICY_REVIEWED,
|
|
11323
12095
|
MODEL_REVIEW_INTERVAL_DAYS,
|
|
11324
12096
|
MODEL_TEMPERATURE,
|
|
11325
12097
|
MODEL_TRIAGE,
|
|
12098
|
+
NESTED_IGNORE_WARNING,
|
|
11326
12099
|
NON_APP_PATH_PATTERNS,
|
|
11327
12100
|
PLAN_CAUSES,
|
|
11328
12101
|
PLAN_UNVERIFIED_NOTICE,
|
|
11329
12102
|
PRO_RULE_COUNT,
|
|
11330
12103
|
PUBLIC_ENV_PREFIX_RE,
|
|
11331
12104
|
QUALITY_EXAMPLES,
|
|
12105
|
+
RULE_ID_PATTERN,
|
|
11332
12106
|
RULE_IMPACTS,
|
|
11333
12107
|
SCANNER_VERSION,
|
|
11334
12108
|
SCAN_AI_DEGRADED_KEYS,
|
|
11335
12109
|
SCAN_TOKEN_NULL_KEYS,
|
|
11336
12110
|
SERVER_ACTION_WRITE_RE,
|
|
12111
|
+
SUPPRESSION_REGEXES,
|
|
11337
12112
|
TEST_FILE_PATTERN,
|
|
11338
12113
|
TOTAL_RULE_COUNT,
|
|
11339
12114
|
WEBHOOK_EVENT_TYPES,
|
|
11340
12115
|
WEBHOOK_REASONS,
|
|
11341
12116
|
aiStatusLine,
|
|
11342
12117
|
allRules,
|
|
12118
|
+
applySuppressions,
|
|
11343
12119
|
assessHeaders,
|
|
11344
12120
|
astMatch,
|
|
12121
|
+
attachInlineSuppressed,
|
|
12122
|
+
attachScanSuppression,
|
|
11345
12123
|
billingWebhookUnmatchedProps,
|
|
11346
12124
|
bucketFiles,
|
|
12125
|
+
buildMarkerIndex,
|
|
11347
12126
|
buildProjectContext,
|
|
11348
12127
|
buildQualityContext,
|
|
11349
12128
|
buildReviewPrompt,
|
|
11350
12129
|
buildTaintMap,
|
|
11351
12130
|
calculateGrade,
|
|
11352
12131
|
callSpreads,
|
|
12132
|
+
capWarnings,
|
|
11353
12133
|
checkIntent,
|
|
12134
|
+
clampCount,
|
|
11354
12135
|
classifyExposure,
|
|
11355
12136
|
classifyPublicEnvVar,
|
|
11356
12137
|
classifyStatement,
|
|
@@ -11358,6 +12139,7 @@ export {
|
|
|
11358
12139
|
complianceMap,
|
|
11359
12140
|
consoleLogProduction,
|
|
11360
12141
|
corsWildcard,
|
|
12142
|
+
countPass,
|
|
11361
12143
|
dangerousInnerHTML,
|
|
11362
12144
|
deduplicateFindings,
|
|
11363
12145
|
detectBuilder,
|
|
@@ -11402,19 +12184,26 @@ export {
|
|
|
11402
12184
|
isMethodCall,
|
|
11403
12185
|
isPrivateAddress,
|
|
11404
12186
|
isProtectedFromAiRemoval,
|
|
12187
|
+
isRootIgnorePath,
|
|
12188
|
+
isRuleScopedIgnoreLine,
|
|
11405
12189
|
isSbomPath,
|
|
11406
12190
|
isServerSideFile,
|
|
11407
12191
|
isServerTarget,
|
|
11408
12192
|
isTestFile,
|
|
11409
12193
|
isTestPath,
|
|
11410
12194
|
isUngradedFinding,
|
|
12195
|
+
isUnscopedOverBroadLine,
|
|
11411
12196
|
isVendoredFinding,
|
|
11412
12197
|
isVendoredPath,
|
|
12198
|
+
isWellFormedRuleId,
|
|
11413
12199
|
lineNumberAt,
|
|
11414
12200
|
lineTextAt,
|
|
12201
|
+
markerCoversLine,
|
|
11415
12202
|
maskComments,
|
|
11416
12203
|
maskOutboundAuthNoise,
|
|
11417
12204
|
maskSecretValue,
|
|
12205
|
+
maskStringLiterals,
|
|
12206
|
+
matchIgnore,
|
|
11418
12207
|
missingAuthMiddleware,
|
|
11419
12208
|
missingCSP,
|
|
11420
12209
|
missingErrorBoundary,
|
|
@@ -11426,11 +12215,17 @@ export {
|
|
|
11426
12215
|
normalizeScanPath,
|
|
11427
12216
|
packReviewBatches,
|
|
11428
12217
|
parseFile,
|
|
12218
|
+
parseIgnoreFile,
|
|
12219
|
+
parseIgnoreSources,
|
|
12220
|
+
parseMarkers,
|
|
11429
12221
|
parseScanTarget,
|
|
11430
12222
|
parseSupabaseConfig,
|
|
11431
12223
|
perCallTimeoutMs,
|
|
11432
12224
|
planCause,
|
|
12225
|
+
publicSuppressedRecord,
|
|
11433
12226
|
qualityRules,
|
|
12227
|
+
readInlineSuppressed,
|
|
12228
|
+
readScanSuppression,
|
|
11434
12229
|
replaceBlockComments,
|
|
11435
12230
|
routeForFile,
|
|
11436
12231
|
runCustomRules,
|
|
@@ -11445,6 +12240,7 @@ export {
|
|
|
11445
12240
|
stripeWebhookUnprotected,
|
|
11446
12241
|
supabaseFunctionName,
|
|
11447
12242
|
supabaseNoRLS,
|
|
12243
|
+
suppressionSummary,
|
|
11448
12244
|
toAiDegraded,
|
|
11449
12245
|
todoLeftInCode,
|
|
11450
12246
|
tryParse,
|
|
@@ -11455,6 +12251,8 @@ export {
|
|
|
11455
12251
|
vendoredReason,
|
|
11456
12252
|
visitBinary,
|
|
11457
12253
|
visitCalls,
|
|
12254
|
+
warningForUpload,
|
|
12255
|
+
warningLine,
|
|
11458
12256
|
weakHashing,
|
|
11459
12257
|
xssVulnerability
|
|
11460
12258
|
};
|