xploitscan-shared-rules 1.21.0 → 1.22.0

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 CHANGED
@@ -41,6 +41,7 @@ __export(index_exports, {
41
41
  androidDebuggable: () => androidDebuggable,
42
42
  assessHeaders: () => assessHeaders,
43
43
  blockingMainThread: () => blockingMainThread,
44
+ buildProjectContext: () => buildProjectContext,
44
45
  buildTaintMap: () => buildTaintMap,
45
46
  calculateGrade: () => calculateGrade,
46
47
  callSpreads: () => callSpreads,
@@ -217,6 +218,7 @@ __export(index_exports, {
217
218
  overlyPermissiveIAM: () => overlyPermissiveIAM,
218
219
  parseFile: () => parseFile,
219
220
  parseScanTarget: () => parseScanTarget,
221
+ parseSupabaseConfig: () => parseSupabaseConfig,
220
222
  pathTraversal: () => pathTraversal,
221
223
  pickleDeserialization: () => pickleDeserialization,
222
224
  piiInLogs: () => piiInLogs,
@@ -254,6 +256,7 @@ __export(index_exports, {
254
256
  ssti: () => ssti,
255
257
  stripeWebhookUnprotected: () => stripeWebhookUnprotected,
256
258
  supabaseAnonAdmin: () => supabaseAnonAdmin,
259
+ supabaseFunctionName: () => supabaseFunctionName,
257
260
  supabaseNoRLS: () => supabaseNoRLS,
258
261
  syncFileOps: () => syncFileOps,
259
262
  terraformStateExposed: () => terraformStateExposed,
@@ -571,6 +574,42 @@ function classifyExposure(filePath) {
571
574
  return "unknown";
572
575
  }
573
576
 
577
+ // src/project-context.ts
578
+ var TOML_FN_SECTION_RE = /^\s*\[functions\.(?:"([^"]+)"|([A-Za-z0-9._-]+))\]\s*$/;
579
+ var TOML_VERIFY_JWT_RE = /^\s*verify_jwt\s*=\s*(true|false)\s*(?:#.*)?$/i;
580
+ function parseSupabaseConfig(toml) {
581
+ const out = /* @__PURE__ */ new Map();
582
+ let current = null;
583
+ for (const line of toml.split(/\r?\n/)) {
584
+ const section = line.match(TOML_FN_SECTION_RE);
585
+ if (section) {
586
+ current = section[1] ?? section[2];
587
+ continue;
588
+ }
589
+ if (/^\s*\[/.test(line)) {
590
+ current = null;
591
+ continue;
592
+ }
593
+ if (!current) continue;
594
+ const verify = line.match(TOML_VERIFY_JWT_RE);
595
+ if (verify) out.set(current, verify[1].toLowerCase() === "true");
596
+ }
597
+ return out;
598
+ }
599
+ function supabaseFunctionName(filePath) {
600
+ const m = filePath.match(/(?:^|\/)supabase\/functions\/([^/]+)\//);
601
+ return m ? m[1] : null;
602
+ }
603
+ function buildProjectContext(files) {
604
+ const ctx = {};
605
+ const config = files.find((f) => /(?:^|\/)supabase\/config\.toml$/.test(f.path));
606
+ if (config) {
607
+ const parsed = parseSupabaseConfig(config.content);
608
+ if (parsed.size > 0) ctx.supabaseEdgeVerifyJwt = parsed;
609
+ }
610
+ return ctx;
611
+ }
612
+
574
613
  // src/vendored.ts
575
614
  var NON_APP_PATH_PATTERNS = [
576
615
  // 1. vendored UI component libraries
@@ -1319,6 +1358,7 @@ var SERVER_SIDE_CONTENT_RE = /\b(?:req|request)\.(?:body|query|params|headers|co
1319
1358
  function isServerSideFile(filePath, content) {
1320
1359
  if (isTestFile(filePath)) return false;
1321
1360
  if (SERVER_SIDE_PATH_RE.test(filePath)) return true;
1361
+ if (content && /^\s*["']use server["']/m.test(content)) return true;
1322
1362
  if (content && SERVER_SIDE_CONTENT_RE.test(content)) return true;
1323
1363
  return false;
1324
1364
  }
@@ -1622,7 +1662,7 @@ var missingAuthMiddleware = {
1622
1662
  severity: "high",
1623
1663
  category: "Authentication",
1624
1664
  description: "API routes without authentication checks allow unauthorized access.",
1625
- check(content, filePath) {
1665
+ check(content, filePath, project) {
1626
1666
  if (!isServerSideFile(filePath, content)) return [];
1627
1667
  const routePatterns = [
1628
1668
  // Express/Hono style
@@ -1630,6 +1670,27 @@ var missingAuthMiddleware = {
1630
1670
  // Next.js API routes — named function declaration
1631
1671
  /export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|PATCH|DELETE)\s*\(/gi
1632
1672
  ];
1673
+ const VERCEL_API_FN_RE = /(?:^|\/)api\/[^/]+\.(?:m?[jt]s)$/;
1674
+ const isNextTree = /(?:^|\/)(?:src\/)?(?:app|pages)\//.test(filePath);
1675
+ if (VERCEL_API_FN_RE.test(filePath) && !isNextTree) {
1676
+ routePatterns.push(
1677
+ /export\s+default\s+(?:async\s+)?(?:function\b|\()/g,
1678
+ /module\.exports\s*=\s*(?:async\s+)?(?:function\b|\()/g
1679
+ );
1680
+ }
1681
+ if (/^\s*["']use server["']/m.test(content)) {
1682
+ routePatterns.push(
1683
+ /export\s+(?:async\s+)?function\s+\w+\s*\(/g,
1684
+ /export\s+const\s+\w+\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?\(/g
1685
+ );
1686
+ }
1687
+ const EDGE_FN_DIR_RE = /(?:^|\/)(?:netlify\/(?:edge-)?functions|functions|edge-functions)\/[^/]+\/?[^/]*\.(?:m?[jt]s)$/;
1688
+ if (EDGE_FN_DIR_RE.test(filePath) && !SUPABASE_EDGE_FN_RE.test(filePath)) {
1689
+ routePatterns.push(
1690
+ /(?:exports\s*\.\s*handler|export\s+const\s+handler)\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?(?:function\b|\()/g,
1691
+ /export\s+default\s+(?:async\s+)?(?:function\b|\()/g
1692
+ );
1693
+ }
1633
1694
  if (/(?:^|\/)(?:src\/)?app\/(?:.*\/)?route\.(?:m?[jt]sx?)$/.test(filePath)) {
1634
1695
  routePatterns.push(
1635
1696
  /export\s+const\s+(?:GET|POST|PUT|PATCH|DELETE)\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?(?:function\b|\()/g
@@ -1670,8 +1731,24 @@ var missingAuthMiddleware = {
1670
1731
  /\b(?:protect|guard)\(/i,
1671
1732
  /\.use\([^)]*(?:auth|session|protect|requireAuth)/i
1672
1733
  ];
1673
- const hasAuth = authPatterns.some((p) => p.test(codeOnly));
1674
- if (hasAuth) return [];
1734
+ const APP_LEVEL_AUTH = [
1735
+ /\.use\([^)]*(?:auth|session|protect|requireAuth)/i,
1736
+ /\bpassport\b/i,
1737
+ /\bclerk\b/i,
1738
+ /\bwithAuth\b/i
1739
+ ];
1740
+ if (APP_LEVEL_AUTH.some((p) => p.test(codeOnly))) return [];
1741
+ const handlerAuthPatterns = authPatterns.filter(
1742
+ (p) => !APP_LEVEL_AUTH.some((a) => a.source === p.source)
1743
+ );
1744
+ const maskedForScope = maskComments(content);
1745
+ const handlerHasAuth = (index) => {
1746
+ const bodyStart = maskedForScope.indexOf("{", index);
1747
+ const probe = bodyStart === -1 ? index : bodyStart + 1;
1748
+ const scope = enclosingHandler(maskedForScope, probe);
1749
+ if (scope === null) return handlerAuthPatterns.some((p) => p.test(codeOnly));
1750
+ return handlerAuthPatterns.some((p) => p.test(scope));
1751
+ };
1675
1752
  const matches = [];
1676
1753
  for (const pattern of routePatterns) {
1677
1754
  matches.push(
@@ -1685,21 +1762,31 @@ var missingAuthMiddleware = {
1685
1762
  );
1686
1763
  }
1687
1764
  if (matches.length === 0 && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
1688
- const withoutCors = stripCorsHeaderList(codeOnly);
1689
- const hasWeakHint = EDGE_WEAK_AUTH_HINTS.some((p) => p.test(withoutCors));
1690
- if (!hasWeakHint) {
1691
- matches.push(
1692
- ...findMatches(
1693
- content,
1694
- DENO_EDGE_ENTRY_RE,
1695
- missingAuthMiddleware,
1696
- filePath,
1697
- () => "This edge function does not establish who is calling it. Read the caller's token from the Authorization header and resolve it (`const { data: { user } } = await supabase.auth.getUser(token)`), or build the Supabase client with that token so row-level security scopes every query to the caller. If the endpoint is public by design, add an inline `// VC003-OK: <reason>` comment above the handler to silence."
1698
- )
1699
- );
1765
+ const fnName = supabaseFunctionName(filePath);
1766
+ const verifyJwt = fnName && project?.supabaseEdgeVerifyJwt ? project.supabaseEdgeVerifyJwt.get(fnName) : void 0;
1767
+ if (verifyJwt !== true) {
1768
+ const withoutCors = stripCorsHeaderList(codeOnly);
1769
+ const hasWeakHint = verifyJwt === false ? false : EDGE_WEAK_AUTH_HINTS.some((p) => p.test(withoutCors));
1770
+ if (!hasWeakHint) {
1771
+ matches.push(
1772
+ ...findMatches(
1773
+ content,
1774
+ DENO_EDGE_ENTRY_RE,
1775
+ missingAuthMiddleware,
1776
+ filePath,
1777
+ () => "This edge function does not establish who is calling it. Read the caller's token from the Authorization header and resolve it (`const { data: { user } } = await supabase.auth.getUser(token)`), or build the Supabase client with that token so row-level security scopes every query to the caller. If the endpoint is public by design, add an inline `// VC003-OK: <reason>` comment above the handler to silence."
1778
+ )
1779
+ );
1780
+ }
1700
1781
  }
1701
1782
  }
1702
- return filterSilenced(matches, content, "VC003");
1783
+ const lineStarts = [0];
1784
+ for (let i = 0; i < content.length; i++) {
1785
+ if (content[i] === "\n") lineStarts.push(i + 1);
1786
+ }
1787
+ const indexOfLine = (line) => lineStarts[Math.max(0, Math.min(line - 1, lineStarts.length - 1))];
1788
+ const unauthenticated = matches.filter((m) => !handlerHasAuth(indexOfLine(m.line)));
1789
+ return filterSilenced(unauthenticated, content, "VC003");
1703
1790
  }
1704
1791
  };
1705
1792
  var supabaseNoRLS = {
@@ -9138,7 +9225,7 @@ var allCustomRules = [
9138
9225
  entitlementFromWebStorage,
9139
9226
  accountStateFromWebStorage
9140
9227
  ];
9141
- function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
9228
+ function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = [], project) {
9142
9229
  const findings = [];
9143
9230
  if (/function runScan\(files\)|export function runCustomRules/.test(content) && /const (?:rules|allRules)\s*[:=]/.test(content) && /findMatches/.test(content)) {
9144
9231
  return findings;
@@ -9160,7 +9247,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
9160
9247
  const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
9161
9248
  for (const rule of ruleset) {
9162
9249
  if (disabledRules.includes(rule.id)) continue;
9163
- const matches = rule.check(content, filePath);
9250
+ const matches = rule.check(content, filePath, project);
9164
9251
  const compliance = complianceMap[rule.id];
9165
9252
  const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
9166
9253
  for (const match of matches) {
@@ -9862,6 +9949,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9862
9949
  androidDebuggable,
9863
9950
  assessHeaders,
9864
9951
  blockingMainThread,
9952
+ buildProjectContext,
9865
9953
  buildTaintMap,
9866
9954
  calculateGrade,
9867
9955
  callSpreads,
@@ -10038,6 +10126,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
10038
10126
  overlyPermissiveIAM,
10039
10127
  parseFile,
10040
10128
  parseScanTarget,
10129
+ parseSupabaseConfig,
10041
10130
  pathTraversal,
10042
10131
  pickleDeserialization,
10043
10132
  piiInLogs,
@@ -10075,6 +10164,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
10075
10164
  ssti,
10076
10165
  stripeWebhookUnprotected,
10077
10166
  supabaseAnonAdmin,
10167
+ supabaseFunctionName,
10078
10168
  supabaseNoRLS,
10079
10169
  syncFileOps,
10080
10170
  terraformStateExposed,