xploitscan-shared-rules 1.16.0 → 1.17.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
@@ -1470,6 +1470,80 @@ var exposedEnvFile = {
1470
1470
  }];
1471
1471
  }
1472
1472
  };
1473
+ var SUPABASE_EDGE_FN_RE = /(?:^|\/)supabase\/functions\/[^/]+\/.*\.(?:m?[jt]s)$/;
1474
+ function isDenoEdgeEntry(codeOnly) {
1475
+ if (/\bDeno\s*\.\s*serve\s*\(/.test(codeOnly)) return true;
1476
+ const importsStdServe = /from\s+["']https?:\/\/deno\.land\/[^"']{0,120}\/http\/server(?:\.ts)?["']/.test(codeOnly) || /from\s+["'](?:jsr:)?@std\/http[^"']{0,40}["']/.test(codeOnly);
1477
+ return importsStdServe && /(?<![.\w])serve\s*\(/.test(codeOnly);
1478
+ }
1479
+ var DENO_EDGE_ENTRY_RE = /(?:\bDeno\s*\.\s*serve|(?<![.\w])serve)\s*\(/g;
1480
+ var EDGE_WEAK_AUTH_HINTS = [
1481
+ // WEAK_AUTH — the author touched the caller's identity somehow.
1482
+ // Covers the classifier's `/\bheaders\s*(?:\.\s*get\s*\(\s*)?["'`]?[Aa]uthorization/`
1483
+ // via the plain `authorization` token.
1484
+ /\bauthorization\b/i,
1485
+ /\bbearer\b/i,
1486
+ /\btoken\b/i,
1487
+ /\bsession\b/i,
1488
+ /\bapi[_-]?key\b/i,
1489
+ /\buser\b/,
1490
+ // Beyond the classifier's WEAK_AUTH list — these are strong-auth or
1491
+ // ownership signals there, and suppressing on them here can only remove
1492
+ // findings.
1493
+ /\b401\b/,
1494
+ /\b403\b/,
1495
+ /\bunauthori[sz]ed\b/i,
1496
+ /\bforbidden\b/i,
1497
+ /\bgetSession\b/,
1498
+ /\bgetClaims\b/,
1499
+ // RLS_DELEGATED — the database is the gate
1500
+ /\bcreateServerClient\s*\(/,
1501
+ /\bcreateRouteHandlerClient\s*\(/,
1502
+ /\bcreateServerComponentClient\s*\(/,
1503
+ /\bpersistSession\b/,
1504
+ // SIGNATURE_VERIFY — a receiver that authenticates its caller with a
1505
+ // signature or a shared secret rather than a session. Matched on content
1506
+ // rather than on the function's name, because the name is only a
1507
+ // convention: an edge function called `sync-inventory` can still be a
1508
+ // signed webhook receiver, and flagging it for "missing authentication"
1509
+ // would be wrong in the most embarrassing possible way.
1510
+ /\bconstructEvent\w*\s*\(/,
1511
+ /\bcreateHmac\s*\(/,
1512
+ // `hmac` bare, not just Node's `createHmac`. Deno edge functions verify
1513
+ // signatures with Web Crypto — `crypto.subtle.importKey(…, { name: "HMAC" })`
1514
+ // — which contains no other token on this list. Its absence flagged
1515
+ // correctly-signed receivers, which is the worst false positive this rule
1516
+ // can produce.
1517
+ /\bhmac\b/i,
1518
+ /\btimingSafeEqual\s*\(/,
1519
+ /\bsvix\b/i,
1520
+ /\bWebhook\s*\(\s*\w{0,64}SECRET/i,
1521
+ // Header names, quoted or bare. The quoted form below requires the literal
1522
+ // to END at `-signature`, so it misses `"X-Hub-Signature-256"` — the header
1523
+ // GitHub actually sends.
1524
+ /\bx-hub-signature\b/i,
1525
+ /\bx-signature\b/i,
1526
+ /\bstripe-signature\b/i,
1527
+ /\bverifyHeader\s*\(/,
1528
+ /\bverifySignature\b/i,
1529
+ /\bwebhook[_-]?secret\b/i,
1530
+ /\bsigning[_-]?secret\b/i,
1531
+ // Beyond the classifier's SIGNATURE_VERIFY list.
1532
+ /["'`][\w-]*-signature["'`]/i,
1533
+ /\b\w*(?:webhook|shared|signing|cron|admin|internal)[_-]?secret\b/i
1534
+ ];
1535
+ var EDGE_PUBLIC_PATH_RE = /(^|[/_-])(health(?:z|check)?|ping|status|version|readyz|livez|robots|sitemap|manifest|favicon|opengraph|og-image|og|rss|feed|_?static|public|metrics)([/_.-]|$)/i;
1536
+ var EDGE_AUTH_FLOW_PATH_RE = /(^|[/_[-])(auth|login|signin|sign-in|signup|sign-up|register|logout|signout|sign-out|callback|oauth|sso|session|csrf|reset-password|forgot-password|forgot|magic-?link|verify-?email|confirm|nextauth|otp|invite|token)([/\]_.-]|$)/i;
1537
+ var EDGE_CRON_PATH_RE = /(^|[/_-])(cron|jobs?|scheduled?|tasks?)([/_.-]|$)/i;
1538
+ function isPublicByDesignEdgePath(filePath) {
1539
+ return EDGE_PUBLIC_PATH_RE.test(filePath) || EDGE_AUTH_FLOW_PATH_RE.test(filePath) || EDGE_CRON_PATH_RE.test(filePath);
1540
+ }
1541
+ function stripCorsHeaderList(codeOnly) {
1542
+ return codeOnly.replace(
1543
+ /["'`]?Access-Control-(?:Allow|Expose)-Headers["'`]?\s*:\s*["'`][^"'`]*["'`]/gi,
1544
+ ""
1545
+ );
1546
+ }
1473
1547
  var missingAuthMiddleware = {
1474
1548
  id: "VC003",
1475
1549
  title: "API Route Missing Authentication",
@@ -1481,14 +1555,19 @@ var missingAuthMiddleware = {
1481
1555
  const routePatterns = [
1482
1556
  // Express/Hono style
1483
1557
  /\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]+["'`]\s*,\s*(?:async\s+)?\(?(?:req|c|ctx)/gi,
1484
- // Next.js API routes
1558
+ // Next.js API routes — named function declaration
1485
1559
  /export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|PATCH|DELETE)\s*\(/gi
1486
1560
  ];
1561
+ if (/(?:^|\/)(?:src\/)?app\/(?:.*\/)?route\.(?:m?[jt]sx?)$/.test(filePath)) {
1562
+ routePatterns.push(
1563
+ /export\s+const\s+(?:GET|POST|PUT|PATCH|DELETE)\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?(?:function\b|\()/g
1564
+ );
1565
+ }
1487
1566
  if (isTestFile(filePath)) return [];
1488
1567
  if (filePath.match(/\.(md|txt|rst|html|css|json|yaml|yml)$/)) return [];
1489
1568
  const isAuthRoute = /\/auth\/|\/login|\/signup|\/register|\/logout|\/password\/|\/forgot|\/reset/i.test(filePath);
1490
1569
  if (isAuthRoute) return [];
1491
- const isWebhookRoute = /\/webhook/i.test(filePath);
1570
+ const isWebhookRoute = /\/webhook/i.test(filePath) || /(?:^|[/_-])webhooks?(?:[/_.-]|$)/i.test(filePath);
1492
1571
  if (isWebhookRoute) return [];
1493
1572
  const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1").replace(/^\s*#.*$/gm, "");
1494
1573
  const authPatterns = [
@@ -1533,6 +1612,21 @@ var missingAuthMiddleware = {
1533
1612
  )
1534
1613
  );
1535
1614
  }
1615
+ if (matches.length === 0 && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
1616
+ const withoutCors = stripCorsHeaderList(codeOnly);
1617
+ const hasWeakHint = EDGE_WEAK_AUTH_HINTS.some((p) => p.test(withoutCors));
1618
+ if (!hasWeakHint) {
1619
+ matches.push(
1620
+ ...findMatches(
1621
+ content,
1622
+ DENO_EDGE_ENTRY_RE,
1623
+ missingAuthMiddleware,
1624
+ filePath,
1625
+ () => "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."
1626
+ )
1627
+ );
1628
+ }
1629
+ }
1536
1630
  return filterSilenced(matches, content, "VC003");
1537
1631
  }
1538
1632
  };