xploitscan-shared-rules 2.4.24 → 2.4.25
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 +918 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -10
- package/dist/index.d.ts +1 -10
- package/dist/index.js +918 -98
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -219,7 +219,7 @@ __export(index_exports, {
|
|
|
219
219
|
module.exports = __toCommonJS(index_exports);
|
|
220
220
|
|
|
221
221
|
// src/version.ts
|
|
222
|
-
var SCANNER_VERSION = "2.4.
|
|
222
|
+
var SCANNER_VERSION = "2.4.25";
|
|
223
223
|
|
|
224
224
|
// src/snippet.ts
|
|
225
225
|
var cacheContent = null;
|
|
@@ -2165,7 +2165,7 @@ var PUBLIC_LAST = /^(?:login|logout|signup|register|forgot(?:-password)?|reset(?
|
|
|
2165
2165
|
var SIDE_EFFECT_RE = /\.(?:save|deleteMany|deleteOne|updateMany|updateOne|createMany|findMany|findOne|findUnique|findFirst|findByIdAndDelete|findByIdAndUpdate|remove|destroy|delete|update|create|insert|insertOne|upsert)\s*\(|\.(?:query|execute|exec|rm)\s*\(|\b(?:kv|redis)\s*\.\s*(?:set|del)\s*\(|\bsql\s*`|\bfetch\s*\(|\b(?:readFileSync|readFile|writeFileSync|writeFile|createReadStream|unlinkSync|unlink|mkdirSync|mkdir|execFileSync|execFile|spawn)\s*\(|\bcookies\s*\(\s*\)\s*\.\s*set\s*\(|\bres\s*\.\s*(?:json|send|redirect|end)\s*\(|\bres\s*\.\s*status\s*\([^)]*\)\s*\.\s*(?:json|send|end)\s*\(|\breturn\b/g;
|
|
2166
2166
|
function blankComments(content) {
|
|
2167
2167
|
let open = content.indexOf("/*");
|
|
2168
|
-
let
|
|
2168
|
+
let blocked2 = content;
|
|
2169
2169
|
if (open !== -1) {
|
|
2170
2170
|
const parts = [];
|
|
2171
2171
|
let copied = 0;
|
|
@@ -2177,14 +2177,18 @@ function blankComments(content) {
|
|
|
2177
2177
|
open = content.indexOf("/*", copied);
|
|
2178
2178
|
}
|
|
2179
2179
|
parts.push(content.slice(copied));
|
|
2180
|
-
|
|
2180
|
+
blocked2 = parts.join("");
|
|
2181
2181
|
}
|
|
2182
|
-
return
|
|
2182
|
+
return blocked2.replace(/(^|[^:])\/\/[^\n]*/gm, (m, lead) => lead + " ".repeat(m.length - lead.length));
|
|
2183
2183
|
}
|
|
2184
|
-
|
|
2184
|
+
var ARG_CAP = 300;
|
|
2185
|
+
var IF_BODY_CAP = 2e3;
|
|
2186
|
+
var BRACE_CAP = 2e4;
|
|
2187
|
+
function matchingCloser(text, open, openCh, closeCh, maxLen = Infinity) {
|
|
2185
2188
|
let depth = 0;
|
|
2186
2189
|
let quote = "";
|
|
2187
|
-
|
|
2190
|
+
const end = maxLen === Infinity ? text.length : Math.min(text.length, open + maxLen);
|
|
2191
|
+
for (let i = open; i < end; i++) {
|
|
2188
2192
|
const c = text[i];
|
|
2189
2193
|
if (quote) {
|
|
2190
2194
|
if (c === "\\") {
|
|
@@ -2206,6 +2210,237 @@ function matchingCloser(text, open, openCh, closeCh) {
|
|
|
2206
2210
|
}
|
|
2207
2211
|
return -1;
|
|
2208
2212
|
}
|
|
2213
|
+
function escapeRegExp(value) {
|
|
2214
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2215
|
+
}
|
|
2216
|
+
function maskStrings(content) {
|
|
2217
|
+
const chars = content.split("");
|
|
2218
|
+
let i = 0;
|
|
2219
|
+
while (i < chars.length) {
|
|
2220
|
+
const c = chars[i];
|
|
2221
|
+
if (c === "'" || c === '"') {
|
|
2222
|
+
const quote = c;
|
|
2223
|
+
chars[i] = " ";
|
|
2224
|
+
i++;
|
|
2225
|
+
while (i < chars.length) {
|
|
2226
|
+
if (chars[i] === "\\") {
|
|
2227
|
+
chars[i] = " ";
|
|
2228
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
2229
|
+
i += 2;
|
|
2230
|
+
continue;
|
|
2231
|
+
}
|
|
2232
|
+
if (chars[i] === "\n") break;
|
|
2233
|
+
if (chars[i] === quote) {
|
|
2234
|
+
chars[i] = " ";
|
|
2235
|
+
i++;
|
|
2236
|
+
break;
|
|
2237
|
+
}
|
|
2238
|
+
chars[i] = " ";
|
|
2239
|
+
i++;
|
|
2240
|
+
}
|
|
2241
|
+
continue;
|
|
2242
|
+
}
|
|
2243
|
+
if (c === "`") {
|
|
2244
|
+
chars[i] = " ";
|
|
2245
|
+
i++;
|
|
2246
|
+
let expr = 0;
|
|
2247
|
+
while (i < chars.length) {
|
|
2248
|
+
if (expr === 0 && chars[i] === "\\") {
|
|
2249
|
+
chars[i] = " ";
|
|
2250
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
2251
|
+
i += 2;
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
if (expr === 0 && chars[i] === "`") {
|
|
2255
|
+
chars[i] = " ";
|
|
2256
|
+
i++;
|
|
2257
|
+
break;
|
|
2258
|
+
}
|
|
2259
|
+
if (expr === 0 && chars[i] === "$" && chars[i + 1] === "{") {
|
|
2260
|
+
chars[i] = " ";
|
|
2261
|
+
chars[i + 1] = " ";
|
|
2262
|
+
expr = 1;
|
|
2263
|
+
i += 2;
|
|
2264
|
+
continue;
|
|
2265
|
+
}
|
|
2266
|
+
if (expr > 0) {
|
|
2267
|
+
if (chars[i] === "{") expr++;
|
|
2268
|
+
else if (chars[i] === "}") expr--;
|
|
2269
|
+
i++;
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
if (chars[i] !== "\n") chars[i] = " ";
|
|
2273
|
+
i++;
|
|
2274
|
+
}
|
|
2275
|
+
continue;
|
|
2276
|
+
}
|
|
2277
|
+
i++;
|
|
2278
|
+
}
|
|
2279
|
+
return chars.join("");
|
|
2280
|
+
}
|
|
2281
|
+
var REJECT_RE = /\bthrow\b|\bredirect\s*\(|\b(?:status(?:Code)?|sendStatus)\s*[:(=]\s*40[13]\b/;
|
|
2282
|
+
function localImportedNames(clause) {
|
|
2283
|
+
const names = [];
|
|
2284
|
+
for (const part of clause.split(",")) {
|
|
2285
|
+
const bits = part.trim().split(/\s+as\s+/i);
|
|
2286
|
+
const local = (bits[1] ?? bits[0] ?? "").replace(/^\s*type\s+/, "").trim();
|
|
2287
|
+
const ident = /^([A-Za-z_$][\w$]*)$/.exec(local);
|
|
2288
|
+
if (ident) names.push(ident[1]);
|
|
2289
|
+
}
|
|
2290
|
+
return names;
|
|
2291
|
+
}
|
|
2292
|
+
function isImportedName(content, name) {
|
|
2293
|
+
const id = escapeRegExp(name);
|
|
2294
|
+
if (new RegExp(`\\bimport\\s+${id}\\s+from\\b`).test(content)) return true;
|
|
2295
|
+
if (new RegExp(`\\b(?:const|let|var)\\s+${id}\\s*=\\s*require\\s*\\(`).test(content)) return true;
|
|
2296
|
+
for (const match of content.matchAll(/\bimport\s+(?:type\s+)?\{([^}]+)\}\s*from/g)) {
|
|
2297
|
+
if (localImportedNames(match[1]).includes(name)) return true;
|
|
2298
|
+
}
|
|
2299
|
+
for (const match of content.matchAll(/\b(?:const|let|var)\s*\{([^}]+)\}\s*=\s*require\s*\(/g)) {
|
|
2300
|
+
if (localImportedNames(match[1]).includes(name)) return true;
|
|
2301
|
+
}
|
|
2302
|
+
return false;
|
|
2303
|
+
}
|
|
2304
|
+
function jwtBindingSpan(file, name) {
|
|
2305
|
+
const id = escapeRegExp(name);
|
|
2306
|
+
const patterns = [
|
|
2307
|
+
new RegExp(`\\bimport\\s+${id}\\s+from\\s+["']jsonwebtoken["']`),
|
|
2308
|
+
new RegExp(`\\bimport\\s*\\*\\s*as\\s+${id}\\s+from\\s+["']jsonwebtoken["']`),
|
|
2309
|
+
new RegExp(
|
|
2310
|
+
`(?:const|let|var)\\s+${id}\\s*=\\s*require\\(\\s*["']jsonwebtoken["']\\s*\\)\\s*;?(?=\\s*(?:$|\\n|\\r))`
|
|
2311
|
+
)
|
|
2312
|
+
];
|
|
2313
|
+
for (const pattern of patterns) {
|
|
2314
|
+
const match = pattern.exec(file);
|
|
2315
|
+
if (!match || match.index === void 0) continue;
|
|
2316
|
+
return [match.index, match.index + match[0].length];
|
|
2317
|
+
}
|
|
2318
|
+
return null;
|
|
2319
|
+
}
|
|
2320
|
+
function bindingIsShadowed(file, name, span) {
|
|
2321
|
+
const id = escapeRegExp(name);
|
|
2322
|
+
const checks = [
|
|
2323
|
+
new RegExp(`\\b(?:const|let|var)\\s+${id}\\b`, "g"),
|
|
2324
|
+
new RegExp(`\\b${id}\\s*=(?!=)`, "g"),
|
|
2325
|
+
new RegExp(`[(,]\\s*${id}\\s*[,)=:]`, "g")
|
|
2326
|
+
];
|
|
2327
|
+
for (const pattern of checks) {
|
|
2328
|
+
let match;
|
|
2329
|
+
while (match = pattern.exec(file)) {
|
|
2330
|
+
if (match.index >= span[0] && match.index < span[1]) continue;
|
|
2331
|
+
return true;
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
return false;
|
|
2335
|
+
}
|
|
2336
|
+
function identifierIsObjectLiteral(file, name) {
|
|
2337
|
+
const id = escapeRegExp(name);
|
|
2338
|
+
return new RegExp(`(?:\\b(?:const|let|var)\\s+|(?<![\\w$.]))${id}\\s*=(?!=)\\s*\\{`).test(file);
|
|
2339
|
+
}
|
|
2340
|
+
function verifyCallForm(source, callIndex, file) {
|
|
2341
|
+
const open = source.indexOf("(", callIndex);
|
|
2342
|
+
if (open < 0) return "none";
|
|
2343
|
+
const close = matchingCloser(source, open, "(", ")", ARG_CAP);
|
|
2344
|
+
if (close < 0) return "none";
|
|
2345
|
+
const args = splitArgs(source.slice(open + 1, close)).map((part) => part.trim()).filter(Boolean);
|
|
2346
|
+
if (args.length === 2) return "sync";
|
|
2347
|
+
if (args.length >= 4) return "callback";
|
|
2348
|
+
if (args.length !== 3) return "none";
|
|
2349
|
+
const third = args[2];
|
|
2350
|
+
if (/=>/.test(third) || /^\s*(?:async\s+)?function\b/.test(third)) return "callback";
|
|
2351
|
+
if (/^\s*\{/.test(third)) return "sync";
|
|
2352
|
+
const ident = /^\s*([A-Za-z_$][\w$]*)\s*$/.exec(third);
|
|
2353
|
+
if (!ident) return "callback";
|
|
2354
|
+
return identifierIsObjectLiteral(file, ident[1]) ? "sync" : "callback";
|
|
2355
|
+
}
|
|
2356
|
+
function syncJwtCredits(body, file) {
|
|
2357
|
+
const masked = maskStrings(body);
|
|
2358
|
+
const re = /\b([A-Za-z_$][\w$]*)\s*\.\s*verify\s*\(/g;
|
|
2359
|
+
let match;
|
|
2360
|
+
while (match = re.exec(masked)) {
|
|
2361
|
+
const span = jwtBindingSpan(file, match[1]);
|
|
2362
|
+
if (!span || bindingIsShadowed(file, match[1], span)) continue;
|
|
2363
|
+
if (verifyCallForm(masked, match.index, file) !== "sync") continue;
|
|
2364
|
+
if (!errorPathRejects(masked, match.index)) continue;
|
|
2365
|
+
return true;
|
|
2366
|
+
}
|
|
2367
|
+
return false;
|
|
2368
|
+
}
|
|
2369
|
+
var fnCacheContent = null;
|
|
2370
|
+
var fnCacheSpans = [];
|
|
2371
|
+
function headerIsFunction(content, brace) {
|
|
2372
|
+
const header = content.slice(Math.max(0, brace - 180), brace);
|
|
2373
|
+
const last = header.slice(header.lastIndexOf("\n") + 1);
|
|
2374
|
+
if (/=>\s*$/.test(last) || /\bfunction\b/.test(last)) return true;
|
|
2375
|
+
const method = /^\s*(?:(?:public|private|protected|static|async|override)\s+)*([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*(?::\s*[^{]+)?$/.exec(last);
|
|
2376
|
+
if (!method) return false;
|
|
2377
|
+
return !/^(?:if|for|while|switch|catch|function|return|else|try)$/.test(method[1]);
|
|
2378
|
+
}
|
|
2379
|
+
function buildFnSpans(content) {
|
|
2380
|
+
const spans = [];
|
|
2381
|
+
const stack = [];
|
|
2382
|
+
let quote = "";
|
|
2383
|
+
for (let i = 0; i < content.length; i++) {
|
|
2384
|
+
const c = content[i];
|
|
2385
|
+
if (quote) {
|
|
2386
|
+
if (c === "\\" && quote !== "`") {
|
|
2387
|
+
i++;
|
|
2388
|
+
continue;
|
|
2389
|
+
}
|
|
2390
|
+
if (c === quote) quote = "";
|
|
2391
|
+
else if (quote !== "`" && c === "\n") quote = "";
|
|
2392
|
+
continue;
|
|
2393
|
+
}
|
|
2394
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
2395
|
+
quote = c;
|
|
2396
|
+
continue;
|
|
2397
|
+
}
|
|
2398
|
+
if (c === "{") stack.push({ open: i, isFn: headerIsFunction(content, i) });
|
|
2399
|
+
else if (c === "}" && stack.length) {
|
|
2400
|
+
const frame = stack.pop();
|
|
2401
|
+
if (frame?.isFn) spans.push({ open: frame.open, close: i });
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
for (const frame of stack) {
|
|
2405
|
+
if (frame.isFn) spans.push({ open: frame.open, close: content.length });
|
|
2406
|
+
}
|
|
2407
|
+
return spans;
|
|
2408
|
+
}
|
|
2409
|
+
var fnPrefixMax = [];
|
|
2410
|
+
function prepareFnCache(content) {
|
|
2411
|
+
if (fnCacheContent === content) return;
|
|
2412
|
+
fnCacheContent = content;
|
|
2413
|
+
fnCacheSpans = buildFnSpans(content).sort((a, b) => a.open - b.open || a.close - b.close);
|
|
2414
|
+
fnPrefixMax = new Array(fnCacheSpans.length);
|
|
2415
|
+
for (let i = 0; i < fnCacheSpans.length; i++) {
|
|
2416
|
+
fnPrefixMax[i] = i === 0 ? fnCacheSpans[i].close : Math.max(fnPrefixMax[i - 1], fnCacheSpans[i].close);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
function fnKeyAt(content, index) {
|
|
2420
|
+
prepareFnCache(content);
|
|
2421
|
+
const spans = fnCacheSpans;
|
|
2422
|
+
let lo = 0;
|
|
2423
|
+
let hi = spans.length - 1;
|
|
2424
|
+
let found = -1;
|
|
2425
|
+
while (lo <= hi) {
|
|
2426
|
+
const mid = lo + hi >> 1;
|
|
2427
|
+
if (spans[mid].open < index) {
|
|
2428
|
+
found = mid;
|
|
2429
|
+
lo = mid + 1;
|
|
2430
|
+
} else {
|
|
2431
|
+
hi = mid - 1;
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
for (let i = found; i >= 0; i--) {
|
|
2435
|
+
if (fnPrefixMax[i] < index) break;
|
|
2436
|
+
const span = spans[i];
|
|
2437
|
+
if (index <= span.close) {
|
|
2438
|
+
if (index - span.open > BRACE_CAP) return "exhausted";
|
|
2439
|
+
return "fn@" + span.open;
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
return "top";
|
|
2443
|
+
}
|
|
2209
2444
|
function firstSideEffect(handler) {
|
|
2210
2445
|
SIDE_EFFECT_RE.lastIndex = 0;
|
|
2211
2446
|
const match = SIDE_EFFECT_RE.exec(handler);
|
|
@@ -2216,39 +2451,51 @@ function beforeSideEffect(handler, index) {
|
|
|
2216
2451
|
return at === -1 || index < at;
|
|
2217
2452
|
}
|
|
2218
2453
|
function localGuardBody(content, name) {
|
|
2219
|
-
const
|
|
2454
|
+
const id = escapeRegExp(name);
|
|
2455
|
+
const fn = new RegExp(`\\b(?:async\\s+)?function\\s+${id}\\s*\\([^)]*\\)\\s*\\{`).exec(content);
|
|
2220
2456
|
if (fn && fn.index !== void 0) {
|
|
2221
2457
|
const brace = content.indexOf("{", fn.index);
|
|
2222
|
-
const end = matchingCloser(content, brace, "{", "}");
|
|
2458
|
+
const end = matchingCloser(content, brace, "{", "}", BRACE_CAP);
|
|
2223
2459
|
return end < 0 ? "" : content.slice(brace + 1, end);
|
|
2224
2460
|
}
|
|
2225
2461
|
const arrow = new RegExp(
|
|
2226
|
-
`\\b(?:const|let|var)\\s+${
|
|
2462
|
+
`\\b(?:const|let|var)\\s+${id}\\s*=\\s*(?:async\\s*)?(?:function\\s*\\([^)]*\\)|(?:\\([^)]*\\)|[A-Za-z_]\\w*)\\s*=>)`
|
|
2227
2463
|
).exec(content);
|
|
2228
2464
|
if (!arrow || arrow.index === void 0) return null;
|
|
2229
2465
|
const after = arrow.index + arrow[0].length;
|
|
2230
2466
|
const rest = content.slice(after);
|
|
2231
2467
|
if (/^\s*\{/.test(rest)) {
|
|
2232
2468
|
const brace = content.indexOf("{", after);
|
|
2233
|
-
const end = matchingCloser(content, brace, "{", "}");
|
|
2469
|
+
const end = matchingCloser(content, brace, "{", "}", BRACE_CAP);
|
|
2234
2470
|
return end < 0 ? "" : content.slice(brace + 1, end);
|
|
2235
2471
|
}
|
|
2236
2472
|
const semi = content.indexOf(";", after);
|
|
2237
2473
|
return content.slice(after, semi === -1 ? content.length : semi);
|
|
2238
2474
|
}
|
|
2239
|
-
function guardBodyQualifies(body) {
|
|
2240
|
-
const
|
|
2475
|
+
function guardBodyQualifies(body, file) {
|
|
2476
|
+
const masked = maskStrings(body);
|
|
2477
|
+
const flat = masked.replace(/\s+/g, " ").trim();
|
|
2241
2478
|
if (!flat) return false;
|
|
2242
2479
|
if (/^(?:return\s+)?next\s*\(\s*\)\s*;?$/.test(flat)) return false;
|
|
2243
|
-
|
|
2480
|
+
if (REJECT_RE.test(masked)) return true;
|
|
2481
|
+
return syncJwtCredits(body, file);
|
|
2244
2482
|
}
|
|
2483
|
+
var guardCacheContent = null;
|
|
2484
|
+
var guardCache = /* @__PURE__ */ new Map();
|
|
2245
2485
|
function guardNameCounts(content, name) {
|
|
2486
|
+
if (guardCacheContent !== content) {
|
|
2487
|
+
guardCacheContent = content;
|
|
2488
|
+
guardCache.clear();
|
|
2489
|
+
}
|
|
2490
|
+
const cached = guardCache.get(name);
|
|
2491
|
+
if (cached !== void 0) return cached;
|
|
2246
2492
|
const body = localGuardBody(content, name);
|
|
2247
|
-
|
|
2248
|
-
|
|
2493
|
+
const result = body === null ? isImportedName(content, name) : guardBodyQualifies(body, content);
|
|
2494
|
+
guardCache.set(name, result);
|
|
2495
|
+
return result;
|
|
2249
2496
|
}
|
|
2250
2497
|
function guardMentioned(content, args) {
|
|
2251
|
-
return GUARD_NAMES.some((name) => new RegExp(`\\b${name}\\b`).test(args) && guardNameCounts(content, name));
|
|
2498
|
+
return GUARD_NAMES.some((name) => new RegExp(`\\b${escapeRegExp(name)}\\b`).test(args) && guardNameCounts(content, name));
|
|
2252
2499
|
}
|
|
2253
2500
|
function handlerBodyOpen(handler) {
|
|
2254
2501
|
const arrow = handler.search(/=>\s*\{/);
|
|
@@ -2289,16 +2536,38 @@ function guardStatementCounts(handler, callIndex) {
|
|
|
2289
2536
|
else if (c === ")") paren--;
|
|
2290
2537
|
else if (c === "[") bracket++;
|
|
2291
2538
|
else if (c === "]") bracket--;
|
|
2292
|
-
else if (c === "
|
|
2539
|
+
else if (c === "\n" && brace === 1 && paren === 0 && bracket === 0) {
|
|
2540
|
+
let j = i - 1;
|
|
2541
|
+
while (j > bodyOpen && /[ \t\r]/.test(handler[j])) j--;
|
|
2542
|
+
const prev = handler[j] ?? "";
|
|
2543
|
+
if (!",([{+-*/=&|?:.".includes(prev)) stmtStart = i + 1;
|
|
2544
|
+
} else if (c === ";" && brace === 1 && paren === 0 && bracket === 0) stmtStart = i + 1;
|
|
2293
2545
|
}
|
|
2294
2546
|
if (brace !== 1 || paren !== 0 || bracket !== 0) return false;
|
|
2295
2547
|
const stmt = handler.slice(stmtStart, callIndex);
|
|
2296
2548
|
if (/&&|\|\||\?\?|\?(?!\.)/.test(stmt)) return false;
|
|
2297
|
-
if (/\b(?:if|while|for|switch)\b/.test(stmt)) return false;
|
|
2549
|
+
if (/\b(?:if|else|while|for|switch|catch|try)\b/.test(stmt)) return false;
|
|
2298
2550
|
if (!/\b(?:const|let|var)\b|=/.test(stmt)) return true;
|
|
2299
|
-
const assigned =
|
|
2551
|
+
const assigned = lastAssignedName(stmt);
|
|
2300
2552
|
if (!assigned) return false;
|
|
2301
|
-
return new RegExp(`\\b${assigned}\\b`).test(handler.slice(callIndex + 1));
|
|
2553
|
+
return new RegExp(`\\b${escapeRegExp(assigned)}\\b`).test(handler.slice(callIndex + 1));
|
|
2554
|
+
}
|
|
2555
|
+
function lastAssignedName(stmt) {
|
|
2556
|
+
let name;
|
|
2557
|
+
let at = -1;
|
|
2558
|
+
for (const match of stmt.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
2559
|
+
if (match.index !== void 0 && match.index >= at) {
|
|
2560
|
+
at = match.index;
|
|
2561
|
+
name = match[1];
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
for (const match of stmt.matchAll(/([A-Za-z_$][\w$]*)\s*=(?!=)/g)) {
|
|
2565
|
+
if (match.index !== void 0 && match.index >= at) {
|
|
2566
|
+
at = match.index;
|
|
2567
|
+
name = match[1];
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
return name;
|
|
2302
2571
|
}
|
|
2303
2572
|
function guardCallBeforeSideEffect(content, handler) {
|
|
2304
2573
|
const re = new RegExp(`\\b(${GUARD_NAMES.join("|")})\\s*\\(`, "g");
|
|
@@ -2324,6 +2593,34 @@ function authPrefixCovers(prefix, path) {
|
|
|
2324
2593
|
const normalized = prefix.length > 1 ? prefix.replace(/\/+$/, "") : prefix;
|
|
2325
2594
|
return path === normalized || path.startsWith(normalized + "/");
|
|
2326
2595
|
}
|
|
2596
|
+
var useCacheContent = null;
|
|
2597
|
+
var useCacheByKey = /* @__PURE__ */ new Map();
|
|
2598
|
+
function usesInScope(content, key) {
|
|
2599
|
+
if (useCacheContent === content) return useCacheByKey.get(key) ?? [];
|
|
2600
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2601
|
+
const re = /\b([A-Za-z_$][\w$]*)\s*\.\s*use\s*\(/g;
|
|
2602
|
+
let match;
|
|
2603
|
+
while (match = re.exec(content)) {
|
|
2604
|
+
const open = match.index + match[0].length - 1;
|
|
2605
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP);
|
|
2606
|
+
if (close < 0) continue;
|
|
2607
|
+
const args = content.slice(open + 1, close);
|
|
2608
|
+
const siteKey = fnKeyAt(content, match.index);
|
|
2609
|
+
const site = {
|
|
2610
|
+
index: match.index,
|
|
2611
|
+
receiver: match[1],
|
|
2612
|
+
args,
|
|
2613
|
+
first: (splitArgs(args)[0] ?? "").trim(),
|
|
2614
|
+
key: siteKey
|
|
2615
|
+
};
|
|
2616
|
+
const list = byKey.get(siteKey);
|
|
2617
|
+
if (list) list.push(site);
|
|
2618
|
+
else byKey.set(siteKey, [site]);
|
|
2619
|
+
}
|
|
2620
|
+
useCacheContent = content;
|
|
2621
|
+
useCacheByKey = byKey;
|
|
2622
|
+
return byKey.get(key) ?? [];
|
|
2623
|
+
}
|
|
2327
2624
|
function useCoversRoute(content, index) {
|
|
2328
2625
|
const lineStart = content.lastIndexOf("\n", Math.max(0, index - 1)) + 1;
|
|
2329
2626
|
const lineEnd = content.indexOf("\n", index);
|
|
@@ -2332,17 +2629,17 @@ function useCoversRoute(content, index) {
|
|
|
2332
2629
|
if (!route) return false;
|
|
2333
2630
|
const receiver = route[1];
|
|
2334
2631
|
const path = route[2];
|
|
2335
|
-
const
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
if (
|
|
2339
|
-
const
|
|
2340
|
-
const
|
|
2341
|
-
if (
|
|
2342
|
-
const
|
|
2343
|
-
const prefix = /^\s*["'`]([^"'`]+)["'`]/.exec(args)?.[1] ?? "";
|
|
2632
|
+
const routeKey = fnKeyAt(content, index);
|
|
2633
|
+
if (routeKey === "exhausted") return false;
|
|
2634
|
+
for (const site of usesInScope(content, routeKey)) {
|
|
2635
|
+
if (site.receiver !== receiver || site.index >= lineStart) continue;
|
|
2636
|
+
const stringPrefix = /^\s*["'`]([^"'`]*)["'`]/.exec(site.first)?.[1];
|
|
2637
|
+
const firstIsGuard = /^[A-Za-z_$][\w$]*$/.test(site.first) && GUARD_NAMES.includes(site.first) && guardNameCounts(content, site.first);
|
|
2638
|
+
if (stringPrefix === void 0 && !firstIsGuard) continue;
|
|
2639
|
+
const prefix = stringPrefix ?? "";
|
|
2344
2640
|
if (prefix && !authPrefixCovers(prefix, path)) continue;
|
|
2345
|
-
if (guardMentioned(content, args))
|
|
2641
|
+
if (!guardMentioned(content, site.args) && !firstIsGuard) continue;
|
|
2642
|
+
return true;
|
|
2346
2643
|
}
|
|
2347
2644
|
return false;
|
|
2348
2645
|
}
|
|
@@ -2405,17 +2702,29 @@ function splitArgs(args) {
|
|
|
2405
2702
|
parts.push(args.slice(start));
|
|
2406
2703
|
return parts;
|
|
2407
2704
|
}
|
|
2705
|
+
function unwrapSecret(value) {
|
|
2706
|
+
let bare = value.trim().replace(/!+$/, "").trim();
|
|
2707
|
+
for (let n = 0; n < 4; n++) {
|
|
2708
|
+
if (!bare.startsWith("(")) break;
|
|
2709
|
+
const end = matchingCloser(bare, 0, "(", ")", ARG_CAP);
|
|
2710
|
+
if (end < 0 || end !== bare.length - 1) break;
|
|
2711
|
+
bare = bare.slice(1, -1).trim().replace(/!+$/, "").trim();
|
|
2712
|
+
}
|
|
2713
|
+
return bare;
|
|
2714
|
+
}
|
|
2715
|
+
function secretValueReal(value) {
|
|
2716
|
+
const bare = unwrapSecret(value);
|
|
2717
|
+
if (bare === '""' || bare === "''" || bare === "``" || bare === "undefined" || bare === "") return false;
|
|
2718
|
+
if (/(\|\||\?\?)\s*(["'`])[^"'`]*\2\s*$/.test(bare)) return false;
|
|
2719
|
+
return true;
|
|
2720
|
+
}
|
|
2408
2721
|
function secretArgOk(args) {
|
|
2409
2722
|
const parts = splitArgs(args).map((part) => part.trim()).filter(Boolean);
|
|
2410
|
-
|
|
2411
|
-
const bare = value.replace(/!+$/, "").trim();
|
|
2412
|
-
return bare === '""' || bare === "''" || bare === "``" || bare === "undefined" || bare === "";
|
|
2413
|
-
};
|
|
2414
|
-
if (parts.length >= 3) return !empty(parts[2]);
|
|
2723
|
+
if (parts.length >= 3) return secretValueReal(parts[2]);
|
|
2415
2724
|
if (parts.length === 1 && parts[0].startsWith("{")) {
|
|
2416
2725
|
const prop = parts[0].match(/\b(?:secret|signingKey|currentSigningKey|token)\s*:\s*([^,}\n]+)/i);
|
|
2417
2726
|
if (!prop) return false;
|
|
2418
|
-
return
|
|
2727
|
+
return secretValueReal(prop[1]);
|
|
2419
2728
|
}
|
|
2420
2729
|
return false;
|
|
2421
2730
|
}
|
|
@@ -2434,7 +2743,7 @@ function errorPathRejects(handler, callIndex) {
|
|
|
2434
2743
|
if (!caught) return true;
|
|
2435
2744
|
const brace = handler.indexOf("{", caught.index);
|
|
2436
2745
|
if (brace < 0) return false;
|
|
2437
|
-
const end = matchingCloser(handler, brace, "{", "}");
|
|
2746
|
+
const end = matchingCloser(handler, brace, "{", "}", BRACE_CAP);
|
|
2438
2747
|
if (end < 0) return false;
|
|
2439
2748
|
const body = handler.slice(brace, end);
|
|
2440
2749
|
return /\bthrow\b/.test(body) || /\breturn\b/.test(body) && /\b4\d\d\b/.test(body);
|
|
@@ -2444,7 +2753,7 @@ function signatureCheckQualifies(handler) {
|
|
|
2444
2753
|
let match;
|
|
2445
2754
|
while (match = callRe.exec(handler)) {
|
|
2446
2755
|
const open = match.index + match[0].length - 1;
|
|
2447
|
-
const close = matchingCloser(handler, open, "(", ")");
|
|
2756
|
+
const close = matchingCloser(handler, open, "(", ")", ARG_CAP);
|
|
2448
2757
|
if (close < 0) continue;
|
|
2449
2758
|
const args = handler.slice(open + 1, close);
|
|
2450
2759
|
if (!/\.text\s*\(/.test(handler) && !/\.text\s*\(/.test(args)) continue;
|
|
@@ -2456,37 +2765,551 @@ function signatureCheckQualifies(handler) {
|
|
|
2456
2765
|
}
|
|
2457
2766
|
return false;
|
|
2458
2767
|
}
|
|
2768
|
+
function ifBranchBody(handler, closeParen) {
|
|
2769
|
+
let i = closeParen + 1;
|
|
2770
|
+
while (i < handler.length && /\s/.test(handler[i])) i++;
|
|
2771
|
+
if (i >= handler.length) return null;
|
|
2772
|
+
if (handler[i] === "{") {
|
|
2773
|
+
const end = matchingCloser(handler, i, "{", "}", IF_BODY_CAP);
|
|
2774
|
+
if (end < 0) return null;
|
|
2775
|
+
return handler.slice(i + 1, end);
|
|
2776
|
+
}
|
|
2777
|
+
const limit = Math.min(handler.length, i + IF_BODY_CAP);
|
|
2778
|
+
const semi = handler.indexOf(";", i);
|
|
2779
|
+
if (semi < 0 || semi >= limit) return null;
|
|
2780
|
+
return handler.slice(i, semi);
|
|
2781
|
+
}
|
|
2782
|
+
function branchRejects401(body) {
|
|
2783
|
+
return /\breturn\b/.test(body) && /\b401\b/.test(body) || /\b(?:status|sendStatus)\s*\(\s*401\b/.test(body);
|
|
2784
|
+
}
|
|
2459
2785
|
function cronSecretGates(handler) {
|
|
2460
2786
|
const re = /\bif\s*\(/g;
|
|
2461
2787
|
let match;
|
|
2462
2788
|
while (match = re.exec(handler)) {
|
|
2463
2789
|
const open = match.index + match[0].length - 1;
|
|
2464
|
-
const close = matchingCloser(handler, open, "(", ")");
|
|
2790
|
+
const close = matchingCloser(handler, open, "(", ")", ARG_CAP);
|
|
2465
2791
|
if (close < 0) continue;
|
|
2466
2792
|
const cond = handler.slice(open + 1, close);
|
|
2467
2793
|
if (!/\bCRON_SECRET\b/.test(cond)) continue;
|
|
2794
|
+
if (/CRON_SECRET\s*(?:&&|\?)/.test(cond)) continue;
|
|
2468
2795
|
if (!/(?:!==|!=(?!=))/.test(cond)) continue;
|
|
2469
2796
|
if (!beforeSideEffect(handler, match.index)) continue;
|
|
2470
|
-
const
|
|
2471
|
-
if (
|
|
2472
|
-
if (/\bstatus\s*\(\s*401\b/.test(after)) return true;
|
|
2797
|
+
const body = ifBranchBody(handler, close);
|
|
2798
|
+
if (body && branchRejects401(body)) return true;
|
|
2473
2799
|
}
|
|
2474
2800
|
return false;
|
|
2475
2801
|
}
|
|
2476
|
-
function
|
|
2802
|
+
function handlerVerb(content, index, _handler) {
|
|
2803
|
+
const lineStart = content.lastIndexOf("\n", Math.max(0, index - 1)) + 1;
|
|
2804
|
+
const lineEnd = content.indexOf("\n", Math.max(index, lineStart));
|
|
2805
|
+
const line = content.slice(lineStart, lineEnd === -1 ? content.length : lineEnd);
|
|
2806
|
+
const registered = line.match(/\b[A-Za-z_$][\w$]*\s*\.\s*(get|head|post|put|patch|delete|all)\s*\(\s*["'`]/i);
|
|
2807
|
+
if (registered) return registered[1].toLowerCase();
|
|
2808
|
+
const windowStart = Math.max(0, index - 120);
|
|
2809
|
+
const window = content.slice(windowStart, index + 180);
|
|
2810
|
+
const re = /export\s+(?:async\s+)?function\s+(GET|HEAD|POST|PUT|PATCH|DELETE)\b|export\s+const\s+(GET|HEAD|POST|PUT|PATCH|DELETE)\s*(?::[^=\n]{0,120})?=/g;
|
|
2811
|
+
let best = null;
|
|
2812
|
+
let match;
|
|
2813
|
+
while (match = re.exec(window)) {
|
|
2814
|
+
const at = windowStart + match.index;
|
|
2815
|
+
if (at > index) continue;
|
|
2816
|
+
const verb = (match[1] || match[2]).toLowerCase();
|
|
2817
|
+
if (!best || Math.abs(at - index) < Math.abs(best.at - index)) best = { at, verb };
|
|
2818
|
+
}
|
|
2819
|
+
return best ? best.verb : null;
|
|
2820
|
+
}
|
|
2821
|
+
var authFaultForTest = false;
|
|
2822
|
+
function widenedAuthSuppressesBody(content, filePath, index, handler) {
|
|
2477
2823
|
if (!handler) return false;
|
|
2478
2824
|
const masked = blankComments(content);
|
|
2479
2825
|
const maskedHandler = blankComments(handler);
|
|
2826
|
+
prepareFnCache(masked);
|
|
2480
2827
|
if (guardCallBeforeSideEffect(masked, maskedHandler)) return true;
|
|
2481
2828
|
if (routeArgsQualify(masked, maskedHandler)) return true;
|
|
2482
2829
|
if (useCoversRoute(masked, index)) return true;
|
|
2483
2830
|
const routePath = routePathFromFile(filePath) ?? expressRoutePath(maskedHandler);
|
|
2484
2831
|
if (routePath && isAnchoredPublicAuthPath(routePath) && !mutatesKeyedOnParams(maskedHandler)) return true;
|
|
2485
|
-
if (routePath && isOgRoutePath(routePath))
|
|
2832
|
+
if (routePath && isOgRoutePath(routePath)) {
|
|
2833
|
+
const verb = handlerVerb(masked, index, maskedHandler);
|
|
2834
|
+
if (verb === "get" || verb === "head") return true;
|
|
2835
|
+
}
|
|
2486
2836
|
if (signatureCheckQualifies(maskedHandler)) return true;
|
|
2487
2837
|
if (cronSecretGates(maskedHandler)) return true;
|
|
2488
2838
|
return false;
|
|
2489
2839
|
}
|
|
2840
|
+
function widenedAuthSuppresses(content, filePath, index, handler) {
|
|
2841
|
+
try {
|
|
2842
|
+
if (authFaultForTest) throw new Error("injected");
|
|
2843
|
+
return widenedAuthSuppressesBody(content, filePath, index, handler);
|
|
2844
|
+
} catch {
|
|
2845
|
+
return false;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
// src/weak-hash.ts
|
|
2850
|
+
var ARG_CAP2 = 300;
|
|
2851
|
+
var PF_RE = /password|passwd|passphrase|pwd/;
|
|
2852
|
+
var TOKEN_WORDS = ["token", "code", "otp", "nonce"];
|
|
2853
|
+
var RESET_WORDS = ["reset", "forgot", "recover"];
|
|
2854
|
+
var HASH_VERBS = ["hash", "encrypt", "digest", "verify"];
|
|
2855
|
+
var KEY_BLOCK = ["token", "code", "otp", "nonce", "reset", "forgot", "recover"];
|
|
2856
|
+
function escapeRegExp2(value) {
|
|
2857
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2858
|
+
}
|
|
2859
|
+
function nameTokens(text) {
|
|
2860
|
+
const out = [];
|
|
2861
|
+
for (const part of text.split(/[^A-Za-z0-9]+/)) {
|
|
2862
|
+
if (!part) continue;
|
|
2863
|
+
const bits = part.split(
|
|
2864
|
+
/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[A-Za-z])(?=\d)|(?<=\d)(?=[A-Za-z])/
|
|
2865
|
+
);
|
|
2866
|
+
for (const bit of bits) if (bit) out.push(bit.toLowerCase());
|
|
2867
|
+
const lower = part.toLowerCase();
|
|
2868
|
+
if (PF_RE.test(lower) && !lower.includes("passwordless") && !bits.some((bit) => bit && PF_RE.test(bit.toLowerCase()))) {
|
|
2869
|
+
out.push(lower);
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
return out;
|
|
2873
|
+
}
|
|
2874
|
+
function isPf(token) {
|
|
2875
|
+
return PF_RE.test(token) && !token.includes("passwordless");
|
|
2876
|
+
}
|
|
2877
|
+
function wordIn(tokens, word) {
|
|
2878
|
+
if (tokens.some((token) => token === word)) return true;
|
|
2879
|
+
return tokens.some((token) => isPf(token) && token.includes(word));
|
|
2880
|
+
}
|
|
2881
|
+
function hasPf(text) {
|
|
2882
|
+
return nameTokens(text).some(isPf);
|
|
2883
|
+
}
|
|
2884
|
+
function isTokenValue(expr) {
|
|
2885
|
+
const tokens = nameTokens(expr);
|
|
2886
|
+
const pf = tokens.filter(isPf);
|
|
2887
|
+
if (pf.some((token) => !TOKEN_WORDS.some((word) => token.includes(word)))) return false;
|
|
2888
|
+
if (TOKEN_WORDS.some((word) => tokens.includes(word))) return true;
|
|
2889
|
+
return TOKEN_WORDS.some((word) => wordIn(tokens, word));
|
|
2890
|
+
}
|
|
2891
|
+
function blocked(text, words) {
|
|
2892
|
+
const tokens = nameTokens(text);
|
|
2893
|
+
return words.some((word) => wordIn(tokens, word));
|
|
2894
|
+
}
|
|
2895
|
+
function namedHasher(name, expr) {
|
|
2896
|
+
if (!hasPf(name)) return false;
|
|
2897
|
+
if (blocked(name, RESET_WORDS) && isTokenValue(expr)) return false;
|
|
2898
|
+
return true;
|
|
2899
|
+
}
|
|
2900
|
+
function hasHashVerb(name) {
|
|
2901
|
+
const tokens = nameTokens(name);
|
|
2902
|
+
return HASH_VERBS.some((word) => wordIn(tokens, word));
|
|
2903
|
+
}
|
|
2904
|
+
function perCallKeeps(name, expr) {
|
|
2905
|
+
if (isTokenValue(expr)) return namedHasher(name, expr) && hasHashVerb(name);
|
|
2906
|
+
return hasPf(expr) || namedHasher(name, expr);
|
|
2907
|
+
}
|
|
2908
|
+
function hashedExprAt(content, index) {
|
|
2909
|
+
const slice = content.slice(index, index + ARG_CAP2);
|
|
2910
|
+
const updateAt = slice.search(/\.update\s*\(/);
|
|
2911
|
+
if (updateAt >= 0) {
|
|
2912
|
+
const open = index + slice.indexOf("(", updateAt);
|
|
2913
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
2914
|
+
return close < 0 ? "" : content.slice(open + 1, close);
|
|
2915
|
+
}
|
|
2916
|
+
const libAt = slice.search(/hashlib\s*\.\s*(?:md5|sha1|sha256)\s*\(/);
|
|
2917
|
+
if (libAt >= 0) {
|
|
2918
|
+
const open = index + slice.indexOf("(", libAt);
|
|
2919
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
2920
|
+
return close < 0 ? "" : content.slice(open + 1, close);
|
|
2921
|
+
}
|
|
2922
|
+
return slice.slice(0, 160);
|
|
2923
|
+
}
|
|
2924
|
+
var METHOD_RE = /^\s*(?:(?:public|private|protected|static|async|override)\s+)*([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*(?::\s*[^{]+)?$/;
|
|
2925
|
+
var METHOD_SKIP = /* @__PURE__ */ new Set(["if", "for", "while", "switch", "catch", "function", "return"]);
|
|
2926
|
+
function methodHeaderName(header) {
|
|
2927
|
+
const last = header.slice(header.lastIndexOf("\n") + 1);
|
|
2928
|
+
const method = METHOD_RE.exec(last);
|
|
2929
|
+
if (!method || METHOD_SKIP.has(method[1])) return "";
|
|
2930
|
+
return method[1];
|
|
2931
|
+
}
|
|
2932
|
+
var memo = null;
|
|
2933
|
+
var helperFault = false;
|
|
2934
|
+
function lineStartsOf(content) {
|
|
2935
|
+
const starts = [0];
|
|
2936
|
+
for (let i = 0; i < content.length; i++) if (content[i] === "\n") starts.push(i + 1);
|
|
2937
|
+
return starts;
|
|
2938
|
+
}
|
|
2939
|
+
function lineNoAt(content, index) {
|
|
2940
|
+
const starts = memo && memo.content === content ? memo.lineStarts : lineStartsOf(content);
|
|
2941
|
+
let lo = 0;
|
|
2942
|
+
let hi = starts.length - 1;
|
|
2943
|
+
while (lo < hi) {
|
|
2944
|
+
const mid = lo + hi + 1 >> 1;
|
|
2945
|
+
if (starts[mid] <= index) lo = mid;
|
|
2946
|
+
else hi = mid - 1;
|
|
2947
|
+
}
|
|
2948
|
+
return lo + 1;
|
|
2949
|
+
}
|
|
2950
|
+
function maskCallSites(content, py) {
|
|
2951
|
+
const chars = content.split("");
|
|
2952
|
+
let i = 0;
|
|
2953
|
+
const blankUntil = (pred) => {
|
|
2954
|
+
while (i < chars.length && !pred(i)) {
|
|
2955
|
+
if (chars[i] !== "\n") chars[i] = " ";
|
|
2956
|
+
i++;
|
|
2957
|
+
}
|
|
2958
|
+
};
|
|
2959
|
+
while (i < chars.length) {
|
|
2960
|
+
const c = chars[i];
|
|
2961
|
+
if (!py && c === "/" && chars[i + 1] === "/") {
|
|
2962
|
+
while (i < chars.length && chars[i] !== "\n") {
|
|
2963
|
+
chars[i] = " ";
|
|
2964
|
+
i++;
|
|
2965
|
+
}
|
|
2966
|
+
continue;
|
|
2967
|
+
}
|
|
2968
|
+
if (!py && c === "/" && chars[i + 1] === "*") {
|
|
2969
|
+
chars[i] = " ";
|
|
2970
|
+
chars[i + 1] = " ";
|
|
2971
|
+
i += 2;
|
|
2972
|
+
blankUntil((n) => chars[n] === "*" && chars[n + 1] === "/");
|
|
2973
|
+
if (i < chars.length) {
|
|
2974
|
+
chars[i] = " ";
|
|
2975
|
+
chars[i + 1] = " ";
|
|
2976
|
+
i += 2;
|
|
2977
|
+
}
|
|
2978
|
+
continue;
|
|
2979
|
+
}
|
|
2980
|
+
if (py && c === "#") {
|
|
2981
|
+
while (i < chars.length && chars[i] !== "\n") {
|
|
2982
|
+
chars[i] = " ";
|
|
2983
|
+
i++;
|
|
2984
|
+
}
|
|
2985
|
+
continue;
|
|
2986
|
+
}
|
|
2987
|
+
if ((c === '"' || c === "'") && chars[i + 1] === c && chars[i + 2] === c) {
|
|
2988
|
+
const q = c;
|
|
2989
|
+
chars[i] = chars[i + 1] = chars[i + 2] = " ";
|
|
2990
|
+
i += 3;
|
|
2991
|
+
blankUntil((n) => chars[n] === q && chars[n + 1] === q && chars[n + 2] === q);
|
|
2992
|
+
if (i < chars.length) {
|
|
2993
|
+
chars[i] = chars[i + 1] = chars[i + 2] = " ";
|
|
2994
|
+
i += 3;
|
|
2995
|
+
}
|
|
2996
|
+
continue;
|
|
2997
|
+
}
|
|
2998
|
+
if (c === "'" || c === '"') {
|
|
2999
|
+
const q = c;
|
|
3000
|
+
chars[i] = " ";
|
|
3001
|
+
i++;
|
|
3002
|
+
while (i < chars.length) {
|
|
3003
|
+
if (chars[i] === "\\") {
|
|
3004
|
+
chars[i] = " ";
|
|
3005
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
3006
|
+
i += 2;
|
|
3007
|
+
continue;
|
|
3008
|
+
}
|
|
3009
|
+
if (chars[i] === "\n") break;
|
|
3010
|
+
if (chars[i] === q) {
|
|
3011
|
+
chars[i] = " ";
|
|
3012
|
+
i++;
|
|
3013
|
+
break;
|
|
3014
|
+
}
|
|
3015
|
+
chars[i] = " ";
|
|
3016
|
+
i++;
|
|
3017
|
+
}
|
|
3018
|
+
continue;
|
|
3019
|
+
}
|
|
3020
|
+
if (c === "`") {
|
|
3021
|
+
chars[i] = " ";
|
|
3022
|
+
i++;
|
|
3023
|
+
let expr = 0;
|
|
3024
|
+
while (i < chars.length) {
|
|
3025
|
+
if (expr === 0 && chars[i] === "\\") {
|
|
3026
|
+
chars[i] = " ";
|
|
3027
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
3028
|
+
i += 2;
|
|
3029
|
+
continue;
|
|
3030
|
+
}
|
|
3031
|
+
if (expr === 0 && chars[i] === "`") {
|
|
3032
|
+
chars[i] = " ";
|
|
3033
|
+
i++;
|
|
3034
|
+
break;
|
|
3035
|
+
}
|
|
3036
|
+
if (expr === 0 && chars[i] === "$" && chars[i + 1] === "{") {
|
|
3037
|
+
chars[i] = " ";
|
|
3038
|
+
chars[i + 1] = " ";
|
|
3039
|
+
expr = 1;
|
|
3040
|
+
i += 2;
|
|
3041
|
+
continue;
|
|
3042
|
+
}
|
|
3043
|
+
if (expr > 0) {
|
|
3044
|
+
if (chars[i] === "{") expr++;
|
|
3045
|
+
else if (chars[i] === "}") expr--;
|
|
3046
|
+
i++;
|
|
3047
|
+
continue;
|
|
3048
|
+
}
|
|
3049
|
+
if (chars[i] !== "\n") chars[i] = " ";
|
|
3050
|
+
i++;
|
|
3051
|
+
}
|
|
3052
|
+
continue;
|
|
3053
|
+
}
|
|
3054
|
+
i++;
|
|
3055
|
+
}
|
|
3056
|
+
return chars.join("");
|
|
3057
|
+
}
|
|
3058
|
+
function remember(content, filePath) {
|
|
3059
|
+
const py = filePath.endsWith(".py");
|
|
3060
|
+
if (memo && memo.content === content && memo.py === py) return memo;
|
|
3061
|
+
memo = {
|
|
3062
|
+
content,
|
|
3063
|
+
py,
|
|
3064
|
+
masked: maskCallSites(content, py),
|
|
3065
|
+
lineStarts: lineStartsOf(content)
|
|
3066
|
+
};
|
|
3067
|
+
return memo;
|
|
3068
|
+
}
|
|
3069
|
+
function argIsParam(expr, param) {
|
|
3070
|
+
const trimmed = expr.trim();
|
|
3071
|
+
const id = escapeRegExp2(param);
|
|
3072
|
+
return new RegExp(`^${id}$`).test(trimmed) || new RegExp(`^String\\(${id}\\)$`).test(trimmed) || new RegExp(`^Buffer\\.from\\(${id}\\)$`).test(trimmed) || new RegExp(`^${id}\\.encode\\([\\s\\S]*\\)$`).test(trimmed);
|
|
3073
|
+
}
|
|
3074
|
+
function argumentOf(content, chain, base) {
|
|
3075
|
+
const update = /createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\s*\)/.exec(chain);
|
|
3076
|
+
if (update) {
|
|
3077
|
+
const after = chain.slice(update.index + update[0].length);
|
|
3078
|
+
const upd = /\.update\s*\(/.exec(after);
|
|
3079
|
+
if (!upd) return null;
|
|
3080
|
+
const open2 = base + update.index + update[0].length + upd.index + upd[0].lastIndexOf("(");
|
|
3081
|
+
const close2 = matchingCloser(content, open2, "(", ")", ARG_CAP2);
|
|
3082
|
+
if (close2 < 0) return null;
|
|
3083
|
+
return { expr: content.slice(open2 + 1, close2), at: base + update.index };
|
|
3084
|
+
}
|
|
3085
|
+
const lib = /hashlib\s*\.\s*(?:md5|sha1|sha256)\s*\(/.exec(chain);
|
|
3086
|
+
if (!lib) return null;
|
|
3087
|
+
const open = base + lib.index + lib[0].lastIndexOf("(");
|
|
3088
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
3089
|
+
if (close < 0) return null;
|
|
3090
|
+
return { expr: content.slice(open + 1, close), at: base + lib.index };
|
|
3091
|
+
}
|
|
3092
|
+
function onlyReturn(body) {
|
|
3093
|
+
const lines = body.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
3094
|
+
if (lines.length !== 1) return null;
|
|
3095
|
+
const match = /^return\s+([\s\S]+?);?$/.exec(lines[0]);
|
|
3096
|
+
return match ? match[1].replace(/;$/, "").trim() : null;
|
|
3097
|
+
}
|
|
3098
|
+
function qualifyingHelpers(content) {
|
|
3099
|
+
const found = [];
|
|
3100
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3101
|
+
const note = (name) => counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
3102
|
+
const arrow = /(?:^|[\n;])\s*(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s+)?(?:\(\s*([A-Za-z_$][\w$]*)\s*(?::\s*[^)=]+)?\s*\)|([A-Za-z_$][\w$]*))\s*=>/g;
|
|
3103
|
+
let match;
|
|
3104
|
+
while (match = arrow.exec(content)) {
|
|
3105
|
+
const name = match[1];
|
|
3106
|
+
const param = match[2] || match[3];
|
|
3107
|
+
note(name);
|
|
3108
|
+
if (!param) continue;
|
|
3109
|
+
const at = match.index + match[0].length;
|
|
3110
|
+
const rest = content.slice(at);
|
|
3111
|
+
let chain = "";
|
|
3112
|
+
let base = at;
|
|
3113
|
+
if (/^\s*\{/.test(rest)) {
|
|
3114
|
+
const brace = content.indexOf("{", at);
|
|
3115
|
+
const end = matchingCloser(content, brace, "{", "}", 2e4);
|
|
3116
|
+
if (end < 0) continue;
|
|
3117
|
+
const body = onlyReturn(content.slice(brace + 1, end));
|
|
3118
|
+
if (body === null) continue;
|
|
3119
|
+
chain = body;
|
|
3120
|
+
base = brace + 1 + content.slice(brace + 1, end).indexOf(body);
|
|
3121
|
+
} else {
|
|
3122
|
+
const lineEnd = content.indexOf("\n", at);
|
|
3123
|
+
const semi = content.indexOf(";", at);
|
|
3124
|
+
let stop = lineEnd < 0 ? content.length : lineEnd;
|
|
3125
|
+
if (semi >= 0 && semi < stop) stop = semi;
|
|
3126
|
+
chain = content.slice(at, stop);
|
|
3127
|
+
base = at;
|
|
3128
|
+
}
|
|
3129
|
+
const hashed = argumentOf(content, chain, base);
|
|
3130
|
+
if (hashed && argIsParam(hashed.expr, param)) found.push({ name, at: hashed.at });
|
|
3131
|
+
}
|
|
3132
|
+
const fn = /(?:^|[\n;])\s*(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(\s*([A-Za-z_$][\w$]*)\s*(?::\s*[^)=]+)?\s*\)\s*\{/g;
|
|
3133
|
+
while (match = fn.exec(content)) {
|
|
3134
|
+
const name = match[1];
|
|
3135
|
+
const param = match[2];
|
|
3136
|
+
note(name);
|
|
3137
|
+
const brace = content.indexOf("{", match.index);
|
|
3138
|
+
const end = matchingCloser(content, brace, "{", "}", 2e4);
|
|
3139
|
+
if (end < 0) continue;
|
|
3140
|
+
const body = onlyReturn(content.slice(brace + 1, end));
|
|
3141
|
+
if (body === null) continue;
|
|
3142
|
+
const base = brace + 1 + content.slice(brace + 1, end).indexOf(body);
|
|
3143
|
+
const hashed = argumentOf(content, body, base);
|
|
3144
|
+
if (hashed && argIsParam(hashed.expr, param)) found.push({ name, at: hashed.at });
|
|
3145
|
+
}
|
|
3146
|
+
const lines = content.split("\n");
|
|
3147
|
+
let offset = 0;
|
|
3148
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3149
|
+
const line = lines[i];
|
|
3150
|
+
const same = /^(\s*)def\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)\s*:\s*return\s+(.+)$/.exec(line);
|
|
3151
|
+
if (same) {
|
|
3152
|
+
note(same[2]);
|
|
3153
|
+
const chainAt = offset + line.indexOf(same[4]);
|
|
3154
|
+
const hashed = argumentOf(content, same[4], chainAt);
|
|
3155
|
+
if (hashed && argIsParam(hashed.expr, same[3])) found.push({ name: same[2], at: hashed.at });
|
|
3156
|
+
} else {
|
|
3157
|
+
const head = /^(\s*)def\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)\s*:\s*$/.exec(line);
|
|
3158
|
+
if (head) {
|
|
3159
|
+
note(head[2]);
|
|
3160
|
+
const next = lines[i + 1] ?? "";
|
|
3161
|
+
const body = /^(\s+)return\s+(.+)$/.exec(next);
|
|
3162
|
+
if (body && body[1].length > head[1].length) {
|
|
3163
|
+
let more = false;
|
|
3164
|
+
for (let j = i + 2; j < lines.length; j++) {
|
|
3165
|
+
if (!lines[j].trim()) continue;
|
|
3166
|
+
const ind = /^[ \t]*/.exec(lines[j])?.[0].length ?? 0;
|
|
3167
|
+
if (ind > head[1].length) more = true;
|
|
3168
|
+
break;
|
|
3169
|
+
}
|
|
3170
|
+
if (!more) {
|
|
3171
|
+
const chainAt = offset + line.length + 1 + next.indexOf(body[2]);
|
|
3172
|
+
const hashed = argumentOf(content, body[2], chainAt);
|
|
3173
|
+
if (hashed && argIsParam(hashed.expr, head[3])) found.push({ name: head[2], at: hashed.at });
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
offset += line.length + 1;
|
|
3179
|
+
}
|
|
3180
|
+
const good = /* @__PURE__ */ new Map();
|
|
3181
|
+
for (const helper of found) good.set(helper.name, (good.get(helper.name) ?? 0) + 1);
|
|
3182
|
+
const kept = /* @__PURE__ */ new Set();
|
|
3183
|
+
for (const [name, count] of counts) {
|
|
3184
|
+
if (good.get(name) === count) kept.add(name);
|
|
3185
|
+
}
|
|
3186
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3187
|
+
return found.filter((helper) => {
|
|
3188
|
+
if (!kept.has(helper.name) || seen.has(helper.name)) return false;
|
|
3189
|
+
seen.add(helper.name);
|
|
3190
|
+
return true;
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
function hasConditionalQuestion(window) {
|
|
3194
|
+
let depth = 0;
|
|
3195
|
+
let quote = "";
|
|
3196
|
+
let open = false;
|
|
3197
|
+
for (let i = 0; i < window.length; i++) {
|
|
3198
|
+
const c = window[i];
|
|
3199
|
+
if (quote) {
|
|
3200
|
+
if (c === "\\") {
|
|
3201
|
+
i++;
|
|
3202
|
+
continue;
|
|
3203
|
+
}
|
|
3204
|
+
if (c === quote) quote = "";
|
|
3205
|
+
continue;
|
|
3206
|
+
}
|
|
3207
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
3208
|
+
quote = c;
|
|
3209
|
+
continue;
|
|
3210
|
+
}
|
|
3211
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
3212
|
+
else if (c === ")" || c === "]" || c === "}") depth = Math.max(0, depth - 1);
|
|
3213
|
+
else if (depth === 0 && (c === ";" || c === "\n")) open = false;
|
|
3214
|
+
else if (c === "?" && depth === 0 && window[i + 1] !== "?" && window[i + 1] !== "." && window[i - 1] !== "?") {
|
|
3215
|
+
open = true;
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
return open;
|
|
3219
|
+
}
|
|
3220
|
+
function rawNames(content, callIndex) {
|
|
3221
|
+
const start = Math.max(0, callIndex - 200);
|
|
3222
|
+
const slice = content.slice(start, callIndex);
|
|
3223
|
+
const nl = slice.lastIndexOf("\n");
|
|
3224
|
+
const window = nl < 0 ? slice : slice.slice(nl + 1);
|
|
3225
|
+
const names = [];
|
|
3226
|
+
if (!hasConditionalQuestion(window)) {
|
|
3227
|
+
const key = /(["']?)([A-Za-z_$][\w$]*)\1\s*:\s*$/.exec(window);
|
|
3228
|
+
if (key) names.push(key[2]);
|
|
3229
|
+
}
|
|
3230
|
+
const assigned = /([A-Za-z_$][\w$.]*)(?:\s*:\s*[^=]{1,80}?)?\s*=\s*$/.exec(window);
|
|
3231
|
+
if (assigned) names.push(assigned[1]);
|
|
3232
|
+
const sub = /\[\s*(["'])([A-Za-z_$][\w$]*)\1\s*\]\s*=\s*$/.exec(window);
|
|
3233
|
+
if (sub) names.push(sub[2]);
|
|
3234
|
+
return names;
|
|
3235
|
+
}
|
|
3236
|
+
function firstArg(content, open) {
|
|
3237
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
3238
|
+
if (close < 0) return null;
|
|
3239
|
+
let depth = 0;
|
|
3240
|
+
let quote = "";
|
|
3241
|
+
for (let i = open + 1; i < close; i++) {
|
|
3242
|
+
const c = content[i];
|
|
3243
|
+
if (quote) {
|
|
3244
|
+
if (c === "\\") {
|
|
3245
|
+
i++;
|
|
3246
|
+
continue;
|
|
3247
|
+
}
|
|
3248
|
+
if (c === quote) quote = "";
|
|
3249
|
+
continue;
|
|
3250
|
+
}
|
|
3251
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
3252
|
+
quote = c;
|
|
3253
|
+
continue;
|
|
3254
|
+
}
|
|
3255
|
+
if (c === "(" || c === "{" || c === "[") depth++;
|
|
3256
|
+
else if (c === ")" || c === "}" || c === "]") depth--;
|
|
3257
|
+
else if (c === "," && depth === 0) return content.slice(open + 1, i);
|
|
3258
|
+
}
|
|
3259
|
+
return content.slice(open + 1, close);
|
|
3260
|
+
}
|
|
3261
|
+
function callQualifies(content, masked, name) {
|
|
3262
|
+
const re = new RegExp(`(?<![\\w$.])${escapeRegExp2(name)}\\(`, "g");
|
|
3263
|
+
let match;
|
|
3264
|
+
while (match = re.exec(masked)) {
|
|
3265
|
+
const before = masked.slice(Math.max(0, match.index - 24), match.index);
|
|
3266
|
+
if (/\b(?:function|def)\s+$/.test(before)) continue;
|
|
3267
|
+
if (/\b(?:const|let|var)\s+$/.test(before)) continue;
|
|
3268
|
+
const arg = firstArg(masked, match.index + name.length);
|
|
3269
|
+
if (arg === null) continue;
|
|
3270
|
+
const names = rawNames(content, match.index);
|
|
3271
|
+
const argOk = hasPf(arg) && !blocked(arg, TOKEN_WORDS);
|
|
3272
|
+
const nameOk = names.some((label) => hasPf(label) && !blocked(label, KEY_BLOCK));
|
|
3273
|
+
if (argOk || nameOk) return true;
|
|
3274
|
+
}
|
|
3275
|
+
return false;
|
|
3276
|
+
}
|
|
3277
|
+
function helperWeakIndexes(content, filePath) {
|
|
3278
|
+
try {
|
|
3279
|
+
if (helperFault) throw new Error("injected");
|
|
3280
|
+
const slot = remember(content, filePath);
|
|
3281
|
+
const helpers = qualifyingHelpers(content);
|
|
3282
|
+
const indexes = [];
|
|
3283
|
+
for (const helper of helpers) {
|
|
3284
|
+
if (callQualifies(content, slot.masked, helper.name)) indexes.push(helper.at);
|
|
3285
|
+
}
|
|
3286
|
+
return indexes;
|
|
3287
|
+
} catch {
|
|
3288
|
+
remember(content, filePath);
|
|
3289
|
+
return [];
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
function pythonDefs(content) {
|
|
3293
|
+
const defs = [];
|
|
3294
|
+
const re = /^([ \t]*)def\s+([A-Za-z_]\w*)\s*\(/gm;
|
|
3295
|
+
let match;
|
|
3296
|
+
while (match = re.exec(content)) {
|
|
3297
|
+
defs.push({ name: match[2], indent: match[1].length, at: match.index });
|
|
3298
|
+
}
|
|
3299
|
+
return defs;
|
|
3300
|
+
}
|
|
3301
|
+
function pythonDefName(content, index, defs) {
|
|
3302
|
+
const lineStart = content.lastIndexOf("\n", Math.max(0, index - 1)) + 1;
|
|
3303
|
+
const indent = /^[ \t]*/.exec(content.slice(lineStart))?.[0].length ?? 0;
|
|
3304
|
+
let name = "";
|
|
3305
|
+
let defIndent = -1;
|
|
3306
|
+
for (const def of defs) {
|
|
3307
|
+
if (def.at >= index) break;
|
|
3308
|
+
name = def.name;
|
|
3309
|
+
defIndent = def.indent;
|
|
3310
|
+
}
|
|
3311
|
+
return name && indent > defIndent ? name : "";
|
|
3312
|
+
}
|
|
2490
3313
|
|
|
2491
3314
|
// src/public-env.ts
|
|
2492
3315
|
var PUBLIC_ENV_PREFIX_RE = /^(?:NEXT_PUBLIC_|NUXT_PUBLIC_|EXPO_PUBLIC_|REACT_APP_|GATSBY_|VITE_|PUBLIC_)/i;
|
|
@@ -4339,10 +5162,10 @@ function unauthenticatedTanStackHandlers(masked, filePath) {
|
|
|
4339
5162
|
return hasAuthMiddleware(handlersAt === -1 ? block : block.slice(0, handlersAt));
|
|
4340
5163
|
})();
|
|
4341
5164
|
if (!routeLevelAuth) {
|
|
4342
|
-
const
|
|
5165
|
+
const METHOD_RE2 = /\b(GET|POST|PUT|PATCH|DELETE)\s*:\s*(?:async\s+)?(?:\(|function\b|\{|[A-Za-z_$][\w$]{0,40}\s*=>)/g;
|
|
4343
5166
|
const methodStarts = [];
|
|
4344
5167
|
let m;
|
|
4345
|
-
while ((m =
|
|
5168
|
+
while ((m = METHOD_RE2.exec(masked)) !== null && methodStarts.length < 200) methodStarts.push(m.index);
|
|
4346
5169
|
for (let k = 0; k < methodStarts.length; k++) {
|
|
4347
5170
|
const start = methodStarts[k];
|
|
4348
5171
|
const limit = k + 1 < methodStarts.length ? methodStarts[k + 1] : Math.min(masked.length, start + 4e4);
|
|
@@ -5873,8 +6696,8 @@ var weakHashing = {
|
|
|
5873
6696
|
() => "Use bcrypt, scrypt, or argon2 for password hashing \u2014 they're intentionally slow. Example: const hash = await bcrypt.hash(password, 12);"
|
|
5874
6697
|
));
|
|
5875
6698
|
}
|
|
5876
|
-
const
|
|
5877
|
-
const
|
|
6699
|
+
const defs = pythonDefs(content);
|
|
6700
|
+
const nameAt = /* @__PURE__ */ new Map();
|
|
5878
6701
|
const weakCallPatterns = [
|
|
5879
6702
|
/createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\s*\)/gi,
|
|
5880
6703
|
/hashlib\.(?:md5|sha1|sha256)\s*\(/gi,
|
|
@@ -5889,58 +6712,49 @@ var weakHashing = {
|
|
|
5889
6712
|
}
|
|
5890
6713
|
return at;
|
|
5891
6714
|
};
|
|
5892
|
-
const hashedExpr = (index) => {
|
|
5893
|
-
const slice = content.slice(index, index + 300);
|
|
5894
|
-
const update = slice.match(/\.update\s*\(\s*([^)]{0,200})\)/);
|
|
5895
|
-
if (update) return update[1];
|
|
5896
|
-
const lib = slice.match(/hashlib\s*\.\s*(?:md5|sha1|sha256)\s*\(\s*([^)]{0,200})\)/);
|
|
5897
|
-
if (lib) return lib[1];
|
|
5898
|
-
return slice.slice(0, 160);
|
|
5899
|
-
};
|
|
5900
|
-
const tokenValue = (expr) => {
|
|
5901
|
-
if (passwordValue.test(expr)) return false;
|
|
5902
|
-
return /token|otp|(?:^|[^A-Za-z])code(?:[^A-Za-z]|$)/i.test(expr);
|
|
5903
|
-
};
|
|
5904
6715
|
const braceEnclosingName = (index) => {
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
6716
|
+
const cached = nameAt.get(index);
|
|
6717
|
+
if (cached !== void 0) return cached;
|
|
6718
|
+
let name = "";
|
|
6719
|
+
try {
|
|
6720
|
+
let searchFrom = index;
|
|
6721
|
+
for (let level = 0; level < 8 && index - searchFrom < 2e4; level++) {
|
|
6722
|
+
let depth = 0;
|
|
6723
|
+
let open = -1;
|
|
6724
|
+
const limit = Math.max(0, index - 2e4);
|
|
6725
|
+
for (let i = searchFrom; i >= limit; i--) {
|
|
6726
|
+
const c = content[i];
|
|
6727
|
+
if (c === "}") depth++;
|
|
6728
|
+
else if (c === "{") {
|
|
6729
|
+
if (depth === 0) {
|
|
6730
|
+
open = i;
|
|
6731
|
+
break;
|
|
6732
|
+
}
|
|
6733
|
+
depth--;
|
|
5916
6734
|
}
|
|
5917
|
-
depth--;
|
|
5918
6735
|
}
|
|
6736
|
+
if (open < 0) break;
|
|
6737
|
+
const header = content.slice(Math.max(0, open - 180), open);
|
|
6738
|
+
const named = /(?:function|def)\s+([A-Za-z_]\w*)\s*\([^)]*\)\s*$/.exec(header) || /(?:const|let|var)\s+([A-Za-z_]\w*)\s*=\s*(?:async\s*)?(?:function\b|\([^)]*\)\s*=>|[A-Za-z_]\w*\s*=>)\s*$/.exec(header);
|
|
6739
|
+
if (named?.[1]) {
|
|
6740
|
+
name = named[1];
|
|
6741
|
+
break;
|
|
6742
|
+
}
|
|
6743
|
+
const method = methodHeaderName(header);
|
|
6744
|
+
if (method) {
|
|
6745
|
+
name = method;
|
|
6746
|
+
break;
|
|
6747
|
+
}
|
|
6748
|
+
searchFrom = open - 1;
|
|
5919
6749
|
}
|
|
5920
|
-
if (
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
if (named?.[1]) return named[1];
|
|
5924
|
-
searchFrom = open - 1;
|
|
5925
|
-
}
|
|
5926
|
-
return "";
|
|
5927
|
-
};
|
|
5928
|
-
const pythonDefName = (index) => {
|
|
5929
|
-
const lineStart = content.lastIndexOf("\n", Math.max(0, index - 1)) + 1;
|
|
5930
|
-
const indent = /^[ \t]*/.exec(content.slice(lineStart))?.[0].length ?? 0;
|
|
5931
|
-
const re = /^([ \t]*)def\s+([A-Za-z_]\w*)\s*\(/gm;
|
|
5932
|
-
re.lastIndex = 0;
|
|
5933
|
-
const before = content.slice(0, index);
|
|
5934
|
-
let name = "";
|
|
5935
|
-
let defIndent = -1;
|
|
5936
|
-
let found;
|
|
5937
|
-
while (found = re.exec(before)) {
|
|
5938
|
-
name = found[2];
|
|
5939
|
-
defIndent = found[1].length;
|
|
6750
|
+
if (!name) name = pythonDefName(content, index, defs);
|
|
6751
|
+
} catch {
|
|
6752
|
+
name = "";
|
|
5940
6753
|
}
|
|
5941
|
-
|
|
6754
|
+
nameAt.set(index, name);
|
|
6755
|
+
return name;
|
|
5942
6756
|
};
|
|
5943
|
-
const
|
|
6757
|
+
const rawHits = [];
|
|
5944
6758
|
for (const p of weakCallPatterns) {
|
|
5945
6759
|
const raw = findMatches(
|
|
5946
6760
|
content,
|
|
@@ -5949,16 +6763,22 @@ var weakHashing = {
|
|
|
5949
6763
|
filePath,
|
|
5950
6764
|
() => "Use bcrypt, scrypt, or argon2 for password hashing. These algorithms are intentionally slow so brute-force attacks are infeasible."
|
|
5951
6765
|
);
|
|
6766
|
+
rawHits.push(...raw);
|
|
5952
6767
|
for (const m of raw) {
|
|
5953
6768
|
if (matches.some((existing) => existing.line === m.line)) continue;
|
|
5954
6769
|
const lineStart = indexOfLineNo(m.line);
|
|
5955
|
-
const expr =
|
|
5956
|
-
const name =
|
|
5957
|
-
|
|
5958
|
-
if (!passwordValue.test(expr) && !namedHasher) continue;
|
|
6770
|
+
const expr = hashedExprAt(content, lineStart);
|
|
6771
|
+
const name = braceEnclosingName(lineStart);
|
|
6772
|
+
if (!perCallKeeps(name, expr)) continue;
|
|
5959
6773
|
matches.push(m);
|
|
5960
6774
|
}
|
|
5961
6775
|
}
|
|
6776
|
+
for (const at of helperWeakIndexes(content, filePath)) {
|
|
6777
|
+
const line = lineNoAt(content, at);
|
|
6778
|
+
if (matches.some((existing) => existing.line === line)) continue;
|
|
6779
|
+
const hit = rawHits.find((m) => m.line === line);
|
|
6780
|
+
if (hit) matches.push(hit);
|
|
6781
|
+
}
|
|
5962
6782
|
return matches;
|
|
5963
6783
|
}
|
|
5964
6784
|
};
|