xploitscan-shared-rules 1.20.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 +183 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -3
- package/dist/index.d.ts +74 -3
- package/dist/index.js +180 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -1227,6 +1266,69 @@ var TEST_FILE_PATTERN = /(?:\.test\.|\.spec\.|__tests__|__mocks__|\.stories\.|\.
|
|
|
1227
1266
|
function isTestFile(filePath) {
|
|
1228
1267
|
return TEST_FILE_PATTERN.test(filePath);
|
|
1229
1268
|
}
|
|
1269
|
+
var HANDLER_HEADER_RE = /(?:\b(?:async\s+)?function\b|=>\s*$|=>\s*\{?\s*$|\.(?:get|post|put|patch|delete|use|all)\s*\(|\bexport\s+(?:async\s+)?(?:function|const)\s+(?:GET|POST|PUT|PATCH|DELETE)\b|\b(?:Deno\.)?serve\s*\()/i;
|
|
1270
|
+
function maskComments(content) {
|
|
1271
|
+
return content.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, " ")).replace(/(^|[^:])\/\/[^\n]*/gm, (m, p1) => p1 + " ".repeat(m.length - p1.length));
|
|
1272
|
+
}
|
|
1273
|
+
function queryScope(content, index) {
|
|
1274
|
+
const open = content.indexOf("(", index);
|
|
1275
|
+
if (open === -1 || open - index > 80) return null;
|
|
1276
|
+
let depth = 0;
|
|
1277
|
+
for (let i = open; i < content.length; i++) {
|
|
1278
|
+
const c = content[i];
|
|
1279
|
+
if (c === "(") depth++;
|
|
1280
|
+
else if (c === ")") {
|
|
1281
|
+
depth--;
|
|
1282
|
+
if (depth === 0) return content.slice(open, i + 1);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
function enclosingHandler(content, index) {
|
|
1288
|
+
const MAX_LEVELS = 6;
|
|
1289
|
+
let searchFrom = index;
|
|
1290
|
+
for (let level = 0; level < MAX_LEVELS; level++) {
|
|
1291
|
+
let depth = 0;
|
|
1292
|
+
let open = -1;
|
|
1293
|
+
for (let i = searchFrom; i >= 0; i--) {
|
|
1294
|
+
const c = content[i];
|
|
1295
|
+
if (c === "}") depth++;
|
|
1296
|
+
else if (c === "{") {
|
|
1297
|
+
if (depth === 0) {
|
|
1298
|
+
open = i;
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
depth--;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
if (open === -1) return null;
|
|
1305
|
+
let fwd = 0;
|
|
1306
|
+
let close = -1;
|
|
1307
|
+
for (let i = open; i < content.length; i++) {
|
|
1308
|
+
const c = content[i];
|
|
1309
|
+
if (c === "{") fwd++;
|
|
1310
|
+
else if (c === "}") {
|
|
1311
|
+
fwd--;
|
|
1312
|
+
if (fwd === 0) {
|
|
1313
|
+
close = i;
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
if (close === -1 || close < index) return null;
|
|
1319
|
+
const rawStart = Math.max(0, open - 240);
|
|
1320
|
+
const window = content.slice(rawStart, open);
|
|
1321
|
+
const cut = Math.max(window.lastIndexOf("}"), window.lastIndexOf(";"));
|
|
1322
|
+
const headerStart = cut === -1 ? rawStart : rawStart + cut + 1;
|
|
1323
|
+
const header = content.slice(headerStart, open);
|
|
1324
|
+
if (HANDLER_HEADER_RE.test(header)) {
|
|
1325
|
+
return content.slice(headerStart, close + 1);
|
|
1326
|
+
}
|
|
1327
|
+
searchFrom = open - 1;
|
|
1328
|
+
if (searchFrom < 0) return null;
|
|
1329
|
+
}
|
|
1330
|
+
return null;
|
|
1331
|
+
}
|
|
1230
1332
|
var SERVER_SIDE_PATH_RE = new RegExp(
|
|
1231
1333
|
[
|
|
1232
1334
|
// Directory-style anchors — match with OR without leading slash so
|
|
@@ -1256,6 +1358,7 @@ var SERVER_SIDE_CONTENT_RE = /\b(?:req|request)\.(?:body|query|params|headers|co
|
|
|
1256
1358
|
function isServerSideFile(filePath, content) {
|
|
1257
1359
|
if (isTestFile(filePath)) return false;
|
|
1258
1360
|
if (SERVER_SIDE_PATH_RE.test(filePath)) return true;
|
|
1361
|
+
if (content && /^\s*["']use server["']/m.test(content)) return true;
|
|
1259
1362
|
if (content && SERVER_SIDE_CONTENT_RE.test(content)) return true;
|
|
1260
1363
|
return false;
|
|
1261
1364
|
}
|
|
@@ -1559,7 +1662,7 @@ var missingAuthMiddleware = {
|
|
|
1559
1662
|
severity: "high",
|
|
1560
1663
|
category: "Authentication",
|
|
1561
1664
|
description: "API routes without authentication checks allow unauthorized access.",
|
|
1562
|
-
check(content, filePath) {
|
|
1665
|
+
check(content, filePath, project) {
|
|
1563
1666
|
if (!isServerSideFile(filePath, content)) return [];
|
|
1564
1667
|
const routePatterns = [
|
|
1565
1668
|
// Express/Hono style
|
|
@@ -1567,6 +1670,27 @@ var missingAuthMiddleware = {
|
|
|
1567
1670
|
// Next.js API routes — named function declaration
|
|
1568
1671
|
/export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|PATCH|DELETE)\s*\(/gi
|
|
1569
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
|
+
}
|
|
1570
1694
|
if (/(?:^|\/)(?:src\/)?app\/(?:.*\/)?route\.(?:m?[jt]sx?)$/.test(filePath)) {
|
|
1571
1695
|
routePatterns.push(
|
|
1572
1696
|
/export\s+const\s+(?:GET|POST|PUT|PATCH|DELETE)\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?(?:function\b|\()/g
|
|
@@ -1607,8 +1731,24 @@ var missingAuthMiddleware = {
|
|
|
1607
1731
|
/\b(?:protect|guard)\(/i,
|
|
1608
1732
|
/\.use\([^)]*(?:auth|session|protect|requireAuth)/i
|
|
1609
1733
|
];
|
|
1610
|
-
const
|
|
1611
|
-
|
|
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
|
+
};
|
|
1612
1752
|
const matches = [];
|
|
1613
1753
|
for (const pattern of routePatterns) {
|
|
1614
1754
|
matches.push(
|
|
@@ -1622,21 +1762,31 @@ var missingAuthMiddleware = {
|
|
|
1622
1762
|
);
|
|
1623
1763
|
}
|
|
1624
1764
|
if (matches.length === 0 && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
|
|
1625
|
-
const
|
|
1626
|
-
const
|
|
1627
|
-
if (
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
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
|
+
}
|
|
1637
1781
|
}
|
|
1638
1782
|
}
|
|
1639
|
-
|
|
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");
|
|
1640
1790
|
}
|
|
1641
1791
|
};
|
|
1642
1792
|
var supabaseNoRLS = {
|
|
@@ -8752,15 +8902,22 @@ var insecureDirectObjectReference = {
|
|
|
8752
8902
|
if (!filePath.match(/\.(js|ts|jsx|tsx)$/)) return [];
|
|
8753
8903
|
if (isTestFile(filePath)) return [];
|
|
8754
8904
|
if (/admin/i.test(filePath)) return [];
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
|
|
8905
|
+
const scan = maskComments(content);
|
|
8906
|
+
const LOOKUP_RE = /findUnique|findFirst|findById|\.findOne\b|\.find\s*\(\s*\{|WHERE[\s\S]{0,120}?(?:params|req\.(?:body|query))|\.get\([^)]*(?:params|req\.(?:body|query))/i;
|
|
8907
|
+
const lookup = scan.match(LOOKUP_RE);
|
|
8908
|
+
if (!lookup || lookup.index === void 0) return [];
|
|
8909
|
+
const handlerScope = enclosingHandler(scan, lookup.index) ?? scan;
|
|
8910
|
+
const qScope = queryScope(scan, lookup.index) ?? handlerScope;
|
|
8911
|
+
if (/userId|ownerId|createdBy|user_id|owner_id|AND.*user|where.*user|authorize|canAccess|checkPermission|isOwner|belongsTo/i.test(qScope)) return [];
|
|
8912
|
+
if (/requireUser|requireUserForApi|requireAuth|withAuth|getServerSession|auth\(\)|passport|isAuthenticated/i.test(handlerScope)) return [];
|
|
8758
8913
|
const isNextApiIdor = /\/api\//i.test(filePath) && /export\s+(?:async\s+)?function\s+(?:GET|PUT|PATCH|DELETE)/i.test(content) && /params\.id|params\.(?:slug|uuid)|req\.params\./i.test(content);
|
|
8759
8914
|
const hasExpressHandler = /\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]*["'`]\s*,/i.test(content);
|
|
8760
8915
|
const readsObjectRef = /req\.params\b|req\.(?:body|query)\.\w*id\b/i.test(content);
|
|
8761
8916
|
const isExpressIdor = hasExpressHandler && readsObjectRef;
|
|
8762
|
-
|
|
8763
|
-
const
|
|
8917
|
+
const hasExportedHandler = /(?:module\.)?exports\.\w+\s*=\s*(?:async\s+)?(?:function\s*)?\(\s*req\b[^)]*\)/i.test(content) || /(?:module\.)?exports\.\w+\s*=\s*(?:async\s*)?\(\s*req\b[^)]*\)\s*=>/i.test(content);
|
|
8918
|
+
const isControllerIdor = hasExportedHandler && readsObjectRef;
|
|
8919
|
+
if (!isNextApiIdor && !isExpressIdor && !isControllerIdor) return [];
|
|
8920
|
+
const m = scan.match(/params\.id|params\.(?:slug|uuid)|req\.params\.\w+|req\.params\b|req\.(?:body|query)\.\w*id/i);
|
|
8764
8921
|
if (!m || m.index === void 0) return [];
|
|
8765
8922
|
const lineNum = lineNumberAt(content, m.index);
|
|
8766
8923
|
return [{
|
|
@@ -9068,7 +9225,7 @@ var allCustomRules = [
|
|
|
9068
9225
|
entitlementFromWebStorage,
|
|
9069
9226
|
accountStateFromWebStorage
|
|
9070
9227
|
];
|
|
9071
|
-
function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
|
|
9228
|
+
function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = [], project) {
|
|
9072
9229
|
const findings = [];
|
|
9073
9230
|
if (/function runScan\(files\)|export function runCustomRules/.test(content) && /const (?:rules|allRules)\s*[:=]/.test(content) && /findMatches/.test(content)) {
|
|
9074
9231
|
return findings;
|
|
@@ -9090,7 +9247,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
9090
9247
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
9091
9248
|
for (const rule of ruleset) {
|
|
9092
9249
|
if (disabledRules.includes(rule.id)) continue;
|
|
9093
|
-
const matches = rule.check(content, filePath);
|
|
9250
|
+
const matches = rule.check(content, filePath, project);
|
|
9094
9251
|
const compliance = complianceMap[rule.id];
|
|
9095
9252
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
9096
9253
|
for (const match of matches) {
|
|
@@ -9792,6 +9949,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
9792
9949
|
androidDebuggable,
|
|
9793
9950
|
assessHeaders,
|
|
9794
9951
|
blockingMainThread,
|
|
9952
|
+
buildProjectContext,
|
|
9795
9953
|
buildTaintMap,
|
|
9796
9954
|
calculateGrade,
|
|
9797
9955
|
callSpreads,
|
|
@@ -9968,6 +10126,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
9968
10126
|
overlyPermissiveIAM,
|
|
9969
10127
|
parseFile,
|
|
9970
10128
|
parseScanTarget,
|
|
10129
|
+
parseSupabaseConfig,
|
|
9971
10130
|
pathTraversal,
|
|
9972
10131
|
pickleDeserialization,
|
|
9973
10132
|
piiInLogs,
|
|
@@ -10005,6 +10164,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
10005
10164
|
ssti,
|
|
10006
10165
|
stripeWebhookUnprotected,
|
|
10007
10166
|
supabaseAnonAdmin,
|
|
10167
|
+
supabaseFunctionName,
|
|
10008
10168
|
supabaseNoRLS,
|
|
10009
10169
|
syncFileOps,
|
|
10010
10170
|
terraformStateExposed,
|