xploitscan-shared-rules 1.20.0 → 1.21.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 +75 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1227,6 +1227,69 @@ var TEST_FILE_PATTERN = /(?:\.test\.|\.spec\.|__tests__|__mocks__|\.stories\.|\.
|
|
|
1227
1227
|
function isTestFile(filePath) {
|
|
1228
1228
|
return TEST_FILE_PATTERN.test(filePath);
|
|
1229
1229
|
}
|
|
1230
|
+
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;
|
|
1231
|
+
function maskComments(content) {
|
|
1232
|
+
return content.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, " ")).replace(/(^|[^:])\/\/[^\n]*/gm, (m, p1) => p1 + " ".repeat(m.length - p1.length));
|
|
1233
|
+
}
|
|
1234
|
+
function queryScope(content, index) {
|
|
1235
|
+
const open = content.indexOf("(", index);
|
|
1236
|
+
if (open === -1 || open - index > 80) return null;
|
|
1237
|
+
let depth = 0;
|
|
1238
|
+
for (let i = open; i < content.length; i++) {
|
|
1239
|
+
const c = content[i];
|
|
1240
|
+
if (c === "(") depth++;
|
|
1241
|
+
else if (c === ")") {
|
|
1242
|
+
depth--;
|
|
1243
|
+
if (depth === 0) return content.slice(open, i + 1);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return null;
|
|
1247
|
+
}
|
|
1248
|
+
function enclosingHandler(content, index) {
|
|
1249
|
+
const MAX_LEVELS = 6;
|
|
1250
|
+
let searchFrom = index;
|
|
1251
|
+
for (let level = 0; level < MAX_LEVELS; level++) {
|
|
1252
|
+
let depth = 0;
|
|
1253
|
+
let open = -1;
|
|
1254
|
+
for (let i = searchFrom; i >= 0; i--) {
|
|
1255
|
+
const c = content[i];
|
|
1256
|
+
if (c === "}") depth++;
|
|
1257
|
+
else if (c === "{") {
|
|
1258
|
+
if (depth === 0) {
|
|
1259
|
+
open = i;
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1262
|
+
depth--;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
if (open === -1) return null;
|
|
1266
|
+
let fwd = 0;
|
|
1267
|
+
let close = -1;
|
|
1268
|
+
for (let i = open; i < content.length; i++) {
|
|
1269
|
+
const c = content[i];
|
|
1270
|
+
if (c === "{") fwd++;
|
|
1271
|
+
else if (c === "}") {
|
|
1272
|
+
fwd--;
|
|
1273
|
+
if (fwd === 0) {
|
|
1274
|
+
close = i;
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
if (close === -1 || close < index) return null;
|
|
1280
|
+
const rawStart = Math.max(0, open - 240);
|
|
1281
|
+
const window = content.slice(rawStart, open);
|
|
1282
|
+
const cut = Math.max(window.lastIndexOf("}"), window.lastIndexOf(";"));
|
|
1283
|
+
const headerStart = cut === -1 ? rawStart : rawStart + cut + 1;
|
|
1284
|
+
const header = content.slice(headerStart, open);
|
|
1285
|
+
if (HANDLER_HEADER_RE.test(header)) {
|
|
1286
|
+
return content.slice(headerStart, close + 1);
|
|
1287
|
+
}
|
|
1288
|
+
searchFrom = open - 1;
|
|
1289
|
+
if (searchFrom < 0) return null;
|
|
1290
|
+
}
|
|
1291
|
+
return null;
|
|
1292
|
+
}
|
|
1230
1293
|
var SERVER_SIDE_PATH_RE = new RegExp(
|
|
1231
1294
|
[
|
|
1232
1295
|
// Directory-style anchors — match with OR without leading slash so
|
|
@@ -8752,15 +8815,22 @@ var insecureDirectObjectReference = {
|
|
|
8752
8815
|
if (!filePath.match(/\.(js|ts|jsx|tsx)$/)) return [];
|
|
8753
8816
|
if (isTestFile(filePath)) return [];
|
|
8754
8817
|
if (/admin/i.test(filePath)) return [];
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
|
|
8818
|
+
const scan = maskComments(content);
|
|
8819
|
+
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;
|
|
8820
|
+
const lookup = scan.match(LOOKUP_RE);
|
|
8821
|
+
if (!lookup || lookup.index === void 0) return [];
|
|
8822
|
+
const handlerScope = enclosingHandler(scan, lookup.index) ?? scan;
|
|
8823
|
+
const qScope = queryScope(scan, lookup.index) ?? handlerScope;
|
|
8824
|
+
if (/userId|ownerId|createdBy|user_id|owner_id|AND.*user|where.*user|authorize|canAccess|checkPermission|isOwner|belongsTo/i.test(qScope)) return [];
|
|
8825
|
+
if (/requireUser|requireUserForApi|requireAuth|withAuth|getServerSession|auth\(\)|passport|isAuthenticated/i.test(handlerScope)) return [];
|
|
8758
8826
|
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
8827
|
const hasExpressHandler = /\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]*["'`]\s*,/i.test(content);
|
|
8760
8828
|
const readsObjectRef = /req\.params\b|req\.(?:body|query)\.\w*id\b/i.test(content);
|
|
8761
8829
|
const isExpressIdor = hasExpressHandler && readsObjectRef;
|
|
8762
|
-
|
|
8763
|
-
const
|
|
8830
|
+
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);
|
|
8831
|
+
const isControllerIdor = hasExportedHandler && readsObjectRef;
|
|
8832
|
+
if (!isNextApiIdor && !isExpressIdor && !isControllerIdor) return [];
|
|
8833
|
+
const m = scan.match(/params\.id|params\.(?:slug|uuid)|req\.params\.\w+|req\.params\b|req\.(?:body|query)\.\w*id/i);
|
|
8764
8834
|
if (!m || m.index === void 0) return [];
|
|
8765
8835
|
const lineNum = lineNumberAt(content, m.index);
|
|
8766
8836
|
return [{
|