xploitscan-shared-rules 2.4.10 → 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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SCANNER_VERSION = "2.4.10";
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
 
@@ -514,7 +644,7 @@ function isTestPath(filePath) {
514
644
  if (/(?:^|\/)testing(?:\/|$)/i.test(normalized)) return true;
515
645
  return false;
516
646
  }
517
- var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
647
+ var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.(?:json|xml)|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
518
648
  function isSbomPath(filePath) {
519
649
  return SBOM_FILE_RE.test(normalize(filePath));
520
650
  }
@@ -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 lineStartIndex = (line) => lines.slice(0, line - 1).reduce((acc, l) => acc + l.length + 1, 0);
1746
- return matches.filter((m) => !isInlineSilenced(content, lineStartIndex(m.line), ruleId));
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
- if (isCommentLine(content, m.index)) continue;
1771
- if (isInsideFixMessage(content, m.index)) continue;
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: getSnippet(content, lineNum),
1936
+ snippet,
1783
1937
  fix: fixTemplate?.(m)
1784
1938
  });
1785
1939
  if (matches.length >= MAX_MATCHES) break;
@@ -1852,13 +2006,40 @@ function dbUrlLacksRealCredential(url) {
1852
2006
  const userinfo = rest.slice(0, at);
1853
2007
  const colon = userinfo.indexOf(":");
1854
2008
  const user = colon < 0 ? userinfo : userinfo.slice(0, colon);
1855
- const pass = colon < 0 ? "" : decodeURIComponentSafe(userinfo.slice(colon + 1));
2009
+ const rawPass = colon < 0 ? "" : userinfo.slice(colon + 1);
2010
+ const pass = colon < 0 ? "" : decodeURIComponentSafe(rawPass);
1856
2011
  if (!pass) return true;
2012
+ const portShaped = /^(\d{1,5})(?:\/[\w.-]{0,64})?[?#"'`][^@]*$/.exec(rawPass);
2013
+ if (portShaped && Number(portShaped[1]) <= 65535) return true;
1857
2014
  if (isFormatPlaceholder(pass)) return true;
1858
2015
  if (isPlaceholderSecret(pass)) return true;
1859
2016
  if (/^(?:u|user|username)$/i.test(user) && /^(?:pass|password|passwd|pwd)$/i.test(pass)) return true;
1860
2017
  return false;
1861
2018
  }
2019
+ var LOOPBACK_DEV_USER_RE = /^(?:postgres|root|admin|user|test|dev|mysql|mongo|mongodb|redis|sa|guest|app|example)$/i;
2020
+ function isLoopbackDevDefault(url) {
2021
+ const rest = url.replace(/^[a-z0-9+]+:\/\//i, "");
2022
+ const at = rest.lastIndexOf("@");
2023
+ if (at < 0) return false;
2024
+ const userinfo = rest.slice(0, at);
2025
+ const colon = userinfo.indexOf(":");
2026
+ if (colon < 0) return false;
2027
+ const user = userinfo.slice(0, colon);
2028
+ const pass = decodeURIComponentSafe(userinfo.slice(colon + 1));
2029
+ if (user !== pass || !LOOPBACK_DEV_USER_RE.test(user)) return false;
2030
+ let host = rest.slice(at + 1);
2031
+ const cut = host.search(/[/?#]/);
2032
+ if (cut >= 0) host = host.slice(0, cut);
2033
+ if (host.startsWith("[")) {
2034
+ const end = host.indexOf("]");
2035
+ host = end >= 0 ? host.slice(1, end) : host;
2036
+ } else {
2037
+ const port = host.lastIndexOf(":");
2038
+ if (port >= 0) host = host.slice(0, port);
2039
+ }
2040
+ const h = host.toLowerCase();
2041
+ return h === "localhost" || h === "::1" || h === "0.0.0.0" || h === "host.docker.internal" || /^127(?:\.\d{1,3}){0,3}$/.test(h);
2042
+ }
1862
2043
  function decodeURIComponentSafe(value) {
1863
2044
  try {
1864
2045
  return decodeURIComponent(value);
@@ -1867,10 +2048,12 @@ function decodeURIComponentSafe(value) {
1867
2048
  }
1868
2049
  }
1869
2050
  var FORMAT_PLACEHOLDER_MAX = 256;
2051
+ var FORMAT_FIELD_RE = /^\{(?:[a-z_][a-z0-9_]{0,63}|[A-Z_][A-Z0-9_]{0,63})(?:\.(?:[a-z_][a-z0-9_]{0,63}|[A-Z_][A-Z0-9_]{0,63})){0,4}(?:\[[\w'"]{1,64}\])?(?:![rsa])?(?::[<>=^]?\d{0,3}[sd]?)?\}$/;
1870
2052
  function isFormatPlaceholder(value) {
1871
2053
  const v = value.trim();
1872
2054
  if (!v) return true;
1873
2055
  if (v.length > FORMAT_PLACEHOLDER_MAX) return false;
2056
+ if (FORMAT_FIELD_RE.test(v)) return true;
1874
2057
  if (/^(?:%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>|\*+)$/i.test(v)) return true;
1875
2058
  if (/%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>/.test(v)) return true;
1876
2059
  return false;
@@ -2055,7 +2238,12 @@ var hardcodedSecrets = {
2055
2238
  if (isKeySuffix && isSlotIdentifier) continue;
2056
2239
  }
2057
2240
  }
2058
- if (pi === 10 && dbUrlLacksRealCredential(matchedText[ri] ?? "")) continue;
2241
+ if (pi === 10) {
2242
+ const url = matchedText[ri] ?? "";
2243
+ if (dbUrlLacksRealCredential(url)) continue;
2244
+ matches.push(isLoopbackDevDefault(url) ? { ...rm, severity: "low" } : textHasLiveCredential(url) ? { ...rm, live: true } : rm);
2245
+ continue;
2246
+ }
2059
2247
  const matched = matchedText[ri] ?? "";
2060
2248
  matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
2061
2249
  }
@@ -2476,6 +2664,23 @@ function unauthenticatedTanStackHandlers(masked, filePath) {
2476
2664
  }
2477
2665
  return hits;
2478
2666
  }
2667
+ var NAMED_ROUTE_EXPORT_RE = /export\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/i;
2668
+ var SERVER_ACTION_WRITE_RE = [
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*\(/,
2670
+ /\b(?:stripe|paypal|braintree|lemonsqueezy|paddle)\s*\.\s*\w{1,40}\s*\.\s*(?:create|update|del|cancel|capture|refund)\w{0,10}\s*\(/,
2671
+ /\bfetch\s*\([^;]{0,400}?\bmethod\s*(?::\s*(?=["'`](?:POST|PUT|PATCH|DELETE)\b|`\$\{|[A-Za-z_$(\[])|(?=[,}]))/i,
2672
+ /\b(?:fs(?:\.promises)?\s*\.\s*)?(?:writeFile|appendFile|unlink|rm|rmdir|rename|copyFile)(?:Sync)?\s*\(/,
2673
+ /\.\s*(?:del|deleteOne|deleteMany|insertOne|insertMany|updateOne|updateMany|replaceOne|bulkWrite|upsert|increment|decrement|destroy|truncate)\s*\(/,
2674
+ /cookies\(\)\)?\s*\.\s*set\(\s*["'`][\w-]*(?:session|token|auth|jwt|sid|role|user|admin)/i,
2675
+ ...TANSTACK_MUTATION_RE,
2676
+ /\b(?:prisma|db|tx)\s*\.\s*\w{1,64}\s*\.\s*(?:create|createMany|insert\w{0,10})\s*\(/,
2677
+ /\b(?:db|tx)\s*\.\s*insert\s*\(\s*\w/,
2678
+ /\.from\(\s*["'`][\w.-]{1,64}["'`]\s*\)\s*\.\s*insert\s*\(/,
2679
+ /\bINSERT\s+INTO\b/i,
2680
+ /\.collection\(\s*["'`][\w.-]{1,64}["'`]\s*\)\s*\.\s*(?:insert\w{0,8}|update\w{0,8}|delete\w{0,8}|replaceOne|findOneAndUpdate|findOneAndDelete)\s*\(/,
2681
+ /\b(?!(?:Object|Array|Promise|Reflect|Buffer|Math|JSON|Date|Intl|Symbol|Map|Set|WeakMap|Response|NextResponse|Request|URL|Error)\b)[A-Z]\w{0,40}\.(?:create|insertMany|updateOne|updateMany|deleteOne|deleteMany|findByIdAndUpdate|findByIdAndDelete|findOneAndUpdate|findOneAndDelete|destroy)\s*\(/,
2682
+ /\b(?:delete|remove|update|set|grant|revoke|ban|promote|demote|transfer|refund|cancel|reset|change)\w{0,20}(?:User|Account|Role|Admin|Order|Payment|Subscription|Member|Permission|Password|Email|Org|Organization|Team|Project|Invoice|Profile|Balance|Credits?|Plan|Post|Comment)s?\s*\(/
2683
+ ];
2479
2684
  var missingAuthMiddleware = {
2480
2685
  id: "VC003",
2481
2686
  title: "API Route Missing Authentication",
@@ -2501,8 +2706,9 @@ var missingAuthMiddleware = {
2501
2706
  /module\.exports\s*=\s*(?:async\s+)?(?:function\b|\()/g
2502
2707
  );
2503
2708
  }
2709
+ const useServerPatterns = [];
2504
2710
  if (USE_SERVER_DIRECTIVE_RE.test(content)) {
2505
- routePatterns.push(
2711
+ useServerPatterns.push(
2506
2712
  /export\s+(?:async\s+)?function\s+\w+\s*\(/g,
2507
2713
  /export\s+const\s+\w+\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?\(/g
2508
2714
  );
@@ -2588,24 +2794,34 @@ var missingAuthMiddleware = {
2588
2794
  );
2589
2795
  const maskedForScope = maskOutboundAuthNoise(maskComments(content));
2590
2796
  const codeForAuth = maskOutboundAuthNoise(codeOnly);
2591
- const handlerHasAuth = (index) => {
2797
+ const scopeCache = /* @__PURE__ */ new Map();
2798
+ const scopeAt = (index) => {
2799
+ const cached = scopeCache.get(index);
2800
+ if (cached !== void 0) return cached;
2592
2801
  const bodyStart = maskedForScope.indexOf("{", index);
2593
2802
  const probe = bodyStart === -1 ? index : bodyStart + 1;
2594
2803
  const scope = enclosingHandler(maskedForScope, probe);
2595
- if (scope === null) return handlerAuthPatterns.some((p) => p.test(codeForAuth));
2804
+ scopeCache.set(index, scope);
2805
+ return scope;
2806
+ };
2807
+ let fileHasAuth;
2808
+ const handlerHasAuth = (index) => {
2809
+ const scope = scopeAt(index);
2810
+ if (scope === null) return fileHasAuth ??= handlerAuthPatterns.some((p) => p.test(codeForAuth));
2596
2811
  return handlerAuthPatterns.some((p) => p.test(scope));
2597
2812
  };
2598
2813
  const matches = [];
2814
+ const routeLines = /* @__PURE__ */ new Set();
2815
+ const authFix = "Add authentication middleware to protect this route. Check the user's session/token before processing the request. If the endpoint is public by design (an OG image, an embeddable badge, a health check), add an inline `// VC003-OK: <reason>` comment above the handler to silence.";
2599
2816
  for (const pattern of serverSide ? routePatterns : []) {
2600
- matches.push(
2601
- ...findMatches(
2602
- content,
2603
- pattern,
2604
- missingAuthMiddleware,
2605
- filePath,
2606
- () => "Add authentication middleware to protect this route. Check the user's session/token before processing the request. If the endpoint is public by design (an OG image, an embeddable badge, a health check), add an inline `// VC003-OK: <reason>` comment above the handler to silence."
2607
- )
2608
- );
2817
+ const found = findMatches(content, pattern, missingAuthMiddleware, filePath, () => authFix);
2818
+ for (const foundMatch of found) routeLines.add(foundMatch.line);
2819
+ matches.push(...found);
2820
+ }
2821
+ if (serverSide) {
2822
+ for (const pattern of useServerPatterns) {
2823
+ matches.push(...findMatches(content, pattern, missingAuthMiddleware, filePath, () => authFix));
2824
+ }
2609
2825
  }
2610
2826
  if (matches.length === 0 && serverSide && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
2611
2827
  const fnName = supabaseFunctionName(filePath);
@@ -2632,9 +2848,21 @@ var missingAuthMiddleware = {
2632
2848
  }
2633
2849
  const indexOfLine = (line) => lineStarts[Math.max(0, Math.min(line - 1, lineStarts.length - 1))];
2634
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;
2635
2856
  const unauthenticated = matches.filter((m) => {
2636
2857
  const index = indexOfLine(m.line);
2637
- return !isPublicRootGet(index) && !handlerHasAuth(index);
2858
+ if (isPublicRootGet(index) || handlerHasAuth(index)) return false;
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]))) {
2862
+ const scope = scopeAt(index);
2863
+ if (scope !== null && !SERVER_ACTION_WRITE_RE.some((re) => re.test(scope))) return false;
2864
+ }
2865
+ return true;
2638
2866
  });
2639
2867
  if (serverSide || tanstackCandidate) {
2640
2868
  for (const idx of unauthenticatedTanStackHandlers(maskedForScope, filePath)) {
@@ -3034,6 +3262,9 @@ var noRateLimiting = {
3034
3262
  check(content, filePath) {
3035
3263
  const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
3036
3264
  if (!isEntryFile) return [];
3265
+ if (/(?:^|\/)(?:lib|libs|utils?|helpers?|components|hooks|shared|types)\/(?:[^/]+\/)*index\.[jt]sx?$/.test(filePath) && !/\.listen\s*\(|\bcreateServer\s*\(|\bexpress\s*\(\s*\)|\bFastify\s*\(|\bnew\s+(?:Koa|Hono)\b/.test(content)) {
3266
+ return [];
3267
+ }
3037
3268
  const isServer = /(?:from\s+|require\s*\(\s*)["'`](?:express|hono|fastify|koa|koa-router|@koa\/[\w-]+|@hono\/[\w-]+|next(?:\/server)?|next-auth(?:\/[\w-]+)?|@clerk\/nextjs(?:\/server)?)["'`]/.test(content) || // Case-sensitive framework types — `adNext` and `nextLap` can't match.
3038
3269
  /\b(?:NextApiRequest|NextApiResponse|NextRequest|NextResponse)\b/.test(content) || /\b(?:express|fastify|createServer)\s*\(/.test(content) || /\bnew\s+(?:Hono|Koa)\s*\(/.test(content) || /\b(?:Deno|Bun)\.serve\s*\(/.test(content) || /\.listen\s*\(/.test(content);
3039
3270
  if (!isServer) return [];
@@ -3309,6 +3540,9 @@ var evalUsage = {
3309
3540
  const hasEvalInString = /["'`]eval(?:-source-map|["'`])/i.test(content);
3310
3541
  if (hasEvalInString && !/\beval\s*\([^)]{0,500}(?:req\.|body\.|input|params|user|data)/i.test(content)) return [];
3311
3542
  const matches = [];
3543
+ let evalLineStarts;
3544
+ let evalLastLine = -1;
3545
+ let evalLastKeep = false;
3312
3546
  for (const p of patterns) {
3313
3547
  const rawMatches = findMatches(
3314
3548
  content,
@@ -3318,11 +3552,18 @@ var evalUsage = {
3318
3552
  () => "Replace eval() with JSON.parse() for data, or a proper parser for expressions. Never pass user input to eval()."
3319
3553
  );
3320
3554
  for (const rm of rawMatches) {
3321
- const lineStart = content.lastIndexOf("\n", content.split("\n").slice(0, rm.line - 1).join("\n").length) + 1;
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];
3322
3562
  const lineEnd = content.indexOf("\n", lineStart + 1);
3323
3563
  const lineText = content.substring(lineStart, lineEnd === -1 ? content.length : lineEnd);
3324
3564
  if (/devtool|source-map/i.test(lineText)) continue;
3325
3565
  if (/(?:description|title|message)\s*[:=]/i.test(lineText)) continue;
3566
+ evalLastKeep = true;
3326
3567
  matches.push(rm);
3327
3568
  }
3328
3569
  }
@@ -3341,14 +3582,22 @@ var unvalidatedRedirect = {
3341
3582
  const matches = [];
3342
3583
  const navPattern = /(?:window\.location(?:\.href)?\s*=\s*|window\.location\.(?:assign|replace)\s*\(\s*)([^;\n)]+)/g;
3343
3584
  let m;
3585
+ let commentLineStart = -1;
3586
+ let commentLine = false;
3587
+ let silenceLines;
3344
3588
  while ((m = navPattern.exec(content)) !== null) {
3345
- if (isCommentLine(content, m.index)) continue;
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;
3346
3595
  const value = m[1].trim();
3347
3596
  const hasInterpolation = /\$\{/.test(value);
3348
3597
  const isPureLiteral = /^["'`][^"'`]*["'`]$/.test(value);
3349
3598
  if (!hasInterpolation && isPureLiteral) continue;
3350
- if (isInlineSilenced(content, m.index, "VC016")) continue;
3351
3599
  const line = lineNumberAt(content, m.index);
3600
+ if (isLineSilenced(silenceLines ??= content.split("\n"), line - 1, "VC016")) continue;
3352
3601
  matches.push({
3353
3602
  rule: "VC016",
3354
3603
  title: unvalidatedRedirect.title,
@@ -3373,6 +3622,28 @@ var unvalidatedRedirect = {
3373
3622
  var CLIENT_PREFERENCE_COOKIE_NAME_RE = /(?:consent|preferences?|prefs?)/i;
3374
3623
  var CLIENT_PREFERENCE_COOKIE_VALUE_RE = /(?:choice|consent|preferences?|prefs?|accepted|essential(?:-only)?|declined|rejected|granted|denied|opt(?:ed)?[-_ ]?(?:in|out))/i;
3375
3624
  var SENSITIVE_CLIENT_COOKIE_RE = /(?:auth|session|token|jwt|bearer|credential|password|passwd|secret|csrf|xsrf|refresh)/i;
3625
+ var UI_FLAG_COOKIE_NAME_RE = /^(?:theme|color-?scheme|sidebar|welcome-toast|toast|locale|lang|language|dir|collapsed|expanded|layout|banner|dismissed|density|contrast|font|font-?size|motion|reduced-?motion|color-mode|dark-mode|ui)$/i;
3626
+ var UI_FLAG_COOKIE_ASSIGN_RE = /\b(?:document\s*\.\s*)?cookie\s*=\s*(["'`])([^"'`]*)\1/gi;
3627
+ var UI_FLAG_SENSITIVE_NAME_RE = /(?:sess|sid(?!ebar)|login|user|uid|key|account|admin|role|remember|__host-|__secure-)/i;
3628
+ var UI_FLAG_COOKIE_BODY_RE = /^[A-Za-z0-9_.-]+=[A-Za-z0-9_.-]+(?:\s*;\s*(?:max-age=-?\d{1,10}|path=\/[\w./-]{0,100}|expires=[\w ,:+-]{1,40}|samesite=(?:lax|strict|none)|secure|domain=\.?[\w.-]{1,100})){0,6}\s*;?\s*$/i;
3629
+ function isConstantUiFlagCookieWrite(line, nextLine) {
3630
+ const next = nextLine.trimStart();
3631
+ if (next.startsWith("+") || next.startsWith(".") || next.startsWith("`")) return false;
3632
+ if (/\bset-cookie\b|\bsetCookie\b|res\.cookie\s*\(/i.test(line)) return false;
3633
+ const re = new RegExp(UI_FLAG_COOKIE_ASSIGN_RE.source, "gi");
3634
+ let saw = false;
3635
+ let assignment;
3636
+ while ((assignment = re.exec(line)) !== null) {
3637
+ saw = true;
3638
+ const body = assignment[2];
3639
+ if (!UI_FLAG_COOKIE_BODY_RE.test(body)) return false;
3640
+ if (SENSITIVE_CLIENT_COOKIE_RE.test(body)) return false;
3641
+ const name = body.split("=")[0];
3642
+ if (!UI_FLAG_COOKIE_NAME_RE.test(name)) return false;
3643
+ if (UI_FLAG_SENSITIVE_NAME_RE.test(name)) return false;
3644
+ }
3645
+ return saw;
3646
+ }
3376
3647
  function isClearlyNonSensitivePreferenceCookieWrite(content, line) {
3377
3648
  const assignment = /\bdocument\s*\.\s*cookie\s*=\s*(.+)$/i.exec(line);
3378
3649
  if (!assignment) return false;
@@ -3404,7 +3675,7 @@ var insecureCookies = {
3404
3675
  check(content, filePath) {
3405
3676
  if (isTestFile(filePath)) return [];
3406
3677
  if (!/cookie/i.test(content)) return [];
3407
- const setCookiePattern = /(?:set-cookie|setCookie|\bcookie\s*=|res\.cookie\s*\()/i;
3678
+ const setCookiePattern = /(?:\bset-cookie|\bsetCookie|\bcookie\s*=|res\.cookie\s*\()/i;
3408
3679
  if (!setCookiePattern.test(content)) return [];
3409
3680
  const hasHttpOnly = /httpOnly\s*:\s*true|httponly/i.test(content);
3410
3681
  const hasSecure = /secure\s*:\s*(?!false\b)\S/i.test(content) || /;\s*secure/i.test(content);
@@ -3423,12 +3694,18 @@ var insecureCookies = {
3423
3694
  () => `Add missing cookie flags: ${missing.join(", ")}. Example: { httpOnly: true, secure: true, sameSite: 'lax' }`
3424
3695
  );
3425
3696
  const lines = content.split("\n");
3697
+ const uiFlagMemo = /* @__PURE__ */ new Map();
3426
3698
  for (const match of rawMatches) {
3427
3699
  const line = lines[match.line - 1] ?? "";
3428
3700
  if (!hasHttpOnly && isClearlyNonSensitivePreferenceCookieWrite(content, line)) {
3429
3701
  continue;
3430
3702
  }
3431
- matches.push(match);
3703
+ let info = uiFlagMemo.get(match.line);
3704
+ if (info === void 0) {
3705
+ info = isConstantUiFlagCookieWrite(line, lines[match.line] ?? "");
3706
+ uiFlagMemo.set(match.line, info);
3707
+ }
3708
+ matches.push(info ? { ...match, severity: "info" } : match);
3432
3709
  }
3433
3710
  }
3434
3711
  return matches;
@@ -3539,9 +3816,9 @@ var hardcodedJWTSecret = {
3539
3816
  check(content, filePath) {
3540
3817
  if (filePath.endsWith(".example") || filePath.endsWith(".template") || filePath.includes("test")) return [];
3541
3818
  const patterns = [
3542
- /jwt\.sign\s*\([^,]+,\s*["'`][^"'`]{3,}["'`]/g,
3543
- /jwt\.verify\s*\([^,]+,\s*["'`][^"'`]{3,}["'`]/g,
3544
- /jsonwebtoken.*secret\s*[:=]\s*["'`][^"'`]{3,}["'`]/gi,
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,
3545
3822
  /JWT_SECRET\s*[:=]\s*["'`][^"'`]{3,}["'`]/g
3546
3823
  ];
3547
3824
  const matches = [];
@@ -3574,19 +3851,49 @@ var missingHTTPS = {
3574
3851
  const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
3575
3852
  if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
3576
3853
  const httpPattern = /["'`]http:\/\/(?!localhost|127\.0\.0\.1|0\.0\.0\.0|192\.168\.|10\.|172\.(?:1[6-9]|2\d|3[01])\.|www\.w3\.org|www\.apple\.com\/DTDs|schemas?\.|xml\.org|purl\.org|ns\.adobe|xmlpull\.org|java\.sun\.com)[^"'`\s]+["'`]/g;
3577
- const rawMatches = findMatches(
3578
- content,
3579
- httpPattern,
3580
- missingHTTPS,
3581
- filePath,
3582
- () => "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains"
3583
- );
3854
+ const httpIndexes = [];
3855
+ const rawMatches = findMatches(content, httpPattern, missingHTTPS, filePath, (m) => {
3856
+ httpIndexes.push(m.index);
3857
+ return "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains";
3858
+ });
3584
3859
  const lines = rawMatches.length > 0 ? content.split("\n") : [];
3585
- for (const rm of rawMatches) {
3860
+ const lineStarts = [];
3861
+ if (rawMatches.length > 0) {
3862
+ let acc = 0;
3863
+ for (const line of lines) {
3864
+ lineStarts.push(acc);
3865
+ acc += line.length + 1;
3866
+ }
3867
+ }
3868
+ const schemaKeyOnLine = /* @__PURE__ */ new Map();
3869
+ const tsaOnLine = /* @__PURE__ */ new Map();
3870
+ const firstSchemaKey = (line, lineNo) => {
3871
+ const cached = schemaKeyOnLine.get(lineNo);
3872
+ if (cached !== void 0) return cached;
3873
+ const key = /(?<![\w$])["']?\$(?:schema|id|ref)["']?\s*:/.exec(line);
3874
+ const at = key ? key.index : -1;
3875
+ schemaKeyOnLine.set(lineNo, at);
3876
+ return at;
3877
+ };
3878
+ for (let i = 0; i < rawMatches.length; i++) {
3879
+ const rm = rawMatches[i];
3586
3880
  const matchText = lines[rm.line - 1] ?? "";
3587
3881
  if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
3588
- if (/["']\$schema["']\s*:|["']\$id["']\s*:/.test(matchText)) continue;
3589
- if (/--\s*tsaurl\b|\btsaurl\b|timestamp\.(?:digicert|sectigo|comodoca|globalsign|entrust|geotrust|verisign|apple)\.|timestamp\.acs\.microsoft\.com|freetsa\.org/i.test(matchText)) continue;
3882
+ if (firstSchemaKey(matchText, rm.line) >= 0) {
3883
+ const col = httpIndexes[i] - (lineStarts[rm.line - 1] ?? 0);
3884
+ const lookback = matchText.slice(Math.max(0, col - 48), col);
3885
+ if (/(?<![\w$])["']?\$(?:schema|id)["']?\s*:\s*["']?\s*$/.test(lookback)) continue;
3886
+ if (/(?<![\w$])["']?\$ref["']?\s*:\s*["']?\s*$/.test(lookback)) {
3887
+ const host = (/https?:\/\/([^/"'\s:?#]+)/i.exec(matchText.slice(col, col + 300))?.[1] ?? "").toLowerCase();
3888
+ if (host === "json-schema.org" || host.endsWith(".json-schema.org")) continue;
3889
+ }
3890
+ }
3891
+ let tsa = tsaOnLine.get(rm.line);
3892
+ if (tsa === void 0) {
3893
+ tsa = /--\s*tsaurl\b|\btsaurl\b|timestamp\.(?:digicert|sectigo|comodoca|globalsign|entrust|geotrust|verisign|apple)\.|timestamp\.acs\.microsoft\.com|freetsa\.org/i.test(matchText);
3894
+ tsaOnLine.set(rm.line, tsa);
3895
+ }
3896
+ if (tsa) continue;
3590
3897
  matches.push(rm);
3591
3898
  }
3592
3899
  return matches;
@@ -3615,7 +3922,7 @@ var exposedDebugMode = {
3615
3922
  // Debug endpoints that leak environment / process internals in the
3616
3923
  // response body. Very high-signal — a production service shouldn't
3617
3924
  // serialize process.env or process.version to callers.
3618
- /res\.(?:json|send)\s*\([^)]*process\.(?:env|version|pid|arch|platform)/gi,
3925
+ /res\.(?:json|send)\s*\([^)]{0,500}process\.(?:env|version|pid|arch|platform)/gi,
3619
3926
  /(?:env|environment)\s*:\s*process\.env\b/gi
3620
3927
  ];
3621
3928
  for (const p of patterns) {
@@ -3715,8 +4022,8 @@ var exposedStackTraces = {
3715
4022
  const matches = [];
3716
4023
  const patterns = [
3717
4024
  // Sending stack trace in response
3718
- /(?:res\.(?:json|send|status)|c\.json|return.*json)\s*\([^)]*(?:err\.stack|error\.stack|e\.stack)/gi,
3719
- /(?:res\.(?:json|send|status)|c\.json)\s*\([^)]*(?:err\.message|error\.message|e\.message)/gi,
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,
3720
4027
  // Express-style error with stack
3721
4028
  /(?:message|error)\s*:\s*(?:err|error|e)\.(?:stack|message)/gi
3722
4029
  ];
@@ -3767,11 +4074,11 @@ var weakHashing = {
3767
4074
  if (/bcrypt|scrypt|argon2/i.test(content)) return [];
3768
4075
  const matches = [];
3769
4076
  const inlinePatterns = [
3770
- /(?:md5|sha1|sha256|sha512)\s*\([^)]*(?:password|passwd|pwd)/gi,
3771
- /createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\).*(?:password|passwd|pwd)/gi,
3772
- /(?:password|passwd|pwd).*createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\)/gi,
3773
- /hashlib\.(?:md5|sha1|sha256)\s*\([^)]*(?:password|passwd|pwd)/gi,
3774
- /Digest::(?:MD5|SHA1|SHA256).*(?:password|passwd|pwd)/gi
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
3775
4082
  ];
3776
4083
  for (const p of inlinePatterns) {
3777
4084
  matches.push(...findMatches(
@@ -3817,7 +4124,7 @@ var disabledTLSVerification = {
3817
4124
  const patterns = [
3818
4125
  /NODE_TLS_REJECT_UNAUTHORIZED\s*[:=]\s*["'`]?0["'`]?/g,
3819
4126
  /rejectUnauthorized\s*:\s*false/g,
3820
- /verify\s*[:=]\s*false.*(?:ssl|tls|cert|https)/gi,
4127
+ /verify\s*[:=]\s*false.{0,300}(?:ssl|tls|cert|https)/gi,
3821
4128
  /PYTHONHTTPSVERIFY\s*[:=]\s*["'`]?0["'`]?/g,
3822
4129
  /ssl_verify\s*[:=]\s*false/gi,
3823
4130
  /InsecureSkipVerify\s*:\s*true/g
@@ -4516,12 +4823,13 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
4516
4823
  }
4517
4824
  if (maxLineLen > 5e4) return findings;
4518
4825
  if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
4519
- if (isSbomPath(filePath)) return findings;
4826
+ const sbomFile = isSbomPath(filePath);
4520
4827
  const vendoredFile = isVendoredPath(filePath);
4521
4828
  const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
4522
4829
  const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
4523
4830
  for (const rule of ruleset) {
4524
4831
  if (disabledRules.includes(rule.id)) continue;
4832
+ if (sbomFile && rule.category !== "Secrets") continue;
4525
4833
  const matches = rule.check(content, filePath, project);
4526
4834
  const compliance = complianceMap[rule.id];
4527
4835
  const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
@@ -4934,6 +5242,30 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
4934
5242
  }
4935
5243
 
4936
5244
  // src/entropy-scanner.ts
5245
+ function orderedAlphabetRatio(value) {
5246
+ if (value.length === 0) return 0;
5247
+ let ordered = 0;
5248
+ let run = 1;
5249
+ const cls = (c) => {
5250
+ if (c >= 48 && c <= 57) return 1;
5251
+ if (c >= 65 && c <= 90) return 2;
5252
+ if (c >= 97 && c <= 122) return 3;
5253
+ return 0;
5254
+ };
5255
+ for (let i = 1; i < value.length; i++) {
5256
+ const a = value.charCodeAt(i - 1);
5257
+ const b = value.charCodeAt(i);
5258
+ const ca = cls(a);
5259
+ if (ca !== 0 && ca === cls(b) && b === a + 1) {
5260
+ run++;
5261
+ if (run === 4) ordered += 4;
5262
+ else if (run > 4) ordered++;
5263
+ } else {
5264
+ run = 1;
5265
+ }
5266
+ }
5267
+ return ordered / value.length;
5268
+ }
4937
5269
  function shannonEntropy(str) {
4938
5270
  const freq = {};
4939
5271
  for (const ch of str) {
@@ -5173,6 +5505,7 @@ function scanEntropy(files) {
5173
5505
  const stringPattern = /(?:[:=]\s*)(["'`])([^"'`\n]{20,256})\1/g;
5174
5506
  let match;
5175
5507
  while ((match = stringPattern.exec(line)) !== null) {
5508
+ if (match[1] === "`" && /(?:^|[\s(]):[a-z][\w-]{0,20}:$/.test(line.slice(Math.max(0, match.index - 23), match.index + 1))) continue;
5176
5509
  let beforeAssign = line.substring(0, match.index);
5177
5510
  if (structured) beforeAssign = beforeAssign.slice(Math.max(beforeAssign.lastIndexOf(","), beforeAssign.lastIndexOf("{")) + 1);
5178
5511
  candidates.push({ value: match[2], beforeAssign });
@@ -5185,6 +5518,8 @@ function scanEntropy(files) {
5185
5518
  if (value.includes("${")) continue;
5186
5519
  if (value.includes("\\(")) continue;
5187
5520
  if (value.includes("#{") || value.includes("{{")) continue;
5521
+ if (/^(?:\$\w{1,64}|\$env\{\w{1,64}\}|%\w{1,64}%|~|\.{1,2})?[\/\\](?:[\w.@ -]{1,64}[\/\\]){1,20}[\w@ -][\w.@ -]{0,63}\.[A-Za-z0-9]{1,8}$/.test(value) && !/[A-Za-z0-9+]{24,}/.test(value)) continue;
5522
+ if (orderedAlphabetRatio(value) >= 0.9) continue;
5188
5523
  const isUuidShape = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
5189
5524
  if (!isUuidShape && SAFE_PATTERNS.some((p) => p.test(value))) continue;
5190
5525
  if (HASH_PREFIX_RE.test(value)) continue;
@@ -5841,6 +6176,7 @@ function getSnippet5(content, line) {
5841
6176
  }
5842
6177
  function scanMultiFile(files) {
5843
6178
  files = files.filter((f) => !isSbomPath(f.path));
6179
+ const guarded = secretGuardedRoutes(files);
5844
6180
  const findings = [];
5845
6181
  const fileMap = /* @__PURE__ */ new Map();
5846
6182
  for (const f of files) {
@@ -5856,6 +6192,7 @@ function scanMultiFile(files) {
5856
6192
  if (!/(?:\/api\/|routes?\/|controllers?\/)/i.test(f.path)) continue;
5857
6193
  if (/middleware/i.test(f.path)) continue;
5858
6194
  if (/(?:health|status|ping|ready|live)\.(?:ts|js)/i.test(f.path)) continue;
6195
+ if (guarded.has(f.path)) continue;
5859
6196
  const hasLocalAuth = /(?:requireAuth|isAuthenticated|authenticate|verify|getAuth|getSession|getServerSession|withAuth|jwt\.verify|clerk)/i.test(f.content);
5860
6197
  const hasAuthImport = f.content.split("\n").some((line) => {
5861
6198
  const at = line.search(/import/i);
@@ -9716,6 +10053,7 @@ export {
9716
10053
  QUALITY_EXAMPLES,
9717
10054
  RULE_IMPACTS,
9718
10055
  SCANNER_VERSION,
10056
+ SERVER_ACTION_WRITE_RE,
9719
10057
  TEST_FILE_PATTERN,
9720
10058
  TOTAL_RULE_COUNT,
9721
10059
  allRules,