xploitscan-shared-rules 2.4.11 → 2.4.12
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/README.md +1 -1
- package/dist/index.cjs +206 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +206 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -33,6 +33,11 @@ interface ProjectContext {
|
|
|
33
33
|
* unknown rather than assuming either way.
|
|
34
34
|
*/
|
|
35
35
|
supabaseEdgeVerifyJwt?: Map<string, boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* App Router route files whose every handler only delegates to an imported
|
|
38
|
+
* function that opens with a shared-secret check. VC003 skips their handlers.
|
|
39
|
+
*/
|
|
40
|
+
secretGuardedRoutes?: Set<string>;
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* Parse `supabase/config.toml` for per-function `verify_jwt` settings.
|
|
@@ -160,7 +165,7 @@ interface CustomRule {
|
|
|
160
165
|
* before a scan can be saved without enough provenance to explain a changed
|
|
161
166
|
* grade.
|
|
162
167
|
*/
|
|
163
|
-
declare const SCANNER_VERSION = "2.4.
|
|
168
|
+
declare const SCANNER_VERSION = "2.4.12";
|
|
164
169
|
|
|
165
170
|
/**
|
|
166
171
|
* Line-oriented helpers shared by every rule. Pure string manipulation — no fs
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ interface ProjectContext {
|
|
|
33
33
|
* unknown rather than assuming either way.
|
|
34
34
|
*/
|
|
35
35
|
supabaseEdgeVerifyJwt?: Map<string, boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* App Router route files whose every handler only delegates to an imported
|
|
38
|
+
* function that opens with a shared-secret check. VC003 skips their handlers.
|
|
39
|
+
*/
|
|
40
|
+
secretGuardedRoutes?: Set<string>;
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* Parse `supabase/config.toml` for per-function `verify_jwt` settings.
|
|
@@ -160,7 +165,7 @@ interface CustomRule {
|
|
|
160
165
|
* before a scan can be saved without enough provenance to explain a changed
|
|
161
166
|
* grade.
|
|
162
167
|
*/
|
|
163
|
-
declare const SCANNER_VERSION = "2.4.
|
|
168
|
+
declare const SCANNER_VERSION = "2.4.12";
|
|
164
169
|
|
|
165
170
|
/**
|
|
166
171
|
* Line-oriented helpers shared by every rule. Pure string manipulation — no fs
|
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.12";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -345,6 +345,134 @@ function classifyExposure(filePath) {
|
|
|
345
345
|
return "unknown";
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
+
// src/route-delegation.ts
|
|
349
|
+
var ROUTE_FILE_RE = /(?:^|\/)app\/(?:[^/]+\/)*route\.[jt]sx?$/;
|
|
350
|
+
var METHOD = "(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)";
|
|
351
|
+
var HANDLER_EXPORT_RE = new RegExp(`\\bexport\\s+(?:(?:async\\s+)?function\\s+${METHOD}\\b|const\\s+${METHOD}\\s*=)`, "g");
|
|
352
|
+
var DELEGATING_HANDLER_RE = new RegExp(
|
|
353
|
+
`\\bexport\\s+(?:async\\s+)?function\\s+${METHOD}\\s*\\(\\s*([A-Za-z_$][\\w$]{0,40})[^()]{0,200}\\)[^{;]{0,80}\\{\\s*return\\s+(?:await\\s+)?([A-Za-z_$][\\w$]{0,64})\\s*\\(\\s*\\1\\s*\\)\\s*;?\\s*\\}`,
|
|
354
|
+
"y"
|
|
355
|
+
);
|
|
356
|
+
var HANDLER_HEAD_RE = new RegExp(
|
|
357
|
+
`\\bexport\\s+(?:(?:async\\s+)?function\\s+${METHOD}\\s*\\([^()]{0,200}\\)[^{;]{0,80}\\{|const\\s+${METHOD}\\s*(?::[^=;\\n]{0,80})?=\\s*(?:async\\s*)?\\([^()]{0,200}\\)[^{;=]{0,80}=>\\s*\\{)`,
|
|
358
|
+
"y"
|
|
359
|
+
);
|
|
360
|
+
var OTHER_EXPORT_RE = /\bexport\s+(?:let|var)\s+(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b|\bexport\s*\{|\bexport\s*\*/;
|
|
361
|
+
var STR = `"[^"\\n]{0,200}"|'[^'\\n]{0,200}'`;
|
|
362
|
+
var ID = `[A-Za-z_$][\\w$]{0,40}`;
|
|
363
|
+
var READ_DECL_RE = new RegExp(
|
|
364
|
+
`(?:const|let)\\s+(?:([A-Za-z_$][\\w$]{0,40})|\\{[\\s\\w$,]{1,200}\\})\\s*(?::[^=;\\n]{0,80})?=\\s*(?![^;\\n]{0,300}?process\\.env)(?:await\\s+[A-Za-z_$][\\w$]{0,40}\\.json\\(\\s*\\)|(\\[\\s*(?:(?:${STR})\\s*,\\s*){0,20}(?:(?:${STR})\\s*)?\\])|\\(\\s*await\\s+headers\\(\\s*\\)\\s*\\)\\.get\\(\\s*(?:${STR})\\s*\\)(?:\\s*(?:\\|\\||\\?\\?)\\s*(?:${STR}))?|[^;"'\`\\n{}()]{0,200}(?:\\.get\\(\\s*(?:${STR}|[\\w$.]{1,80})\\s*\\)[^;"'\`\\n{}()]{0,100})?);\\s*`,
|
|
365
|
+
"y"
|
|
366
|
+
);
|
|
367
|
+
var ENV_DOT = `process\\.env\\.`;
|
|
368
|
+
var ENV_PUBLIC_EXCL = `(?!(?:NEXT_PUBLIC|PUBLIC|VITE|EXPO_PUBLIC|REACT_APP)_)`;
|
|
369
|
+
var ENV_NAME_TAIL = `\\w{0,60}(?:SECRET|TOKEN|KEY)\\b`;
|
|
370
|
+
var ENV_SECRET = ENV_DOT + ENV_PUBLIC_EXCL + ENV_NAME_TAIL;
|
|
371
|
+
var OPERAND = `(?<![\\w$.])(?!(?:undefined|null)\\b)[A-Za-z_$][\\w$.?]{0,80}(?:\\(\\s*(?:${STR}|[\\w$.]{0,80})\\s*\\))?`;
|
|
372
|
+
var NOT_LIT = `(?!(?:undefined|null)\\b)[A-Za-z_$]`;
|
|
373
|
+
var CMP = `(?:${OPERAND}\\s*!==\\s*${ENV_SECRET}|${ENV_SECRET}\\s*!==\\s*${NOT_LIT}|!\\s*\\(\\s*${OPERAND}\\s*===\\s*${ENV_SECRET}\\s*\\)|!\\s*\\(\\s*${ENV_SECRET}\\s*===\\s*${NOT_LIT}|!\\s*(?:crypto\\s*\\.\\s*)?timingSafeEqual\\s*\\([^;\\n&]{0,300}?${ENV_SECRET})`;
|
|
374
|
+
var COND = `[^;\\n{}&]{0,300}?`;
|
|
375
|
+
var COND_REJECT = `(?![^\\n]{0,300}?!\\s*\\([^;\\n]{0,200}?!==)(?![^\\n]{0,300}?(?:[^!=<>]==(?!=)|!=(?!=)))`;
|
|
376
|
+
var INCLUDES_DECL_RE = new RegExp(
|
|
377
|
+
`(?:const|let)\\s+(${ID})\\s*(?::[^=;\\n]{0,80})?=\\s*(${ID})\\.includes\\(\\s*${ID}\\s*\\)\\s*;\\s*`,
|
|
378
|
+
"y"
|
|
379
|
+
);
|
|
380
|
+
var REJECT_HEAD = `\\)\\s*(?:\\{\\s*(?:console\\.(?:error|warn|log|info)\\s*\\(\\s*(?:${STR})\\s*\\)\\s*;\\s*)?)?(?:throw\\b|return\\b`;
|
|
381
|
+
var REJECT_CODE = `[^;\\n]{0,200}?(?:\\b40[13]\\b|`;
|
|
382
|
+
var REJECT_WORDS = `[Uu]nauthori[sz]ed|[Ff]orbidden))`;
|
|
383
|
+
var REJECT = REJECT_HEAD + REJECT_CODE + REJECT_WORDS;
|
|
384
|
+
var COND_TAIL = `(?:\\?\\.|(?!function\\b)[^;\\n{}&?]){0,300}?`;
|
|
385
|
+
var SECRET_GUARD_RE = new RegExp(`if\\s*\\(${COND_REJECT}${COND}${CMP}${COND_TAIL}${REJECT}`, "y");
|
|
386
|
+
var WS_RE = /(?:\s+|\/\/[^\n]{0,400}(?=\n|$)|\/\*(?:[^*]|\*(?!\/)){0,800}\*\/){0,40}/y;
|
|
387
|
+
var MAX_DECLS = 6;
|
|
388
|
+
function opensWithGuard(body) {
|
|
389
|
+
let i = 1;
|
|
390
|
+
const arrays = /* @__PURE__ */ new Set();
|
|
391
|
+
for (let k = 0; ; k++) {
|
|
392
|
+
WS_RE.lastIndex = i;
|
|
393
|
+
WS_RE.exec(body);
|
|
394
|
+
i = WS_RE.lastIndex;
|
|
395
|
+
if (k === MAX_DECLS) break;
|
|
396
|
+
INCLUDES_DECL_RE.lastIndex = i;
|
|
397
|
+
const inc = INCLUDES_DECL_RE.exec(body);
|
|
398
|
+
if (inc !== null) {
|
|
399
|
+
if (!arrays.has(inc[2])) break;
|
|
400
|
+
arrays.delete(inc[1]);
|
|
401
|
+
i = INCLUDES_DECL_RE.lastIndex;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
READ_DECL_RE.lastIndex = i;
|
|
405
|
+
const d = READ_DECL_RE.exec(body);
|
|
406
|
+
if (d === null) break;
|
|
407
|
+
if (d[1] !== void 0) {
|
|
408
|
+
if (d[2] !== void 0) arrays.add(d[1]);
|
|
409
|
+
else arrays.delete(d[1]);
|
|
410
|
+
}
|
|
411
|
+
i = READ_DECL_RE.lastIndex;
|
|
412
|
+
}
|
|
413
|
+
SECRET_GUARD_RE.lastIndex = i;
|
|
414
|
+
return SECRET_GUARD_RE.test(body);
|
|
415
|
+
}
|
|
416
|
+
function firstMatches(text, re, max) {
|
|
417
|
+
const found = [];
|
|
418
|
+
re.lastIndex = 0;
|
|
419
|
+
for (let m = re.exec(text); m !== null && found.length < max; m = re.exec(text)) found.push(m);
|
|
420
|
+
re.lastIndex = 0;
|
|
421
|
+
return found;
|
|
422
|
+
}
|
|
423
|
+
var esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
424
|
+
function secretGuardedRoutes(files) {
|
|
425
|
+
const out = /* @__PURE__ */ new Set();
|
|
426
|
+
for (const f of files) {
|
|
427
|
+
if (!ROUTE_FILE_RE.test(f.path) || OTHER_EXPORT_RE.test(f.content)) continue;
|
|
428
|
+
const exported = firstMatches(f.content, HANDLER_EXPORT_RE, 8);
|
|
429
|
+
if (exported.length === 0 || exported.length > 7) continue;
|
|
430
|
+
const callees = /* @__PURE__ */ new Set();
|
|
431
|
+
let readable = true;
|
|
432
|
+
for (const e of exported) {
|
|
433
|
+
DELEGATING_HANDLER_RE.lastIndex = e.index;
|
|
434
|
+
const h = DELEGATING_HANDLER_RE.exec(f.content);
|
|
435
|
+
if (h !== null) {
|
|
436
|
+
callees.add(h[2]);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
HANDLER_HEAD_RE.lastIndex = e.index;
|
|
440
|
+
const head = HANDLER_HEAD_RE.exec(f.content);
|
|
441
|
+
const open = head === null ? -1 : e.index + head[0].length - 1;
|
|
442
|
+
if (open === -1 || !opensWithGuard(f.content.slice(open, open + 4e3))) {
|
|
443
|
+
readable = false;
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (!readable) continue;
|
|
448
|
+
if ([...callees].every((fn) => calleeIsGuarded(fn, f.content, files))) out.add(f.path);
|
|
449
|
+
}
|
|
450
|
+
return out;
|
|
451
|
+
}
|
|
452
|
+
function calleeIsGuarded(fn, route, files) {
|
|
453
|
+
let spec = null;
|
|
454
|
+
for (const m of route.matchAll(/\bimport\s*\{([^{}]{0,1000})\}\s*from\s*["']([^"'\n]{1,200})["']/g)) {
|
|
455
|
+
if (m[1].split(",").some((n) => n.trim() === fn)) {
|
|
456
|
+
spec = m[2];
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (spec === null) return false;
|
|
461
|
+
const tail = spec.replace(/^(?:@|~)\//, "").replace(/^(?:\.\.?\/)+/, "");
|
|
462
|
+
const tailRe = new RegExp(`(?:^|/)${esc(tail)}(?:\\.[jt]sx?|/index\\.[jt]sx?)$`);
|
|
463
|
+
const targets = files.filter((g) => tailRe.test(g.path));
|
|
464
|
+
if (targets.length !== 1) return false;
|
|
465
|
+
const F = esc(fn);
|
|
466
|
+
const defRe = new RegExp(
|
|
467
|
+
`\\bfunction\\s+${F}\\s*\\([^()]{0,200}\\)[^{;]{0,80}\\{|\\b(?:const|let)\\s+${F}\\s*(?::[^=;\\n]{0,80})?=\\s*(?:async\\s*)?\\([^()]{0,200}\\)[^{;=]{0,80}=>\\s*\\{`,
|
|
468
|
+
"g"
|
|
469
|
+
);
|
|
470
|
+
const defs = [...targets[0].content.matchAll(defRe)];
|
|
471
|
+
if (defs.length !== 1) return false;
|
|
472
|
+
const open = defs[0].index + defs[0][0].length - 1;
|
|
473
|
+
return opensWithGuard(targets[0].content.slice(open, open + 4e3));
|
|
474
|
+
}
|
|
475
|
+
|
|
348
476
|
// src/project-context.ts
|
|
349
477
|
var TOML_FN_SECTION_RE = /^\s*\[functions\.(?:"([^"]+)"|([A-Za-z0-9._-]+))\]\s*$/;
|
|
350
478
|
var TOML_VERIFY_JWT_RE = /^\s*verify_jwt\s*=\s*(true|false)\s*(?:#.*)?$/i;
|
|
@@ -378,6 +506,8 @@ function buildProjectContext(files) {
|
|
|
378
506
|
const parsed = parseSupabaseConfig(config.content);
|
|
379
507
|
if (parsed.size > 0) ctx.supabaseEdgeVerifyJwt = parsed;
|
|
380
508
|
}
|
|
509
|
+
const guarded = secretGuardedRoutes(files);
|
|
510
|
+
if (guarded.size > 0) ctx.secretGuardedRoutes = guarded;
|
|
381
511
|
return ctx;
|
|
382
512
|
}
|
|
383
513
|
|
|
@@ -1742,8 +1872,20 @@ function isInsideFixMessage(content, matchIndex) {
|
|
|
1742
1872
|
function filterSilenced(matches, content, ruleId) {
|
|
1743
1873
|
if (matches.length === 0) return matches;
|
|
1744
1874
|
const lines = content.split("\n");
|
|
1745
|
-
const
|
|
1746
|
-
return matches.filter((m) =>
|
|
1875
|
+
const silencedByLine = /* @__PURE__ */ new Map();
|
|
1876
|
+
return matches.filter((m) => {
|
|
1877
|
+
let silenced = silencedByLine.get(m.line);
|
|
1878
|
+
if (silenced === void 0) {
|
|
1879
|
+
silenced = isLineSilenced(lines, m.line - 1, ruleId);
|
|
1880
|
+
silencedByLine.set(m.line, silenced);
|
|
1881
|
+
}
|
|
1882
|
+
return !silenced;
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
function lineStartOffsets(content) {
|
|
1886
|
+
const starts = [0];
|
|
1887
|
+
for (let i = content.indexOf("\n"); i !== -1; i = content.indexOf("\n", i + 1)) starts.push(i + 1);
|
|
1888
|
+
return starts;
|
|
1747
1889
|
}
|
|
1748
1890
|
function findMatches(content, pattern, rule, filePath, fixTemplate) {
|
|
1749
1891
|
const re = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
@@ -1766,12 +1908,24 @@ function findMatchesAt(content, found, rule, filePath, fixTemplate) {
|
|
|
1766
1908
|
let scanned = 0;
|
|
1767
1909
|
let lineNum = 1;
|
|
1768
1910
|
const MAX_MATCHES = 500;
|
|
1911
|
+
let skipLineStart = -1;
|
|
1912
|
+
let skipLine = false;
|
|
1913
|
+
let snippetLine = -1;
|
|
1914
|
+
let snippet = "";
|
|
1769
1915
|
for (const m of found) {
|
|
1770
|
-
|
|
1771
|
-
if (
|
|
1916
|
+
const lineStart = content.lastIndexOf("\n", m.index - 1) + 1;
|
|
1917
|
+
if (lineStart !== skipLineStart) {
|
|
1918
|
+
skipLineStart = lineStart;
|
|
1919
|
+
skipLine = isCommentLine(content, m.index) || isInsideFixMessage(content, m.index);
|
|
1920
|
+
}
|
|
1921
|
+
if (skipLine) continue;
|
|
1772
1922
|
for (; scanned < m.index; scanned++) {
|
|
1773
1923
|
if (content.charCodeAt(scanned) === 10) lineNum++;
|
|
1774
1924
|
}
|
|
1925
|
+
if (lineNum !== snippetLine) {
|
|
1926
|
+
snippetLine = lineNum;
|
|
1927
|
+
snippet = getSnippet(content, lineNum);
|
|
1928
|
+
}
|
|
1775
1929
|
matches.push({
|
|
1776
1930
|
rule: rule.id,
|
|
1777
1931
|
title: rule.title,
|
|
@@ -1779,7 +1933,7 @@ function findMatchesAt(content, found, rule, filePath, fixTemplate) {
|
|
|
1779
1933
|
category: rule.category,
|
|
1780
1934
|
file: filePath,
|
|
1781
1935
|
line: lineNum,
|
|
1782
|
-
snippet
|
|
1936
|
+
snippet,
|
|
1783
1937
|
fix: fixTemplate?.(m)
|
|
1784
1938
|
});
|
|
1785
1939
|
if (matches.length >= MAX_MATCHES) break;
|
|
@@ -2510,6 +2664,7 @@ function unauthenticatedTanStackHandlers(masked, filePath) {
|
|
|
2510
2664
|
}
|
|
2511
2665
|
return hits;
|
|
2512
2666
|
}
|
|
2667
|
+
var NAMED_ROUTE_EXPORT_RE = /export\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/i;
|
|
2513
2668
|
var SERVER_ACTION_WRITE_RE = [
|
|
2514
2669
|
/\b(?:kv|redis|cache|upstash)\s*\.\s*(?:set|del|hset|hdel|incr\w{0,4}|decr\w{0,4}|lpush|rpush|sadd|srem|zadd|expire|getdel)\s*\(/,
|
|
2515
2670
|
/\b(?:stripe|paypal|braintree|lemonsqueezy|paddle)\s*\.\s*\w{1,40}\s*\.\s*(?:create|update|del|cancel|capture|refund)\w{0,10}\s*\(/,
|
|
@@ -2649,9 +2804,10 @@ var missingAuthMiddleware = {
|
|
|
2649
2804
|
scopeCache.set(index, scope);
|
|
2650
2805
|
return scope;
|
|
2651
2806
|
};
|
|
2807
|
+
let fileHasAuth;
|
|
2652
2808
|
const handlerHasAuth = (index) => {
|
|
2653
2809
|
const scope = scopeAt(index);
|
|
2654
|
-
if (scope === null) return handlerAuthPatterns.some((p) => p.test(codeForAuth));
|
|
2810
|
+
if (scope === null) return fileHasAuth ??= handlerAuthPatterns.some((p) => p.test(codeForAuth));
|
|
2655
2811
|
return handlerAuthPatterns.some((p) => p.test(scope));
|
|
2656
2812
|
};
|
|
2657
2813
|
const matches = [];
|
|
@@ -2692,10 +2848,17 @@ var missingAuthMiddleware = {
|
|
|
2692
2848
|
}
|
|
2693
2849
|
const indexOfLine = (line) => lineStarts[Math.max(0, Math.min(line - 1, lineStarts.length - 1))];
|
|
2694
2850
|
const isPublicRootGet = (index) => /\.\s*get\s*\(\s*["'`]\/["'`]\s*,/i.test(content.slice(index, index + 240));
|
|
2851
|
+
const lineText = (index) => {
|
|
2852
|
+
const end = content.indexOf("\n", index);
|
|
2853
|
+
return content.slice(index, end === -1 ? content.length : end);
|
|
2854
|
+
};
|
|
2855
|
+
const secretGuarded = project?.secretGuardedRoutes?.has(filePath) === true;
|
|
2695
2856
|
const unauthenticated = matches.filter((m) => {
|
|
2696
2857
|
const index = indexOfLine(m.line);
|
|
2697
2858
|
if (isPublicRootGet(index) || handlerHasAuth(index)) return false;
|
|
2698
|
-
|
|
2859
|
+
const namedExport = NAMED_ROUTE_EXPORT_RE.exec(lineText(index));
|
|
2860
|
+
if (namedExport && secretGuarded && /^[A-Z]+$/.test(namedExport[1])) return false;
|
|
2861
|
+
if (useServerPatterns.length > 0 && (!routeLines.has(m.line) || namedExport !== null && !/^[A-Z]+$/.test(namedExport[1]))) {
|
|
2699
2862
|
const scope = scopeAt(index);
|
|
2700
2863
|
if (scope !== null && !SERVER_ACTION_WRITE_RE.some((re) => re.test(scope))) return false;
|
|
2701
2864
|
}
|
|
@@ -3377,6 +3540,9 @@ var evalUsage = {
|
|
|
3377
3540
|
const hasEvalInString = /["'`]eval(?:-source-map|["'`])/i.test(content);
|
|
3378
3541
|
if (hasEvalInString && !/\beval\s*\([^)]{0,500}(?:req\.|body\.|input|params|user|data)/i.test(content)) return [];
|
|
3379
3542
|
const matches = [];
|
|
3543
|
+
let evalLineStarts;
|
|
3544
|
+
let evalLastLine = -1;
|
|
3545
|
+
let evalLastKeep = false;
|
|
3380
3546
|
for (const p of patterns) {
|
|
3381
3547
|
const rawMatches = findMatches(
|
|
3382
3548
|
content,
|
|
@@ -3386,11 +3552,18 @@ var evalUsage = {
|
|
|
3386
3552
|
() => "Replace eval() with JSON.parse() for data, or a proper parser for expressions. Never pass user input to eval()."
|
|
3387
3553
|
);
|
|
3388
3554
|
for (const rm of rawMatches) {
|
|
3389
|
-
|
|
3555
|
+
if (rm.line === evalLastLine) {
|
|
3556
|
+
if (evalLastKeep) matches.push(rm);
|
|
3557
|
+
continue;
|
|
3558
|
+
}
|
|
3559
|
+
evalLastLine = rm.line;
|
|
3560
|
+
evalLastKeep = false;
|
|
3561
|
+
const lineStart = (evalLineStarts ??= lineStartOffsets(content))[rm.line - 1];
|
|
3390
3562
|
const lineEnd = content.indexOf("\n", lineStart + 1);
|
|
3391
3563
|
const lineText = content.substring(lineStart, lineEnd === -1 ? content.length : lineEnd);
|
|
3392
3564
|
if (/devtool|source-map/i.test(lineText)) continue;
|
|
3393
3565
|
if (/(?:description|title|message)\s*[:=]/i.test(lineText)) continue;
|
|
3566
|
+
evalLastKeep = true;
|
|
3394
3567
|
matches.push(rm);
|
|
3395
3568
|
}
|
|
3396
3569
|
}
|
|
@@ -3409,14 +3582,22 @@ var unvalidatedRedirect = {
|
|
|
3409
3582
|
const matches = [];
|
|
3410
3583
|
const navPattern = /(?:window\.location(?:\.href)?\s*=\s*|window\.location\.(?:assign|replace)\s*\(\s*)([^;\n)]+)/g;
|
|
3411
3584
|
let m;
|
|
3585
|
+
let commentLineStart = -1;
|
|
3586
|
+
let commentLine = false;
|
|
3587
|
+
let silenceLines;
|
|
3412
3588
|
while ((m = navPattern.exec(content)) !== null) {
|
|
3413
|
-
|
|
3589
|
+
const navLineStart = content.lastIndexOf("\n", m.index - 1) + 1;
|
|
3590
|
+
if (navLineStart !== commentLineStart) {
|
|
3591
|
+
commentLineStart = navLineStart;
|
|
3592
|
+
commentLine = isCommentLine(content, m.index);
|
|
3593
|
+
}
|
|
3594
|
+
if (commentLine) continue;
|
|
3414
3595
|
const value = m[1].trim();
|
|
3415
3596
|
const hasInterpolation = /\$\{/.test(value);
|
|
3416
3597
|
const isPureLiteral = /^["'`][^"'`]*["'`]$/.test(value);
|
|
3417
3598
|
if (!hasInterpolation && isPureLiteral) continue;
|
|
3418
|
-
if (isInlineSilenced(content, m.index, "VC016")) continue;
|
|
3419
3599
|
const line = lineNumberAt(content, m.index);
|
|
3600
|
+
if (isLineSilenced(silenceLines ??= content.split("\n"), line - 1, "VC016")) continue;
|
|
3420
3601
|
matches.push({
|
|
3421
3602
|
rule: "VC016",
|
|
3422
3603
|
title: unvalidatedRedirect.title,
|
|
@@ -3635,9 +3816,9 @@ var hardcodedJWTSecret = {
|
|
|
3635
3816
|
check(content, filePath) {
|
|
3636
3817
|
if (filePath.endsWith(".example") || filePath.endsWith(".template") || filePath.includes("test")) return [];
|
|
3637
3818
|
const patterns = [
|
|
3638
|
-
/jwt\.sign\s*\([^,]
|
|
3639
|
-
/jwt\.verify\s*\([^,]
|
|
3640
|
-
/jsonwebtoken
|
|
3819
|
+
/jwt\.sign\s*\([^,]{1,300},\s*["'`][^"'`]{3,}["'`]/g,
|
|
3820
|
+
/jwt\.verify\s*\([^,]{1,300},\s*["'`][^"'`]{3,}["'`]/g,
|
|
3821
|
+
/jsonwebtoken.{0,300}secret\s*[:=]\s*["'`][^"'`]{3,}["'`]/gi,
|
|
3641
3822
|
/JWT_SECRET\s*[:=]\s*["'`][^"'`]{3,}["'`]/g
|
|
3642
3823
|
];
|
|
3643
3824
|
const matches = [];
|
|
@@ -3741,7 +3922,7 @@ var exposedDebugMode = {
|
|
|
3741
3922
|
// Debug endpoints that leak environment / process internals in the
|
|
3742
3923
|
// response body. Very high-signal — a production service shouldn't
|
|
3743
3924
|
// serialize process.env or process.version to callers.
|
|
3744
|
-
/res\.(?:json|send)\s*\([^)]
|
|
3925
|
+
/res\.(?:json|send)\s*\([^)]{0,500}process\.(?:env|version|pid|arch|platform)/gi,
|
|
3745
3926
|
/(?:env|environment)\s*:\s*process\.env\b/gi
|
|
3746
3927
|
];
|
|
3747
3928
|
for (const p of patterns) {
|
|
@@ -3841,8 +4022,8 @@ var exposedStackTraces = {
|
|
|
3841
4022
|
const matches = [];
|
|
3842
4023
|
const patterns = [
|
|
3843
4024
|
// Sending stack trace in response
|
|
3844
|
-
/(?:res\.(?:json|send|status)|c\.json|return
|
|
3845
|
-
/(?:res\.(?:json|send|status)|c\.json)\s*\([^)]
|
|
4025
|
+
/(?:res\.(?:json|send|status)|c\.json|return.{0,300}json)\s*\([^)]{0,500}(?:err\.stack|error\.stack|e\.stack)/gi,
|
|
4026
|
+
/(?:res\.(?:json|send|status)|c\.json)\s*\([^)]{0,500}(?:err\.message|error\.message|e\.message)/gi,
|
|
3846
4027
|
// Express-style error with stack
|
|
3847
4028
|
/(?:message|error)\s*:\s*(?:err|error|e)\.(?:stack|message)/gi
|
|
3848
4029
|
];
|
|
@@ -3893,11 +4074,11 @@ var weakHashing = {
|
|
|
3893
4074
|
if (/bcrypt|scrypt|argon2/i.test(content)) return [];
|
|
3894
4075
|
const matches = [];
|
|
3895
4076
|
const inlinePatterns = [
|
|
3896
|
-
/(?:md5|sha1|sha256|sha512)\s*\([^)]
|
|
3897
|
-
/createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\)
|
|
3898
|
-
/(?:password|passwd|pwd)
|
|
3899
|
-
/hashlib\.(?:md5|sha1|sha256)\s*\([^)]
|
|
3900
|
-
/Digest::(?:MD5|SHA1|SHA256)
|
|
4077
|
+
/(?:md5|sha1|sha256|sha512)\s*\([^)]{0,500}(?:password|passwd|pwd)/gi,
|
|
4078
|
+
/createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\).{0,500}(?:password|passwd|pwd)/gi,
|
|
4079
|
+
/(?:password|passwd|pwd).{0,500}createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\)/gi,
|
|
4080
|
+
/hashlib\.(?:md5|sha1|sha256)\s*\([^)]{0,500}(?:password|passwd|pwd)/gi,
|
|
4081
|
+
/Digest::(?:MD5|SHA1|SHA256).{0,500}(?:password|passwd|pwd)/gi
|
|
3901
4082
|
];
|
|
3902
4083
|
for (const p of inlinePatterns) {
|
|
3903
4084
|
matches.push(...findMatches(
|
|
@@ -3943,7 +4124,7 @@ var disabledTLSVerification = {
|
|
|
3943
4124
|
const patterns = [
|
|
3944
4125
|
/NODE_TLS_REJECT_UNAUTHORIZED\s*[:=]\s*["'`]?0["'`]?/g,
|
|
3945
4126
|
/rejectUnauthorized\s*:\s*false/g,
|
|
3946
|
-
/verify\s*[:=]\s*false
|
|
4127
|
+
/verify\s*[:=]\s*false.{0,300}(?:ssl|tls|cert|https)/gi,
|
|
3947
4128
|
/PYTHONHTTPSVERIFY\s*[:=]\s*["'`]?0["'`]?/g,
|
|
3948
4129
|
/ssl_verify\s*[:=]\s*false/gi,
|
|
3949
4130
|
/InsecureSkipVerify\s*:\s*true/g
|
|
@@ -5995,6 +6176,7 @@ function getSnippet5(content, line) {
|
|
|
5995
6176
|
}
|
|
5996
6177
|
function scanMultiFile(files) {
|
|
5997
6178
|
files = files.filter((f) => !isSbomPath(f.path));
|
|
6179
|
+
const guarded = secretGuardedRoutes(files);
|
|
5998
6180
|
const findings = [];
|
|
5999
6181
|
const fileMap = /* @__PURE__ */ new Map();
|
|
6000
6182
|
for (const f of files) {
|
|
@@ -6010,6 +6192,7 @@ function scanMultiFile(files) {
|
|
|
6010
6192
|
if (!/(?:\/api\/|routes?\/|controllers?\/)/i.test(f.path)) continue;
|
|
6011
6193
|
if (/middleware/i.test(f.path)) continue;
|
|
6012
6194
|
if (/(?:health|status|ping|ready|live)\.(?:ts|js)/i.test(f.path)) continue;
|
|
6195
|
+
if (guarded.has(f.path)) continue;
|
|
6013
6196
|
const hasLocalAuth = /(?:requireAuth|isAuthenticated|authenticate|verify|getAuth|getSession|getServerSession|withAuth|jwt\.verify|clerk)/i.test(f.content);
|
|
6014
6197
|
const hasAuthImport = f.content.split("\n").some((line) => {
|
|
6015
6198
|
const at = line.search(/import/i);
|