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 +96 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +96 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1190,6 +1190,80 @@ var exposedEnvFile = {
|
|
|
1190
1190
|
}];
|
|
1191
1191
|
}
|
|
1192
1192
|
};
|
|
1193
|
+
var SUPABASE_EDGE_FN_RE = /(?:^|\/)supabase\/functions\/[^/]+\/.*\.(?:m?[jt]s)$/;
|
|
1194
|
+
function isDenoEdgeEntry(codeOnly) {
|
|
1195
|
+
if (/\bDeno\s*\.\s*serve\s*\(/.test(codeOnly)) return true;
|
|
1196
|
+
const importsStdServe = /from\s+["']https?:\/\/deno\.land\/[^"']{0,120}\/http\/server(?:\.ts)?["']/.test(codeOnly) || /from\s+["'](?:jsr:)?@std\/http[^"']{0,40}["']/.test(codeOnly);
|
|
1197
|
+
return importsStdServe && /(?<![.\w])serve\s*\(/.test(codeOnly);
|
|
1198
|
+
}
|
|
1199
|
+
var DENO_EDGE_ENTRY_RE = /(?:\bDeno\s*\.\s*serve|(?<![.\w])serve)\s*\(/g;
|
|
1200
|
+
var EDGE_WEAK_AUTH_HINTS = [
|
|
1201
|
+
// WEAK_AUTH — the author touched the caller's identity somehow.
|
|
1202
|
+
// Covers the classifier's `/\bheaders\s*(?:\.\s*get\s*\(\s*)?["'`]?[Aa]uthorization/`
|
|
1203
|
+
// via the plain `authorization` token.
|
|
1204
|
+
/\bauthorization\b/i,
|
|
1205
|
+
/\bbearer\b/i,
|
|
1206
|
+
/\btoken\b/i,
|
|
1207
|
+
/\bsession\b/i,
|
|
1208
|
+
/\bapi[_-]?key\b/i,
|
|
1209
|
+
/\buser\b/,
|
|
1210
|
+
// Beyond the classifier's WEAK_AUTH list — these are strong-auth or
|
|
1211
|
+
// ownership signals there, and suppressing on them here can only remove
|
|
1212
|
+
// findings.
|
|
1213
|
+
/\b401\b/,
|
|
1214
|
+
/\b403\b/,
|
|
1215
|
+
/\bunauthori[sz]ed\b/i,
|
|
1216
|
+
/\bforbidden\b/i,
|
|
1217
|
+
/\bgetSession\b/,
|
|
1218
|
+
/\bgetClaims\b/,
|
|
1219
|
+
// RLS_DELEGATED — the database is the gate
|
|
1220
|
+
/\bcreateServerClient\s*\(/,
|
|
1221
|
+
/\bcreateRouteHandlerClient\s*\(/,
|
|
1222
|
+
/\bcreateServerComponentClient\s*\(/,
|
|
1223
|
+
/\bpersistSession\b/,
|
|
1224
|
+
// SIGNATURE_VERIFY — a receiver that authenticates its caller with a
|
|
1225
|
+
// signature or a shared secret rather than a session. Matched on content
|
|
1226
|
+
// rather than on the function's name, because the name is only a
|
|
1227
|
+
// convention: an edge function called `sync-inventory` can still be a
|
|
1228
|
+
// signed webhook receiver, and flagging it for "missing authentication"
|
|
1229
|
+
// would be wrong in the most embarrassing possible way.
|
|
1230
|
+
/\bconstructEvent\w*\s*\(/,
|
|
1231
|
+
/\bcreateHmac\s*\(/,
|
|
1232
|
+
// `hmac` bare, not just Node's `createHmac`. Deno edge functions verify
|
|
1233
|
+
// signatures with Web Crypto — `crypto.subtle.importKey(…, { name: "HMAC" })`
|
|
1234
|
+
// — which contains no other token on this list. Its absence flagged
|
|
1235
|
+
// correctly-signed receivers, which is the worst false positive this rule
|
|
1236
|
+
// can produce.
|
|
1237
|
+
/\bhmac\b/i,
|
|
1238
|
+
/\btimingSafeEqual\s*\(/,
|
|
1239
|
+
/\bsvix\b/i,
|
|
1240
|
+
/\bWebhook\s*\(\s*\w{0,64}SECRET/i,
|
|
1241
|
+
// Header names, quoted or bare. The quoted form below requires the literal
|
|
1242
|
+
// to END at `-signature`, so it misses `"X-Hub-Signature-256"` — the header
|
|
1243
|
+
// GitHub actually sends.
|
|
1244
|
+
/\bx-hub-signature\b/i,
|
|
1245
|
+
/\bx-signature\b/i,
|
|
1246
|
+
/\bstripe-signature\b/i,
|
|
1247
|
+
/\bverifyHeader\s*\(/,
|
|
1248
|
+
/\bverifySignature\b/i,
|
|
1249
|
+
/\bwebhook[_-]?secret\b/i,
|
|
1250
|
+
/\bsigning[_-]?secret\b/i,
|
|
1251
|
+
// Beyond the classifier's SIGNATURE_VERIFY list.
|
|
1252
|
+
/["'`][\w-]*-signature["'`]/i,
|
|
1253
|
+
/\b\w*(?:webhook|shared|signing|cron|admin|internal)[_-]?secret\b/i
|
|
1254
|
+
];
|
|
1255
|
+
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;
|
|
1256
|
+
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;
|
|
1257
|
+
var EDGE_CRON_PATH_RE = /(^|[/_-])(cron|jobs?|scheduled?|tasks?)([/_.-]|$)/i;
|
|
1258
|
+
function isPublicByDesignEdgePath(filePath) {
|
|
1259
|
+
return EDGE_PUBLIC_PATH_RE.test(filePath) || EDGE_AUTH_FLOW_PATH_RE.test(filePath) || EDGE_CRON_PATH_RE.test(filePath);
|
|
1260
|
+
}
|
|
1261
|
+
function stripCorsHeaderList(codeOnly) {
|
|
1262
|
+
return codeOnly.replace(
|
|
1263
|
+
/["'`]?Access-Control-(?:Allow|Expose)-Headers["'`]?\s*:\s*["'`][^"'`]*["'`]/gi,
|
|
1264
|
+
""
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1193
1267
|
var missingAuthMiddleware = {
|
|
1194
1268
|
id: "VC003",
|
|
1195
1269
|
title: "API Route Missing Authentication",
|
|
@@ -1201,14 +1275,19 @@ var missingAuthMiddleware = {
|
|
|
1201
1275
|
const routePatterns = [
|
|
1202
1276
|
// Express/Hono style
|
|
1203
1277
|
/\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]+["'`]\s*,\s*(?:async\s+)?\(?(?:req|c|ctx)/gi,
|
|
1204
|
-
// Next.js API routes
|
|
1278
|
+
// Next.js API routes — named function declaration
|
|
1205
1279
|
/export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|PATCH|DELETE)\s*\(/gi
|
|
1206
1280
|
];
|
|
1281
|
+
if (/(?:^|\/)(?:src\/)?app\/(?:.*\/)?route\.(?:m?[jt]sx?)$/.test(filePath)) {
|
|
1282
|
+
routePatterns.push(
|
|
1283
|
+
/export\s+const\s+(?:GET|POST|PUT|PATCH|DELETE)\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?(?:function\b|\()/g
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1207
1286
|
if (isTestFile(filePath)) return [];
|
|
1208
1287
|
if (filePath.match(/\.(md|txt|rst|html|css|json|yaml|yml)$/)) return [];
|
|
1209
1288
|
const isAuthRoute = /\/auth\/|\/login|\/signup|\/register|\/logout|\/password\/|\/forgot|\/reset/i.test(filePath);
|
|
1210
1289
|
if (isAuthRoute) return [];
|
|
1211
|
-
const isWebhookRoute = /\/webhook/i.test(filePath);
|
|
1290
|
+
const isWebhookRoute = /\/webhook/i.test(filePath) || /(?:^|[/_-])webhooks?(?:[/_.-]|$)/i.test(filePath);
|
|
1212
1291
|
if (isWebhookRoute) return [];
|
|
1213
1292
|
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1").replace(/^\s*#.*$/gm, "");
|
|
1214
1293
|
const authPatterns = [
|
|
@@ -1253,6 +1332,21 @@ var missingAuthMiddleware = {
|
|
|
1253
1332
|
)
|
|
1254
1333
|
);
|
|
1255
1334
|
}
|
|
1335
|
+
if (matches.length === 0 && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
|
|
1336
|
+
const withoutCors = stripCorsHeaderList(codeOnly);
|
|
1337
|
+
const hasWeakHint = EDGE_WEAK_AUTH_HINTS.some((p) => p.test(withoutCors));
|
|
1338
|
+
if (!hasWeakHint) {
|
|
1339
|
+
matches.push(
|
|
1340
|
+
...findMatches(
|
|
1341
|
+
content,
|
|
1342
|
+
DENO_EDGE_ENTRY_RE,
|
|
1343
|
+
missingAuthMiddleware,
|
|
1344
|
+
filePath,
|
|
1345
|
+
() => "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."
|
|
1346
|
+
)
|
|
1347
|
+
);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1256
1350
|
return filterSilenced(matches, content, "VC003");
|
|
1257
1351
|
}
|
|
1258
1352
|
};
|