xploitscan-shared-rules 1.15.2 → 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
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  allCustomRules: () => allCustomRules,
36
36
  allRules: () => allRules,
37
37
  androidDebuggable: () => androidDebuggable,
38
+ assessHeaders: () => assessHeaders,
38
39
  blockingMainThread: () => blockingMainThread,
39
40
  buildTaintMap: () => buildTaintMap,
40
41
  calculateGrade: () => calculateGrade,
@@ -52,6 +53,8 @@ __export(index_exports, {
52
53
  corsWildcard: () => corsWildcard,
53
54
  dangerousInnerHTML: () => dangerousInnerHTML,
54
55
  deprecatedTLS: () => deprecatedTLS,
56
+ detectBuilder: () => detectBuilder,
57
+ detectExposedConfig: () => detectExposedConfig,
55
58
  detectFramework: () => detectFramework,
56
59
  detectPlatform: () => detectPlatform,
57
60
  disabledTLSVerification: () => disabledTLSVerification,
@@ -80,7 +83,9 @@ __export(index_exports, {
80
83
  exposedServerActions: () => exposedServerActions,
81
84
  exposedSourceMaps: () => exposedSourceMaps,
82
85
  exposedStackTraces: () => exposedStackTraces,
86
+ extractScriptUrls: () => extractScriptUrls,
83
87
  filterFalsePositives: () => filterFalsePositives,
88
+ findSourceMapRefs: () => findSourceMapRefs,
84
89
  firebaseClientConfig: () => firebaseClientConfig,
85
90
  flaskSecretKey: () => flaskSecretKey,
86
91
  freeRules: () => freeRules,
@@ -157,6 +162,7 @@ __export(index_exports, {
157
162
  ipcPathTraversal: () => ipcPathTraversal,
158
163
  isCalleeNamed: () => isCalleeNamed,
159
164
  isMethodCall: () => isMethodCall,
165
+ isPrivateAddress: () => isPrivateAddress,
160
166
  isVendoredFinding: () => isVendoredFinding,
161
167
  isVendoredPath: () => isVendoredPath,
162
168
  javaDeserialization: () => javaDeserialization,
@@ -204,6 +210,7 @@ __export(index_exports, {
204
210
  openRedirectParams: () => openRedirectParams,
205
211
  overlyPermissiveIAM: () => overlyPermissiveIAM,
206
212
  parseFile: () => parseFile,
213
+ parseScanTarget: () => parseScanTarget,
207
214
  pathTraversal: () => pathTraversal,
208
215
  pickleDeserialization: () => pickleDeserialization,
209
216
  piiInLogs: () => piiInLogs,
@@ -1463,6 +1470,80 @@ var exposedEnvFile = {
1463
1470
  }];
1464
1471
  }
1465
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
+ }
1466
1547
  var missingAuthMiddleware = {
1467
1548
  id: "VC003",
1468
1549
  title: "API Route Missing Authentication",
@@ -1474,14 +1555,19 @@ var missingAuthMiddleware = {
1474
1555
  const routePatterns = [
1475
1556
  // Express/Hono style
1476
1557
  /\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]+["'`]\s*,\s*(?:async\s+)?\(?(?:req|c|ctx)/gi,
1477
- // Next.js API routes
1558
+ // Next.js API routes — named function declaration
1478
1559
  /export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|PATCH|DELETE)\s*\(/gi
1479
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
+ }
1480
1566
  if (isTestFile(filePath)) return [];
1481
1567
  if (filePath.match(/\.(md|txt|rst|html|css|json|yaml|yml)$/)) return [];
1482
1568
  const isAuthRoute = /\/auth\/|\/login|\/signup|\/register|\/logout|\/password\/|\/forgot|\/reset/i.test(filePath);
1483
1569
  if (isAuthRoute) return [];
1484
- const isWebhookRoute = /\/webhook/i.test(filePath);
1570
+ const isWebhookRoute = /\/webhook/i.test(filePath) || /(?:^|[/_-])webhooks?(?:[/_.-]|$)/i.test(filePath);
1485
1571
  if (isWebhookRoute) return [];
1486
1572
  const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1").replace(/^\s*#.*$/gm, "");
1487
1573
  const authPatterns = [
@@ -1526,6 +1612,21 @@ var missingAuthMiddleware = {
1526
1612
  )
1527
1613
  );
1528
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
+ }
1529
1630
  return filterSilenced(matches, content, "VC003");
1530
1631
  }
1531
1632
  };
@@ -9305,6 +9406,179 @@ function scanEntropy(files) {
9305
9406
  }
9306
9407
  return findings;
9307
9408
  }
9409
+
9410
+ // src/url-recon.ts
9411
+ var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
9412
+ "localhost",
9413
+ "127.0.0.1",
9414
+ "0.0.0.0",
9415
+ "::1",
9416
+ "[::1]",
9417
+ "metadata.google.internal",
9418
+ "metadata.goog",
9419
+ "instance-data"
9420
+ ]);
9421
+ var BLOCKED_SUFFIXES = [".local", ".localhost", ".internal", ".home.arpa", ".cluster.local"];
9422
+ function isPrivateAddress(address) {
9423
+ const addr = address.trim().toLowerCase().replace(/^\[|\]$/g, "");
9424
+ const mapped = addr.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
9425
+ if (mapped) return isPrivateAddress(mapped[1]);
9426
+ const v4 = addr.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
9427
+ if (v4) {
9428
+ const [a, b] = [Number(v4[1]), Number(v4[2])];
9429
+ if ([a, Number(v4[2]), Number(v4[3]), Number(v4[4])].some((o) => o > 255)) return true;
9430
+ if (a === 0) return true;
9431
+ if (a === 10) return true;
9432
+ if (a === 127) return true;
9433
+ if (a === 169 && b === 254) return true;
9434
+ if (a === 172 && b >= 16 && b <= 31) return true;
9435
+ if (a === 192 && b === 168) return true;
9436
+ if (a === 100 && b >= 64 && b <= 127) return true;
9437
+ if (a === 192 && b === 0) return true;
9438
+ if (a === 198 && (b === 18 || b === 19)) return true;
9439
+ if (a >= 224) return true;
9440
+ return false;
9441
+ }
9442
+ if (addr === "::" || addr === "::1") return true;
9443
+ if (/^f[cd][0-9a-f]{2}:/.test(addr)) return true;
9444
+ if (/^fe[89ab][0-9a-f]:/.test(addr)) return true;
9445
+ return false;
9446
+ }
9447
+ function parseScanTarget(input) {
9448
+ const raw = (input || "").trim();
9449
+ if (!raw) return { ok: false, reason: "Enter a URL to scan." };
9450
+ if (raw.length > 2048) return { ok: false, reason: "That URL is too long." };
9451
+ const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw) ? raw : `https://${raw}`;
9452
+ let url;
9453
+ try {
9454
+ url = new URL(withScheme);
9455
+ } catch {
9456
+ return { ok: false, reason: "That doesn't look like a valid URL." };
9457
+ }
9458
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
9459
+ return { ok: false, reason: "Only http and https URLs can be scanned." };
9460
+ }
9461
+ if (url.username || url.password) {
9462
+ return { ok: false, reason: "Remove the username and password from the URL." };
9463
+ }
9464
+ if (url.port && url.port !== "80" && url.port !== "443") {
9465
+ return { ok: false, reason: "Only the standard web ports (80 and 443) can be scanned." };
9466
+ }
9467
+ const host = url.hostname.toLowerCase();
9468
+ if (BLOCKED_HOSTNAMES.has(host)) {
9469
+ return { ok: false, reason: "That address is not publicly reachable." };
9470
+ }
9471
+ if (BLOCKED_SUFFIXES.some((s) => host.endsWith(s))) {
9472
+ return { ok: false, reason: "That address is not publicly reachable." };
9473
+ }
9474
+ if (isPrivateAddress(host)) {
9475
+ return { ok: false, reason: "That address is not publicly reachable." };
9476
+ }
9477
+ if (!host.includes(".")) {
9478
+ return { ok: false, reason: "Enter a full domain name." };
9479
+ }
9480
+ return { ok: true, url: url.toString(), hostname: host };
9481
+ }
9482
+ var BUILDER_SIGNATURES = [
9483
+ {
9484
+ id: "lovable",
9485
+ name: "Lovable",
9486
+ patterns: [/lovable-tagger/i, /lovable\.dev/i, /data-lov-id=/i, /gpteng\.co/i]
9487
+ },
9488
+ { id: "v0", name: "v0", patterns: [/v0-user-next/i, /v0\.dev/i, /_next\/static.*v0-/i] },
9489
+ { id: "bolt", name: "Bolt", patterns: [/bolt-vite-react/i, /stackblitz/i, /bolt\.new/i] },
9490
+ { id: "base44", name: "Base44", patterns: [/@base44\/sdk/i, /base44\.app/i, /base44\.com/i] }
9491
+ ];
9492
+ function detectBuilder(haystack) {
9493
+ for (const sig of BUILDER_SIGNATURES) {
9494
+ for (const p of sig.patterns) {
9495
+ const m = haystack.match(p);
9496
+ if (m) return { id: sig.id, name: sig.name, evidence: m[0].slice(0, 120) };
9497
+ }
9498
+ }
9499
+ return null;
9500
+ }
9501
+ function findSourceMapRefs(js, bundleUrl) {
9502
+ const out = [];
9503
+ const re = /[#@]\s*sourceMappingURL\s*=\s*([^\s*'"]+)/g;
9504
+ let m;
9505
+ while ((m = re.exec(js)) !== null) {
9506
+ const ref = m[1].trim();
9507
+ if (!ref || ref.startsWith("data:")) continue;
9508
+ try {
9509
+ out.push(new URL(ref, bundleUrl).toString());
9510
+ } catch {
9511
+ }
9512
+ }
9513
+ return [...new Set(out)];
9514
+ }
9515
+ function detectExposedConfig(js) {
9516
+ const out = [];
9517
+ const supabase = js.match(/https:\/\/([a-z0-9]{16,32})\.supabase\.co/i);
9518
+ if (supabase) {
9519
+ out.push({
9520
+ kind: "supabase",
9521
+ projectRef: supabase[1],
9522
+ detail: "A Supabase project URL is present in the client bundle. This is normal and expected \u2014 but it means row-level security is the only thing standing between a visitor and your data."
9523
+ });
9524
+ }
9525
+ const firebase = js.match(/["']?projectId["']?\s*:\s*["']([a-z0-9-]{4,60})["']/i);
9526
+ if (firebase && /firebase/i.test(js)) {
9527
+ out.push({
9528
+ kind: "firebase",
9529
+ projectRef: firebase[1],
9530
+ detail: "A Firebase project configuration is present in the client bundle. This is normal and expected \u2014 but it means your Firestore/Storage rules are the only access control."
9531
+ });
9532
+ }
9533
+ return out;
9534
+ }
9535
+ function assessHeaders(headers) {
9536
+ const h = {};
9537
+ for (const [k, v] of Object.entries(headers)) h[k.toLowerCase()] = v;
9538
+ const out = [];
9539
+ if (!h["content-security-policy"]) {
9540
+ out.push({
9541
+ header: "Content-Security-Policy",
9542
+ severity: "medium",
9543
+ message: "No CSP. A single injected script has nothing stopping it from loading or exfiltrating."
9544
+ });
9545
+ }
9546
+ if (!h["strict-transport-security"]) {
9547
+ out.push({
9548
+ header: "Strict-Transport-Security",
9549
+ severity: "medium",
9550
+ message: "No HSTS. A first visit over http can be intercepted before the redirect to https."
9551
+ });
9552
+ }
9553
+ if (!h["x-content-type-options"]) {
9554
+ out.push({
9555
+ header: "X-Content-Type-Options",
9556
+ severity: "low",
9557
+ message: "Missing nosniff. Browsers may re-interpret a response as a type you did not intend."
9558
+ });
9559
+ }
9560
+ if (!h["referrer-policy"]) {
9561
+ out.push({
9562
+ header: "Referrer-Policy",
9563
+ severity: "low",
9564
+ message: "No referrer policy. Full URLs \u2014 including any ids in the path \u2014 leak to third parties."
9565
+ });
9566
+ }
9567
+ return out;
9568
+ }
9569
+ function extractScriptUrls(html, pageUrl, limit = 12) {
9570
+ const out = [];
9571
+ const re = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["']/gi;
9572
+ let m;
9573
+ while ((m = re.exec(html)) !== null && out.length < limit) {
9574
+ try {
9575
+ const u = new URL(m[1], pageUrl);
9576
+ if (u.protocol === "http:" || u.protocol === "https:") out.push(u.toString());
9577
+ } catch {
9578
+ }
9579
+ }
9580
+ return [...new Set(out)];
9581
+ }
9308
9582
  // Annotate the CommonJS export names for ESM import in node:
9309
9583
  0 && (module.exports = {
9310
9584
  NON_APP_PATH_PATTERNS,
@@ -9312,6 +9586,7 @@ function scanEntropy(files) {
9312
9586
  allCustomRules,
9313
9587
  allRules,
9314
9588
  androidDebuggable,
9589
+ assessHeaders,
9315
9590
  blockingMainThread,
9316
9591
  buildTaintMap,
9317
9592
  calculateGrade,
@@ -9329,6 +9604,8 @@ function scanEntropy(files) {
9329
9604
  corsWildcard,
9330
9605
  dangerousInnerHTML,
9331
9606
  deprecatedTLS,
9607
+ detectBuilder,
9608
+ detectExposedConfig,
9332
9609
  detectFramework,
9333
9610
  detectPlatform,
9334
9611
  disabledTLSVerification,
@@ -9357,7 +9634,9 @@ function scanEntropy(files) {
9357
9634
  exposedServerActions,
9358
9635
  exposedSourceMaps,
9359
9636
  exposedStackTraces,
9637
+ extractScriptUrls,
9360
9638
  filterFalsePositives,
9639
+ findSourceMapRefs,
9361
9640
  firebaseClientConfig,
9362
9641
  flaskSecretKey,
9363
9642
  freeRules,
@@ -9434,6 +9713,7 @@ function scanEntropy(files) {
9434
9713
  ipcPathTraversal,
9435
9714
  isCalleeNamed,
9436
9715
  isMethodCall,
9716
+ isPrivateAddress,
9437
9717
  isVendoredFinding,
9438
9718
  isVendoredPath,
9439
9719
  javaDeserialization,
@@ -9481,6 +9761,7 @@ function scanEntropy(files) {
9481
9761
  openRedirectParams,
9482
9762
  overlyPermissiveIAM,
9483
9763
  parseFile,
9764
+ parseScanTarget,
9484
9765
  pathTraversal,
9485
9766
  pickleDeserialization,
9486
9767
  piiInLogs,