xploitscan-shared-rules 2.4.24 → 2.4.26
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 +2907 -443
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2899 -443
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -76,6 +76,7 @@ __export(index_exports, {
|
|
|
76
76
|
attachInlineSuppressed: () => attachInlineSuppressed,
|
|
77
77
|
attachScanSuppression: () => attachScanSuppression,
|
|
78
78
|
authPrefixCovers: () => authPrefixCovers,
|
|
79
|
+
bearerProvenanceSafe: () => bearerProvenanceSafe,
|
|
79
80
|
billingWebhookUnmatchedProps: () => billingWebhookUnmatchedProps,
|
|
80
81
|
bucketFiles: () => bucketFiles,
|
|
81
82
|
buildMarkerIndex: () => buildMarkerIndex,
|
|
@@ -86,6 +87,7 @@ __export(index_exports, {
|
|
|
86
87
|
calculateGrade: () => calculateGrade,
|
|
87
88
|
callSpreads: () => callSpreads,
|
|
88
89
|
capWarnings: () => capWarnings,
|
|
90
|
+
capabilityTokenHandler: () => capabilityTokenHandler,
|
|
89
91
|
checkIntent: () => checkIntent,
|
|
90
92
|
clampCount: () => clampCount,
|
|
91
93
|
classifyExposure: () => classifyExposure,
|
|
@@ -180,11 +182,15 @@ __export(index_exports, {
|
|
|
180
182
|
parseSupabaseConfig: () => parseSupabaseConfig,
|
|
181
183
|
perCallTimeoutMs: () => perCallTimeoutMs,
|
|
182
184
|
planCause: () => planCause,
|
|
185
|
+
publicHttpsUrl: () => publicHttpsUrl,
|
|
186
|
+
publicReadOnlyHandler: () => publicReadOnlyHandler,
|
|
183
187
|
publicSuppressedRecord: () => publicSuppressedRecord,
|
|
184
188
|
qualityRules: () => qualityRules,
|
|
185
189
|
readInlineSuppressed: () => readInlineSuppressed,
|
|
186
190
|
readScanSuppression: () => readScanSuppression,
|
|
191
|
+
refineDirectObjectFindings: () => refineDirectObjectFindings,
|
|
187
192
|
replaceBlockComments: () => replaceBlockComments,
|
|
193
|
+
resetStructuralState: () => resetStructuralState,
|
|
188
194
|
routeForFile: () => routeForFile,
|
|
189
195
|
routePathFromFile: () => routePathFromFile,
|
|
190
196
|
runCustomRules: () => runCustomRules,
|
|
@@ -195,8 +201,10 @@ __export(index_exports, {
|
|
|
195
201
|
scanMultiFile: () => scanMultiFile,
|
|
196
202
|
scanQuality: () => scanQuality,
|
|
197
203
|
scanTokenNullProps: () => scanTokenNullProps,
|
|
204
|
+
setStructuralFaultForTest: () => setStructuralFaultForTest,
|
|
198
205
|
sqlInjection: () => sqlInjection,
|
|
199
206
|
stripeWebhookUnprotected: () => stripeWebhookUnprotected,
|
|
207
|
+
structuralParseCount: () => structuralParseCount,
|
|
200
208
|
supabaseFunctionName: () => supabaseFunctionName,
|
|
201
209
|
supabaseNoRLS: () => supabaseNoRLS,
|
|
202
210
|
suppressionSummary: () => suppressionSummary,
|
|
@@ -219,7 +227,7 @@ __export(index_exports, {
|
|
|
219
227
|
module.exports = __toCommonJS(index_exports);
|
|
220
228
|
|
|
221
229
|
// src/version.ts
|
|
222
|
-
var SCANNER_VERSION = "2.4.
|
|
230
|
+
var SCANNER_VERSION = "2.4.26";
|
|
223
231
|
|
|
224
232
|
// src/snippet.ts
|
|
225
233
|
var cacheContent = null;
|
|
@@ -2159,230 +2167,2774 @@ function checkIntent(files, findings) {
|
|
|
2159
2167
|
return { statements, mismatches, sources, unchallenged, uncheckable };
|
|
2160
2168
|
}
|
|
2161
2169
|
|
|
2162
|
-
// src/
|
|
2163
|
-
var
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2170
|
+
// src/structural-handlers.ts
|
|
2171
|
+
var import_traverse = __toESM(require("@babel/traverse"), 1);
|
|
2172
|
+
|
|
2173
|
+
// src/ast/parse.ts
|
|
2174
|
+
var import_parser = require("@babel/parser");
|
|
2175
|
+
var MAX_CACHE = 256;
|
|
2176
|
+
var cache = /* @__PURE__ */ new Map();
|
|
2177
|
+
function cacheKey(filename, digest2) {
|
|
2178
|
+
return `${filename}:${digest2}`;
|
|
2179
|
+
}
|
|
2180
|
+
function fullDigest(s) {
|
|
2181
|
+
let h1 = 5381;
|
|
2182
|
+
let h2 = 52711;
|
|
2183
|
+
for (let i = 0; i < s.length; i++) {
|
|
2184
|
+
const c = s.charCodeAt(i);
|
|
2185
|
+
h1 = Math.imul(h1, 33) + c | 0;
|
|
2186
|
+
h2 = Math.imul(h2, 31) + c | 0;
|
|
2187
|
+
}
|
|
2188
|
+
return `${s.length}:${h1}:${h2}`;
|
|
2189
|
+
}
|
|
2190
|
+
function pickLanguage(filename) {
|
|
2191
|
+
if (/\.tsx$/i.test(filename)) return "tsx";
|
|
2192
|
+
if (/\.jsx$/i.test(filename)) return "jsx";
|
|
2193
|
+
if (/\.(ts|cts|mts)$/i.test(filename)) return "ts";
|
|
2194
|
+
if (/\.(js|cjs|mjs)$/i.test(filename)) return "js";
|
|
2195
|
+
return null;
|
|
2196
|
+
}
|
|
2197
|
+
function parseFile(content, filename) {
|
|
2198
|
+
const lang = pickLanguage(filename);
|
|
2199
|
+
if (!lang) return null;
|
|
2200
|
+
if (!content || content.length === 0) return null;
|
|
2201
|
+
const key = cacheKey(filename, fullDigest(content));
|
|
2202
|
+
const hit = cache.get(key);
|
|
2203
|
+
if (hit && hit.content === content) return hit.value;
|
|
2204
|
+
const plugins = [];
|
|
2205
|
+
if (lang === "ts" || lang === "tsx") plugins.push("typescript");
|
|
2206
|
+
if (lang === "jsx" || lang === "tsx") plugins.push("jsx");
|
|
2207
|
+
plugins.push("decorators-legacy", "classProperties", "dynamicImport", "topLevelAwait");
|
|
2208
|
+
let ast = null;
|
|
2209
|
+
try {
|
|
2210
|
+
ast = (0, import_parser.parse)(content, {
|
|
2211
|
+
sourceType: "unambiguous",
|
|
2212
|
+
allowImportExportEverywhere: true,
|
|
2213
|
+
allowReturnOutsideFunction: true,
|
|
2214
|
+
allowAwaitOutsideFunction: true,
|
|
2215
|
+
allowUndeclaredExports: true,
|
|
2216
|
+
errorRecovery: true,
|
|
2217
|
+
plugins
|
|
2218
|
+
});
|
|
2219
|
+
} catch {
|
|
2220
|
+
cache.set(key, { content, value: null });
|
|
2221
|
+
if (cache.size > MAX_CACHE) {
|
|
2222
|
+
const firstKey = cache.keys().next().value;
|
|
2223
|
+
if (firstKey !== void 0) cache.delete(firstKey);
|
|
2178
2224
|
}
|
|
2179
|
-
|
|
2180
|
-
|
|
2225
|
+
return null;
|
|
2226
|
+
}
|
|
2227
|
+
const entry = { ast, language: lang };
|
|
2228
|
+
cache.set(key, { content, value: entry });
|
|
2229
|
+
if (cache.size > MAX_CACHE) {
|
|
2230
|
+
const firstKey = cache.keys().next().value;
|
|
2231
|
+
if (firstKey !== void 0) cache.delete(firstKey);
|
|
2181
2232
|
}
|
|
2182
|
-
return
|
|
2233
|
+
return entry;
|
|
2183
2234
|
}
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2235
|
+
|
|
2236
|
+
// src/structural-handlers.ts
|
|
2237
|
+
var traverse = typeof import_traverse.default === "function" ? import_traverse.default : import_traverse.default.default;
|
|
2238
|
+
var PARSE_BYTES = 256 * 1024;
|
|
2239
|
+
var LOOKUP_LIMIT = 200;
|
|
2240
|
+
var METHODS = /* @__PURE__ */ new Set(["get", "head", "post", "put", "patch", "delete"]);
|
|
2241
|
+
var ROLE_WORD = /^(admin|superadmin|staff|owner)$/i;
|
|
2242
|
+
var faultName = null;
|
|
2243
|
+
var parseCount = 0;
|
|
2244
|
+
var modelCache = /* @__PURE__ */ new Map();
|
|
2245
|
+
var bearerSpanCache = /* @__PURE__ */ new Map();
|
|
2246
|
+
function setStructuralFaultForTest(name) {
|
|
2247
|
+
faultName = name;
|
|
2248
|
+
}
|
|
2249
|
+
function structuralParseCount() {
|
|
2250
|
+
return parseCount;
|
|
2251
|
+
}
|
|
2252
|
+
function resetStructuralState() {
|
|
2253
|
+
parseCount = 0;
|
|
2254
|
+
modelCache.clear();
|
|
2255
|
+
bearerSpanCache.clear();
|
|
2256
|
+
faultName = null;
|
|
2257
|
+
}
|
|
2258
|
+
function fault(name) {
|
|
2259
|
+
if (faultName === name || faultName === "all") throw new Error("injected");
|
|
2260
|
+
}
|
|
2261
|
+
function digest(text) {
|
|
2262
|
+
let h1 = 5381;
|
|
2263
|
+
let h2 = 52711;
|
|
2264
|
+
for (let i = 0; i < text.length; i++) {
|
|
2265
|
+
const c = text.charCodeAt(i);
|
|
2266
|
+
h1 = Math.imul(h1, 33) + c | 0;
|
|
2267
|
+
h2 = Math.imul(h2, 31) + c | 0;
|
|
2268
|
+
}
|
|
2269
|
+
return `${text.length}:${h1}:${h2}`;
|
|
2270
|
+
}
|
|
2271
|
+
function lineAt(content, index) {
|
|
2272
|
+
let line = 1;
|
|
2273
|
+
const end = Math.min(index, content.length);
|
|
2274
|
+
for (let i = 0; i < end; i++) if (content.charCodeAt(i) === 10) line++;
|
|
2275
|
+
return line;
|
|
2276
|
+
}
|
|
2277
|
+
function unwrap(node) {
|
|
2278
|
+
let cur = node;
|
|
2279
|
+
while (cur) {
|
|
2280
|
+
if (cur.type === "AwaitExpression" || cur.type === "ParenthesizedExpression" || cur.type === "TSAsExpression" || cur.type === "TSNonNullExpression" || cur.type === "TSSatisfiesExpression" || cur.type === "TSTypeAssertion" || cur.type === "ChainExpression") {
|
|
2281
|
+
cur = cur.expression ?? cur.argument;
|
|
2195
2282
|
continue;
|
|
2196
2283
|
}
|
|
2197
|
-
|
|
2198
|
-
|
|
2284
|
+
break;
|
|
2285
|
+
}
|
|
2286
|
+
return cur;
|
|
2287
|
+
}
|
|
2288
|
+
function propName(prop) {
|
|
2289
|
+
if (!prop) return "";
|
|
2290
|
+
if (prop.key?.type === "Identifier" && !prop.computed) return String(prop.key.name);
|
|
2291
|
+
if (prop.key?.type === "StringLiteral") return String(prop.key.value);
|
|
2292
|
+
return "";
|
|
2293
|
+
}
|
|
2294
|
+
function walk(node, visit) {
|
|
2295
|
+
if (!node || typeof node !== "object" || !node.type) return;
|
|
2296
|
+
visit(node);
|
|
2297
|
+
for (const key of Object.keys(node)) {
|
|
2298
|
+
if (key === "loc" || key === "start" || key === "end" || key === "range" || key === "leadingComments" || key === "trailingComments" || key === "innerComments") {
|
|
2199
2299
|
continue;
|
|
2200
2300
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2301
|
+
const child = node[key];
|
|
2302
|
+
if (Array.isArray(child)) {
|
|
2303
|
+
for (const item of child) if (item && typeof item === "object" && item.type) walk(item, visit);
|
|
2304
|
+
} else if (child && typeof child === "object" && child.type) {
|
|
2305
|
+
walk(child, visit);
|
|
2205
2306
|
}
|
|
2206
2307
|
}
|
|
2207
|
-
return -1;
|
|
2208
2308
|
}
|
|
2209
|
-
function
|
|
2210
|
-
|
|
2211
|
-
const
|
|
2212
|
-
|
|
2309
|
+
function paramNames(fn) {
|
|
2310
|
+
const names = [];
|
|
2311
|
+
for (const param of fn.params ?? []) {
|
|
2312
|
+
if (param?.type === "Identifier") names.push(param.name);
|
|
2313
|
+
else if (param?.type === "AssignmentPattern" && param.left?.type === "Identifier") names.push(param.left.name);
|
|
2314
|
+
else if (param?.type === "ObjectPattern") {
|
|
2315
|
+
for (const prop of param.properties ?? []) {
|
|
2316
|
+
if (prop?.type === "ObjectProperty" && prop.key?.type === "Identifier") names.push(prop.key.name);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
return names;
|
|
2213
2321
|
}
|
|
2214
|
-
function
|
|
2215
|
-
const
|
|
2216
|
-
|
|
2322
|
+
function statementsOf(fn) {
|
|
2323
|
+
const body = fn?.body;
|
|
2324
|
+
if (!body) return [];
|
|
2325
|
+
if (body.type === "BlockStatement") return body.body ?? [];
|
|
2326
|
+
return [{ type: "ReturnStatement", argument: body, start: body.start, end: body.end }];
|
|
2327
|
+
}
|
|
2328
|
+
function usable(parsed, content) {
|
|
2329
|
+
if (!parsed?.ast) return false;
|
|
2330
|
+
const ast = parsed.ast;
|
|
2331
|
+
if (Array.isArray(ast.errors) && ast.errors.length > 0) return false;
|
|
2332
|
+
if (typeof ast.end === "number" && ast.end !== content.length) return false;
|
|
2333
|
+
return true;
|
|
2217
2334
|
}
|
|
2218
|
-
function
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
const
|
|
2222
|
-
|
|
2223
|
-
|
|
2335
|
+
function controlScope(path) {
|
|
2336
|
+
let cur = path?.parentPath;
|
|
2337
|
+
while (cur) {
|
|
2338
|
+
const t = cur.node?.type;
|
|
2339
|
+
if (t === "IfStatement" || t === "ForStatement" || t === "WhileStatement" || t === "DoWhileStatement" || t === "ForInStatement" || t === "ForOfStatement" || t === "SwitchStatement" || t === "TryStatement" || t === "CatchClause" || t === "ConditionalExpression") {
|
|
2340
|
+
return null;
|
|
2341
|
+
}
|
|
2342
|
+
if (t === "FunctionDeclaration" || t === "FunctionExpression" || t === "ArrowFunctionExpression" || t === "ObjectMethod" || t === "ClassMethod") {
|
|
2343
|
+
return cur.node.start ?? 0;
|
|
2344
|
+
}
|
|
2345
|
+
if (t === "Program") return 0;
|
|
2346
|
+
cur = cur.parentPath;
|
|
2224
2347
|
}
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
if (
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
return end < 0 ? "" : content.slice(brace + 1, end);
|
|
2348
|
+
return 0;
|
|
2349
|
+
}
|
|
2350
|
+
function stringEntries(node) {
|
|
2351
|
+
const value = unwrap(node);
|
|
2352
|
+
if (!value) return null;
|
|
2353
|
+
let array = value;
|
|
2354
|
+
if (value.type === "NewExpression" && value.callee?.type === "Identifier" && value.callee.name === "Set") {
|
|
2355
|
+
if ((value.arguments ?? []).length !== 1) return null;
|
|
2356
|
+
array = value.arguments[0];
|
|
2235
2357
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2358
|
+
if (array?.type !== "ArrayExpression") return null;
|
|
2359
|
+
const entries = [];
|
|
2360
|
+
for (const el of array.elements ?? []) {
|
|
2361
|
+
if (!el || el.type !== "StringLiteral") return null;
|
|
2362
|
+
entries.push(String(el.value));
|
|
2363
|
+
}
|
|
2364
|
+
return entries.length > 0 ? entries : null;
|
|
2238
2365
|
}
|
|
2239
|
-
function
|
|
2240
|
-
const
|
|
2241
|
-
if (!
|
|
2242
|
-
if (
|
|
2243
|
-
|
|
2366
|
+
function staticString(node) {
|
|
2367
|
+
const value = unwrap(node);
|
|
2368
|
+
if (!value) return null;
|
|
2369
|
+
if (value.type === "StringLiteral") return String(value.value);
|
|
2370
|
+
if (value.type === "TemplateLiteral" && (value.expressions ?? []).length === 0) {
|
|
2371
|
+
return value.quasis.map((q) => q.value?.cooked ?? "").join("");
|
|
2372
|
+
}
|
|
2373
|
+
return null;
|
|
2244
2374
|
}
|
|
2245
|
-
function
|
|
2246
|
-
const
|
|
2247
|
-
if (
|
|
2248
|
-
|
|
2375
|
+
function isProcessEnv(node) {
|
|
2376
|
+
const value = unwrap(node);
|
|
2377
|
+
if (value?.type !== "MemberExpression" || value.computed) return false;
|
|
2378
|
+
if (value.property?.type !== "Identifier") return false;
|
|
2379
|
+
const env = value.object;
|
|
2380
|
+
return env?.type === "MemberExpression" && !env.computed && env.property?.name === "env" && env.object?.type === "Identifier" && env.object.name === "process";
|
|
2249
2381
|
}
|
|
2250
|
-
function
|
|
2251
|
-
|
|
2382
|
+
function isEnvRead(node) {
|
|
2383
|
+
const value = unwrap(node);
|
|
2384
|
+
if (!value) return false;
|
|
2385
|
+
if (value.type === "MemberExpression") {
|
|
2386
|
+
if (value.object?.type === "Identifier" && value.object.name === "process" && value.property?.name === "env") return true;
|
|
2387
|
+
if (isProcessEnv(value)) return true;
|
|
2388
|
+
if (value.object?.type === "Identifier" && value.object.name === "env") return true;
|
|
2389
|
+
if (value.object?.type === "MemberExpression" && value.object.property?.name === "env" && (value.object.object?.name === "Deno" || value.object.object?.name === "Bun")) {
|
|
2390
|
+
return true;
|
|
2391
|
+
}
|
|
2392
|
+
if (value.object?.type === "MetaProperty" && value.property?.name === "env") return true;
|
|
2393
|
+
}
|
|
2394
|
+
if (value.type === "CallExpression" && value.callee?.type === "MemberExpression" && value.callee.property?.name === "get" && value.callee.object?.type === "MemberExpression" && value.callee.object.property?.name === "env") {
|
|
2395
|
+
return true;
|
|
2396
|
+
}
|
|
2397
|
+
return false;
|
|
2252
2398
|
}
|
|
2253
|
-
function
|
|
2254
|
-
const
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2399
|
+
function registrationOk(content, start, method, appRouter) {
|
|
2400
|
+
const slice = content.slice(start, start + 160).replace(/^\s+/, "");
|
|
2401
|
+
if (appRouter) return new RegExp(`^export\\s+(?:async\\s+)?function\\s+${method}\\b`).test(slice);
|
|
2402
|
+
return new RegExp(`^[A-Za-z_$][\\w$]*\\s*\\.\\s*${method}\\s*\\(`, "i").test(slice);
|
|
2403
|
+
}
|
|
2404
|
+
function pushHandler(handlers, content, fn, method, path, receiver, line, regStart, routeArgs, appRouter, scope) {
|
|
2405
|
+
if (typeof fn?.start !== "number" || typeof fn?.end !== "number") return;
|
|
2406
|
+
if (!registrationOk(content, regStart, appRouter ? method.toUpperCase() : method, appRouter)) return;
|
|
2407
|
+
const params = paramNames(fn);
|
|
2408
|
+
handlers.push({
|
|
2409
|
+
method,
|
|
2410
|
+
path,
|
|
2411
|
+
receiver,
|
|
2412
|
+
line,
|
|
2413
|
+
fnStart: fn.start,
|
|
2414
|
+
fnEnd: fn.end,
|
|
2415
|
+
regStart,
|
|
2416
|
+
params,
|
|
2417
|
+
statements: statementsOf(fn),
|
|
2418
|
+
fn,
|
|
2419
|
+
appRouter,
|
|
2420
|
+
routeArgs,
|
|
2421
|
+
scope,
|
|
2422
|
+
requestName: params[0] ?? "req",
|
|
2423
|
+
replyName: params[1] ?? "res"
|
|
2424
|
+
});
|
|
2259
2425
|
}
|
|
2260
|
-
function
|
|
2261
|
-
const
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2426
|
+
function build(parsed, content) {
|
|
2427
|
+
const ast = parsed.ast;
|
|
2428
|
+
const handlers = [];
|
|
2429
|
+
const uses = [];
|
|
2430
|
+
const functions = [];
|
|
2431
|
+
const consts = /* @__PURE__ */ new Set();
|
|
2432
|
+
const assigned = /* @__PURE__ */ new Set();
|
|
2433
|
+
traverse(ast, {
|
|
2434
|
+
FunctionExpression(path) {
|
|
2435
|
+
const node = path.node;
|
|
2436
|
+
if (typeof node.start === "number" && typeof node.end === "number") functions.push({ start: node.start, end: node.end });
|
|
2437
|
+
},
|
|
2438
|
+
ArrowFunctionExpression(path) {
|
|
2439
|
+
const node = path.node;
|
|
2440
|
+
if (typeof node.start === "number" && typeof node.end === "number") functions.push({ start: node.start, end: node.end });
|
|
2441
|
+
},
|
|
2442
|
+
VariableDeclaration(path) {
|
|
2443
|
+
if (path.node.kind !== "const") return;
|
|
2444
|
+
for (const decl of path.node.declarations ?? []) {
|
|
2445
|
+
if (decl?.id?.type === "Identifier") consts.add(decl.id.name);
|
|
2274
2446
|
}
|
|
2275
|
-
|
|
2276
|
-
|
|
2447
|
+
},
|
|
2448
|
+
AssignmentExpression(path) {
|
|
2449
|
+
if (path.node.left?.type === "Identifier") assigned.add(path.node.left.name);
|
|
2450
|
+
},
|
|
2451
|
+
FunctionDeclaration(path) {
|
|
2452
|
+
const node = path.node;
|
|
2453
|
+
if (typeof node.start === "number" && typeof node.end === "number") functions.push({ start: node.start, end: node.end });
|
|
2454
|
+
if (path.parent?.type !== "ExportNamedDeclaration") return;
|
|
2455
|
+
const name = path.node.id?.name;
|
|
2456
|
+
if (!name || !/^(GET|HEAD|POST|PUT|PATCH|DELETE)$/.test(name)) return;
|
|
2457
|
+
const reg = path.parent;
|
|
2458
|
+
pushHandler(
|
|
2459
|
+
handlers,
|
|
2460
|
+
content,
|
|
2461
|
+
path.node,
|
|
2462
|
+
name.toLowerCase(),
|
|
2463
|
+
"",
|
|
2464
|
+
"",
|
|
2465
|
+
reg.loc?.start?.line ?? path.node.loc?.start?.line ?? 0,
|
|
2466
|
+
reg.start ?? path.node.start,
|
|
2467
|
+
[],
|
|
2468
|
+
true,
|
|
2469
|
+
0
|
|
2470
|
+
);
|
|
2471
|
+
},
|
|
2472
|
+
CallExpression(path) {
|
|
2473
|
+
const node = path.node;
|
|
2474
|
+
const callee = node.callee;
|
|
2475
|
+
const deno = callee?.type === "MemberExpression" && callee.object?.name === "Deno" && callee.property?.name === "serve" || callee?.type === "Identifier" && callee.name === "serve";
|
|
2476
|
+
if (deno) {
|
|
2477
|
+
const args2 = node.arguments ?? [];
|
|
2478
|
+
const last2 = args2[args2.length - 1];
|
|
2479
|
+
if (last2?.type === "FunctionExpression" || last2?.type === "ArrowFunctionExpression") {
|
|
2480
|
+
pushHandler(handlers, content, last2, "serve", "", "Deno", node.loc?.start?.line ?? 0, node.start ?? 0, args2.slice(0, -1), false, controlScope(path) ?? 0);
|
|
2481
|
+
}
|
|
2482
|
+
return;
|
|
2483
|
+
}
|
|
2484
|
+
if (callee?.type !== "MemberExpression" || callee.computed || callee.optional) return;
|
|
2485
|
+
if (callee.object?.type !== "Identifier" || callee.property?.type !== "Identifier") return;
|
|
2486
|
+
const method = String(callee.property.name);
|
|
2487
|
+
const receiver = String(callee.object.name);
|
|
2488
|
+
if (method === "use") {
|
|
2489
|
+
uses.push({
|
|
2490
|
+
receiver,
|
|
2491
|
+
start: node.start ?? 0,
|
|
2492
|
+
args: node.arguments ?? [],
|
|
2493
|
+
scope: controlScope(path),
|
|
2494
|
+
constReceiver: consts.has(receiver) && !assigned.has(receiver)
|
|
2495
|
+
});
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
const lower = method.toLowerCase();
|
|
2499
|
+
if (!METHODS.has(lower)) return;
|
|
2500
|
+
const args = node.arguments ?? [];
|
|
2501
|
+
const last = args[args.length - 1];
|
|
2502
|
+
if (last?.type !== "FunctionExpression" && last?.type !== "ArrowFunctionExpression") return;
|
|
2503
|
+
const pathArg = args[0];
|
|
2504
|
+
const routePath = pathArg?.type === "StringLiteral" ? String(pathArg.value) : staticString(pathArg) ?? "";
|
|
2505
|
+
pushHandler(
|
|
2506
|
+
handlers,
|
|
2507
|
+
content,
|
|
2508
|
+
last,
|
|
2509
|
+
lower,
|
|
2510
|
+
routePath,
|
|
2511
|
+
receiver,
|
|
2512
|
+
node.loc?.start?.line ?? 0,
|
|
2513
|
+
node.start ?? 0,
|
|
2514
|
+
args.slice(0, -1),
|
|
2515
|
+
false,
|
|
2516
|
+
controlScope(path) ?? 0
|
|
2517
|
+
);
|
|
2277
2518
|
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2519
|
+
});
|
|
2520
|
+
for (const use of uses) use.constReceiver = consts.has(use.receiver) && !assigned.has(use.receiver);
|
|
2521
|
+
return {
|
|
2522
|
+
ast,
|
|
2523
|
+
handlers,
|
|
2524
|
+
uses,
|
|
2525
|
+
functions,
|
|
2526
|
+
sets: moduleSets(ast),
|
|
2527
|
+
primitives: modulePrimitives(ast),
|
|
2528
|
+
cryptoName: importedName(ast, ["crypto", "node:crypto"]),
|
|
2529
|
+
hasherNames: importedNames(ast, ["bcrypt", "bcryptjs", "argon2"]),
|
|
2530
|
+
hashFns: hashFunctions(ast, importedName(ast, ["crypto", "node:crypto"])),
|
|
2531
|
+
randomNames: randomBindings(ast, importedName(ast, ["crypto", "node:crypto"]))
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
function topLevel(ast) {
|
|
2535
|
+
const out = [];
|
|
2536
|
+
for (const stmt of ast.program?.body ?? []) {
|
|
2537
|
+
if (stmt?.type === "ExportNamedDeclaration" && stmt.declaration) out.push(stmt.declaration);
|
|
2538
|
+
else out.push(stmt);
|
|
2539
|
+
}
|
|
2540
|
+
return out;
|
|
2541
|
+
}
|
|
2542
|
+
function moduleSets(ast) {
|
|
2543
|
+
const sets = /* @__PURE__ */ new Map();
|
|
2544
|
+
for (const stmt of topLevel(ast)) {
|
|
2545
|
+
if (stmt?.type !== "VariableDeclaration" || stmt.kind !== "const") continue;
|
|
2546
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2547
|
+
if (decl?.id?.type !== "Identifier") continue;
|
|
2548
|
+
const entries = stringEntries(decl.init);
|
|
2549
|
+
if (!entries) continue;
|
|
2550
|
+
if (entries.every((entry) => publicHttpsUrl(httpsHost(entry)))) sets.set(decl.id.name, entries);
|
|
2281
2551
|
}
|
|
2282
|
-
if (c === "{") {
|
|
2283
|
-
brace++;
|
|
2284
|
-
if (brace === 1) stmtStart = i + 1;
|
|
2285
|
-
} else if (c === "}") {
|
|
2286
|
-
brace--;
|
|
2287
|
-
if (brace === 1) stmtStart = i + 1;
|
|
2288
|
-
} else if (c === "(") paren++;
|
|
2289
|
-
else if (c === ")") paren--;
|
|
2290
|
-
else if (c === "[") bracket++;
|
|
2291
|
-
else if (c === "]") bracket--;
|
|
2292
|
-
else if (c === ";" && brace === 1 && paren === 0 && bracket === 0) stmtStart = i + 1;
|
|
2293
2552
|
}
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2553
|
+
const mutated = /* @__PURE__ */ new Set();
|
|
2554
|
+
walk(ast, (node) => {
|
|
2555
|
+
if (node.type === "AssignmentExpression" && node.left?.type === "Identifier" && sets.has(node.left.name)) mutated.add(node.left.name);
|
|
2556
|
+
if (node.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.type === "Identifier") {
|
|
2557
|
+
const name = node.callee.property?.name;
|
|
2558
|
+
if ((name === "add" || name === "delete" || name === "clear" || name === "push") && sets.has(node.callee.object.name)) {
|
|
2559
|
+
mutated.add(node.callee.object.name);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
for (const name of mutated) sets.delete(name);
|
|
2564
|
+
return sets;
|
|
2302
2565
|
}
|
|
2303
|
-
function
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
if (
|
|
2310
|
-
|
|
2311
|
-
|
|
2566
|
+
function httpsHost(host) {
|
|
2567
|
+
return host.includes("://") ? host : `https://${host}`;
|
|
2568
|
+
}
|
|
2569
|
+
function modulePrimitives(ast) {
|
|
2570
|
+
const names = /* @__PURE__ */ new Set();
|
|
2571
|
+
for (const stmt of topLevel(ast)) {
|
|
2572
|
+
if (stmt?.type !== "VariableDeclaration" || stmt.kind !== "const") continue;
|
|
2573
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2574
|
+
const init = unwrap(decl?.init);
|
|
2575
|
+
if (decl?.id?.type === "Identifier" && init && (init.type === "StringLiteral" || init.type === "NumericLiteral" || init.type === "BooleanLiteral")) {
|
|
2576
|
+
names.add(decl.id.name);
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2312
2579
|
}
|
|
2313
|
-
return
|
|
2580
|
+
return names;
|
|
2314
2581
|
}
|
|
2315
|
-
function
|
|
2316
|
-
const
|
|
2317
|
-
|
|
2318
|
-
const start = match.index + match[0].length;
|
|
2319
|
-
const brace = handler.indexOf("{", start);
|
|
2320
|
-
const args = handler.slice(start, brace === -1 ? handler.length : brace);
|
|
2321
|
-
return guardMentioned(content, args);
|
|
2582
|
+
function importedName(ast, sources) {
|
|
2583
|
+
const names = importedNames(ast, sources);
|
|
2584
|
+
return names.values().next().value ?? null;
|
|
2322
2585
|
}
|
|
2323
|
-
function
|
|
2324
|
-
const
|
|
2325
|
-
|
|
2586
|
+
function importedNames(ast, sources) {
|
|
2587
|
+
const names = /* @__PURE__ */ new Set();
|
|
2588
|
+
const accept = new Set(sources);
|
|
2589
|
+
for (const stmt of ast.program?.body ?? []) {
|
|
2590
|
+
if (stmt?.type === "ImportDeclaration" && accept.has(String(stmt.source?.value))) {
|
|
2591
|
+
for (const spec of stmt.specifiers ?? []) {
|
|
2592
|
+
if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportNamespaceSpecifier") names.add(spec.local.name);
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
if (stmt?.type === "VariableDeclaration") {
|
|
2596
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2597
|
+
const init = unwrap(decl?.init);
|
|
2598
|
+
if (decl?.id?.type !== "Identifier" || init?.type !== "CallExpression") continue;
|
|
2599
|
+
if (init.callee?.type !== "Identifier" || init.callee.name !== "require") continue;
|
|
2600
|
+
const arg = init.arguments?.[0];
|
|
2601
|
+
if (arg?.type === "StringLiteral" && accept.has(String(arg.value))) names.add(decl.id.name);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
return names;
|
|
2326
2606
|
}
|
|
2327
|
-
function
|
|
2607
|
+
function isCreateHashChain(node, param, cryptoName) {
|
|
2608
|
+
const digest2 = unwrap(node);
|
|
2609
|
+
if (digest2?.type !== "CallExpression" || digest2.callee?.type !== "MemberExpression" || digest2.callee.property?.name !== "digest") return false;
|
|
2610
|
+
const digestArgs = digest2.arguments ?? [];
|
|
2611
|
+
if (digestArgs.length > 1) return false;
|
|
2612
|
+
if (digestArgs.length === 1 && digestArgs[0]?.type !== "StringLiteral") return false;
|
|
2613
|
+
const update = digest2.callee.object;
|
|
2614
|
+
if (update?.type !== "CallExpression" || update.callee?.type !== "MemberExpression" || update.callee.property?.name !== "update") return false;
|
|
2615
|
+
if ((update.arguments ?? []).length !== 1 || update.arguments[0]?.type !== "Identifier" || update.arguments[0].name !== param) return false;
|
|
2616
|
+
const created = update.callee.object;
|
|
2617
|
+
if (created?.type !== "CallExpression" || created.callee?.type !== "MemberExpression") return false;
|
|
2618
|
+
if (created.callee.property?.name !== "createHash" || created.callee.object?.name !== cryptoName) return false;
|
|
2619
|
+
return (created.arguments ?? []).length === 1 && created.arguments[0]?.type === "StringLiteral";
|
|
2620
|
+
}
|
|
2621
|
+
function hashFunctions(ast, cryptoName) {
|
|
2622
|
+
const names = /* @__PURE__ */ new Set();
|
|
2623
|
+
if (!cryptoName) return names;
|
|
2624
|
+
walk(ast, (node) => {
|
|
2625
|
+
if (node.type === "FunctionDeclaration" && node.id?.name && hashBody(node, cryptoName)) names.add(node.id.name);
|
|
2626
|
+
if (node.type === "VariableDeclarator" && node.id?.type === "Identifier") {
|
|
2627
|
+
const init = node.init;
|
|
2628
|
+
if ((init?.type === "ArrowFunctionExpression" || init?.type === "FunctionExpression") && hashBody(init, cryptoName)) names.add(node.id.name);
|
|
2629
|
+
}
|
|
2630
|
+
});
|
|
2631
|
+
return names;
|
|
2632
|
+
}
|
|
2633
|
+
function hashBody(fn, cryptoName) {
|
|
2634
|
+
if ((fn.params ?? []).length !== 1 || fn.params[0]?.type !== "Identifier") return false;
|
|
2635
|
+
const param = fn.params[0].name;
|
|
2636
|
+
let body = fn.body;
|
|
2637
|
+
if (body?.type === "BlockStatement") {
|
|
2638
|
+
if ((body.body ?? []).length !== 1 || body.body[0]?.type !== "ReturnStatement") return false;
|
|
2639
|
+
body = body.body[0].argument;
|
|
2640
|
+
}
|
|
2641
|
+
return isCreateHashChain(body, param, cryptoName);
|
|
2642
|
+
}
|
|
2643
|
+
function randomBindings(ast, cryptoName) {
|
|
2644
|
+
const names = /* @__PURE__ */ new Set();
|
|
2645
|
+
if (!cryptoName) return names;
|
|
2646
|
+
walk(ast, (node) => {
|
|
2647
|
+
if (node.type !== "VariableDeclarator" || node.id?.type !== "Identifier") return;
|
|
2648
|
+
if (isRandomBytes(unwrap(node.init), cryptoName)) names.add(node.id.name);
|
|
2649
|
+
});
|
|
2650
|
+
return names;
|
|
2651
|
+
}
|
|
2652
|
+
function isRandomBytes(node, cryptoName) {
|
|
2653
|
+
let call = node;
|
|
2654
|
+
if (call?.type === "CallExpression" && call.callee?.type === "MemberExpression" && call.callee.property?.name === "toString") {
|
|
2655
|
+
call = call.callee.object;
|
|
2656
|
+
}
|
|
2657
|
+
if (call?.type !== "CallExpression" || call.callee?.type !== "MemberExpression" || call.callee.property?.name !== "randomBytes") return false;
|
|
2658
|
+
if (call.callee.object?.name !== cryptoName) return false;
|
|
2659
|
+
const n = call.arguments?.[0];
|
|
2660
|
+
return n?.type === "NumericLiteral" && typeof n.value === "number" && n.value >= 16 && (call.arguments ?? []).length === 1;
|
|
2661
|
+
}
|
|
2662
|
+
function load(content, filePath) {
|
|
2663
|
+
fault("parse");
|
|
2664
|
+
if (content.length > PARSE_BYTES) return null;
|
|
2665
|
+
const key = `${filePath}\0${digest(content)}`;
|
|
2666
|
+
const hit = modelCache.get(key);
|
|
2667
|
+
if (hit && hit.content === content) return hit.model;
|
|
2668
|
+
parseCount += 1;
|
|
2669
|
+
const parsed = parseFile(content, filePath);
|
|
2670
|
+
const model = parsed && usable(parsed, content) ? build(parsed, content) : null;
|
|
2671
|
+
modelCache.set(key, { content, model });
|
|
2672
|
+
if (modelCache.size > 128) {
|
|
2673
|
+
const first = modelCache.keys().next().value;
|
|
2674
|
+
if (first !== void 0) modelCache.delete(first);
|
|
2675
|
+
}
|
|
2676
|
+
return model;
|
|
2677
|
+
}
|
|
2678
|
+
function onLine(model, content, index) {
|
|
2679
|
+
const line = lineAt(content, index);
|
|
2680
|
+
const found = model.handlers.filter((handler) => handler.line === line);
|
|
2681
|
+
return found.length === 1 ? found[0] : null;
|
|
2682
|
+
}
|
|
2683
|
+
function publicHttpsUrl(value) {
|
|
2684
|
+
try {
|
|
2685
|
+
fault("publicHttpsUrl");
|
|
2686
|
+
const url = new URL(value);
|
|
2687
|
+
if (url.protocol !== "https:") return false;
|
|
2688
|
+
if (url.username || url.password) return false;
|
|
2689
|
+
if (url.port !== "") return false;
|
|
2690
|
+
const host = url.hostname.toLowerCase().replace(/\.$/, "");
|
|
2691
|
+
if (!host || !host.includes(".")) return false;
|
|
2692
|
+
if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(host) || host.includes(":")) return false;
|
|
2693
|
+
if (host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal") || host.endsWith(".lan") || host.endsWith(".home.arpa")) {
|
|
2694
|
+
return false;
|
|
2695
|
+
}
|
|
2696
|
+
return true;
|
|
2697
|
+
} catch {
|
|
2698
|
+
return false;
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
function isReq(node, requestName) {
|
|
2702
|
+
const value = unwrap(node);
|
|
2703
|
+
return value?.type === "Identifier" && (value.name === requestName || value.name === "req" || value.name === "request" || value.name === "ctx");
|
|
2704
|
+
}
|
|
2705
|
+
function isRequestInput(node, requestName) {
|
|
2706
|
+
const value = unwrap(node);
|
|
2707
|
+
if (!value || value.type !== "MemberExpression" || value.computed) return false;
|
|
2708
|
+
const prop = value.property?.name;
|
|
2709
|
+
if (["query", "params", "body", "searchParams"].includes(prop) && isReq(value.object, requestName)) return true;
|
|
2710
|
+
return isRequestInput(value.object, requestName);
|
|
2711
|
+
}
|
|
2712
|
+
function hasIdentity(fn, requestName) {
|
|
2713
|
+
let bad = false;
|
|
2714
|
+
walk(fn, (node) => {
|
|
2715
|
+
if (node.type === "CallExpression") {
|
|
2716
|
+
if (node.callee?.type === "Identifier" && (node.callee.name === "cookies" || node.callee.name === "headers")) bad = true;
|
|
2717
|
+
if (node.callee?.type === "MemberExpression" && node.callee.property?.name === "get") {
|
|
2718
|
+
const arg = node.arguments?.[0];
|
|
2719
|
+
if (arg?.type === "StringLiteral" && /^(authorization|cookie|x-api-key)$/i.test(String(arg.value))) bad = true;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
if ((node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && !node.computed) {
|
|
2723
|
+
const prop = node.property?.name;
|
|
2724
|
+
if (["user", "session", "cookies", "auth", "signedCookies"].includes(prop) && isReq(node.object, requestName)) bad = true;
|
|
2725
|
+
if (prop === "user" && node.object?.type === "MemberExpression" && node.object.property?.name === "state") bad = true;
|
|
2726
|
+
}
|
|
2727
|
+
});
|
|
2728
|
+
return bad;
|
|
2729
|
+
}
|
|
2730
|
+
function evalExpr(node, env, depth = 0) {
|
|
2731
|
+
if (!node || depth > 40) return "no";
|
|
2732
|
+
const value = unwrap(node);
|
|
2733
|
+
if (!value) return "no";
|
|
2734
|
+
if (value.type === "StringLiteral" || value.type === "NumericLiteral" || value.type === "BooleanLiteral" || value.type === "NullLiteral") return "value";
|
|
2735
|
+
if (value.type === "TemplateLiteral" && (value.expressions ?? []).length === 0) return "value";
|
|
2736
|
+
if (isEnvRead(value)) {
|
|
2737
|
+
env.bad = true;
|
|
2738
|
+
return "no";
|
|
2739
|
+
}
|
|
2740
|
+
if (value.type === "Identifier") {
|
|
2741
|
+
const known = env.allowed.get(value.name);
|
|
2742
|
+
if (known) return known;
|
|
2743
|
+
if (env.primitives.has(value.name)) return "value";
|
|
2744
|
+
return "no";
|
|
2745
|
+
}
|
|
2746
|
+
if (value.type === "MemberExpression" || value.type === "OptionalMemberExpression") {
|
|
2747
|
+
if (value.optional || value.type === "OptionalMemberExpression") return "no";
|
|
2748
|
+
if (value.computed) {
|
|
2749
|
+
if (isReq(value.property, env.requestName) || isRequestInput(value.property, env.requestName)) env.bad = true;
|
|
2750
|
+
return "no";
|
|
2751
|
+
}
|
|
2752
|
+
if (isRequestInput(value, env.requestName)) return "value";
|
|
2753
|
+
const obj = value.object;
|
|
2754
|
+
if (obj?.type === "Identifier" && env.allowed.get(obj.name) === "url" && (value.property?.name === "hostname" || value.property?.name === "href")) return "value";
|
|
2755
|
+
const inner = evalExpr(obj, env, depth + 1);
|
|
2756
|
+
if (inner === "value") return "value";
|
|
2757
|
+
return "no";
|
|
2758
|
+
}
|
|
2759
|
+
if (value.type === "NewExpression" && value.callee?.type === "Identifier" && value.callee.name === "URL") {
|
|
2760
|
+
if ((value.arguments ?? []).length < 1 || evalExpr(value.arguments[0], env, depth + 1) === "no") return "no";
|
|
2761
|
+
return "url";
|
|
2762
|
+
}
|
|
2763
|
+
if (value.type === "ObjectExpression") {
|
|
2764
|
+
for (const prop of value.properties ?? []) {
|
|
2765
|
+
if (prop?.type !== "ObjectProperty" || prop.computed) return "no";
|
|
2766
|
+
if (evalExpr(prop.value, env, depth + 1) === "no") return "no";
|
|
2767
|
+
}
|
|
2768
|
+
return "value";
|
|
2769
|
+
}
|
|
2770
|
+
if (value.type === "ArrayExpression") {
|
|
2771
|
+
for (const el of value.elements ?? []) if (!el || evalExpr(el, env, depth + 1) === "no") return "no";
|
|
2772
|
+
return "value";
|
|
2773
|
+
}
|
|
2774
|
+
if (value.type === "CallExpression" || value.type === "OptionalCallExpression") {
|
|
2775
|
+
if (value.optional || value.type === "OptionalCallExpression") return "no";
|
|
2776
|
+
return evalCall(value, env, depth);
|
|
2777
|
+
}
|
|
2778
|
+
return "no";
|
|
2779
|
+
}
|
|
2780
|
+
function argsAllowed(node, env, depth) {
|
|
2781
|
+
return (node.arguments ?? []).every((arg) => arg && evalExpr(arg, env, depth + 1) !== "no");
|
|
2782
|
+
}
|
|
2783
|
+
function callbackOk(fn, env) {
|
|
2784
|
+
if (!fn || fn.type !== "ArrowFunctionExpression" && fn.type !== "FunctionExpression") return false;
|
|
2785
|
+
const saved = new Map(env.allowed);
|
|
2786
|
+
const responded = env.responded;
|
|
2787
|
+
const bad = env.bad;
|
|
2788
|
+
for (const name of paramNames(fn)) env.allowed.set(name, "value");
|
|
2789
|
+
let ok = false;
|
|
2790
|
+
if (fn.body?.type === "BlockStatement") ok = (fn.body.body ?? []).every((stmt) => execStmt(stmt, env));
|
|
2791
|
+
else ok = evalExpr(fn.body, env) !== "no";
|
|
2792
|
+
env.allowed = saved;
|
|
2793
|
+
env.responded = responded;
|
|
2794
|
+
env.bad = bad;
|
|
2795
|
+
return ok;
|
|
2796
|
+
}
|
|
2797
|
+
function isReply(node, env) {
|
|
2798
|
+
const value = unwrap(node);
|
|
2799
|
+
return value?.type === "Identifier" && (value.name === "res" || value.name === "reply" || value.name === env.replyName);
|
|
2800
|
+
}
|
|
2801
|
+
function responseCall(node, env, depth) {
|
|
2802
|
+
if (node?.type === "NewExpression" && node.callee?.name === "Response") return argsAllowed(node, env, depth);
|
|
2803
|
+
if (node?.type !== "CallExpression") return false;
|
|
2804
|
+
const callee = node.callee;
|
|
2805
|
+
if (callee?.type === "MemberExpression" && callee.object?.type === "Identifier" && (callee.object.name === "NextResponse" || callee.object.name === "Response") && callee.property?.name === "json") {
|
|
2806
|
+
return argsAllowed(node, env, depth);
|
|
2807
|
+
}
|
|
2808
|
+
if (callee?.type !== "MemberExpression") return false;
|
|
2809
|
+
const prop = callee.property?.name;
|
|
2810
|
+
if (prop === "render") {
|
|
2811
|
+
if (!isReply(callee.object, env)) return false;
|
|
2812
|
+
if (node.arguments?.[0]?.type !== "StringLiteral") return false;
|
|
2813
|
+
return node.arguments.length < 2 || evalExpr(node.arguments[1], env, depth + 1) !== "no";
|
|
2814
|
+
}
|
|
2815
|
+
if (prop !== "json" && prop !== "send" && prop !== "end") return false;
|
|
2816
|
+
const target = callee.object;
|
|
2817
|
+
if (isReply(target, env)) return argsAllowed(node, env, depth);
|
|
2818
|
+
if (target?.type === "CallExpression" && target.callee?.type === "MemberExpression") {
|
|
2819
|
+
const inner = target.callee.property?.name;
|
|
2820
|
+
if ((inner === "status" || inner === "code") && isReply(target.callee.object, env) && target.arguments?.[0]?.type === "NumericLiteral") {
|
|
2821
|
+
return argsAllowed(node, env, depth);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
return false;
|
|
2825
|
+
}
|
|
2826
|
+
function urlBinding(node, env) {
|
|
2827
|
+
const value = unwrap(node);
|
|
2828
|
+
if (value?.type === "Identifier" && env.allowed.get(value.name) === "url") return value.name;
|
|
2829
|
+
if (value?.type === "MemberExpression" && !value.computed && value.property?.name === "href" && value.object?.type === "Identifier" && env.allowed.get(value.object.name) === "url") {
|
|
2830
|
+
return value.object.name;
|
|
2831
|
+
}
|
|
2832
|
+
if (value?.type === "CallExpression" && value.callee?.type === "MemberExpression" && value.callee.property?.name === "toString" && (value.arguments ?? []).length === 0 && value.callee.object?.type === "Identifier" && env.allowed.get(value.callee.object.name) === "url") {
|
|
2833
|
+
return value.callee.object.name;
|
|
2834
|
+
}
|
|
2835
|
+
return null;
|
|
2836
|
+
}
|
|
2837
|
+
var MODEL_PATH = /^\/(?:v\d+(?:beta\d*)?\/)?models\/?$/;
|
|
2838
|
+
function optionState(node) {
|
|
2839
|
+
if (!node) return "absent";
|
|
2840
|
+
if (node.type !== "ObjectExpression") return "bad";
|
|
2841
|
+
let secret = false;
|
|
2842
|
+
for (const prop of node.properties ?? []) {
|
|
2843
|
+
if (prop?.type !== "ObjectProperty" || prop.computed) return "bad";
|
|
2844
|
+
const key = propName(prop);
|
|
2845
|
+
if (key !== "headers" && key !== "cache" && key !== "next" && key !== "method") return "bad";
|
|
2846
|
+
if (key === "method") {
|
|
2847
|
+
const text = staticString(prop.value);
|
|
2848
|
+
if (text !== "GET" && text !== "HEAD" && text !== "get" && text !== "head") return "bad";
|
|
2849
|
+
continue;
|
|
2850
|
+
}
|
|
2851
|
+
if (key === "headers") {
|
|
2852
|
+
if (prop.value?.type !== "ObjectExpression") return "bad";
|
|
2853
|
+
for (const header of prop.value.properties ?? []) {
|
|
2854
|
+
if (header?.type !== "ObjectProperty" || header.computed || !literalValue(header.value)) secret = true;
|
|
2855
|
+
}
|
|
2856
|
+
continue;
|
|
2857
|
+
}
|
|
2858
|
+
if (staticString(prop.value) === null && prop.value?.type !== "NumericLiteral" && prop.value?.type !== "BooleanLiteral") secret = true;
|
|
2859
|
+
}
|
|
2860
|
+
return secret ? "secret" : "ok";
|
|
2861
|
+
}
|
|
2862
|
+
function literalValue(node) {
|
|
2863
|
+
const value = unwrap(node);
|
|
2864
|
+
if (!value) return false;
|
|
2865
|
+
if (value.type === "StringLiteral" || value.type === "NumericLiteral" || value.type === "BooleanLiteral" || value.type === "NullLiteral") return true;
|
|
2866
|
+
if (value.type === "TemplateLiteral") return (value.expressions ?? []).length === 0;
|
|
2867
|
+
if (value.type === "ObjectExpression") {
|
|
2868
|
+
return (value.properties ?? []).every((prop) => prop?.type === "ObjectProperty" && !prop.computed && literalValue(prop.value));
|
|
2869
|
+
}
|
|
2870
|
+
if (value.type === "ArrayExpression") return (value.elements ?? []).every((el) => Boolean(el) && literalValue(el));
|
|
2871
|
+
return false;
|
|
2872
|
+
}
|
|
2873
|
+
function evalCall(node, env, depth) {
|
|
2874
|
+
if (responseCall(node, env, depth)) {
|
|
2875
|
+
env.responded = true;
|
|
2876
|
+
return "value";
|
|
2877
|
+
}
|
|
2878
|
+
const callee = node.callee;
|
|
2879
|
+
if (callee?.type === "Identifier" && callee.name === "fetch") {
|
|
2880
|
+
const state = optionState(node.arguments?.[1]);
|
|
2881
|
+
if (state === "bad" || (node.arguments ?? []).length > 2) return "no";
|
|
2882
|
+
const secret = state === "secret";
|
|
2883
|
+
const literal = staticString(node.arguments?.[0]);
|
|
2884
|
+
if (literal !== null) {
|
|
2885
|
+
if (!publicHttpsUrl(literal)) return "no";
|
|
2886
|
+
if (secret) {
|
|
2887
|
+
const url = new URL(literal);
|
|
2888
|
+
if (url.search || url.hash || !MODEL_PATH.test(url.pathname)) return "no";
|
|
2889
|
+
}
|
|
2890
|
+
env.fetchSeen = true;
|
|
2891
|
+
return "fetch";
|
|
2892
|
+
}
|
|
2893
|
+
const binding = urlBinding(node.arguments?.[0], env);
|
|
2894
|
+
if (!binding || !env.rejected.has(binding) || secret) return "no";
|
|
2895
|
+
env.fetchSeen = true;
|
|
2896
|
+
return "fetch";
|
|
2897
|
+
}
|
|
2898
|
+
if (callee?.type === "Identifier" && (callee.name === "String" || callee.name === "Number" || callee.name === "Boolean")) {
|
|
2899
|
+
return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2900
|
+
}
|
|
2901
|
+
if (callee?.type === "MemberExpression" && !callee.computed) {
|
|
2902
|
+
const obj = callee.object;
|
|
2903
|
+
const prop = callee.property?.name;
|
|
2904
|
+
if (obj?.type === "Identifier" && obj.name === "JSON" && (prop === "parse" || prop === "stringify")) return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2905
|
+
if (obj?.type === "Identifier" && obj.name === "Object" && (prop === "keys" || prop === "values" || prop === "entries")) return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2906
|
+
if (obj?.type === "Identifier" && obj.name === "Array" && prop === "isArray") return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2907
|
+
if ((prop === "json" || prop === "text") && obj?.type === "Identifier" && env.allowed.get(obj.name) === "fetch") return "value";
|
|
2908
|
+
if ((prop === "has" || prop === "includes") && obj?.type === "Identifier" && env.sets.has(obj.name)) return "value";
|
|
2909
|
+
if ((prop === "map" || prop === "filter") && evalExpr(obj, env, depth + 1) === "value") return callbackOk(node.arguments?.[0], env) ? "value" : "no";
|
|
2910
|
+
if ((prop === "slice" || prop === "join" || prop === "toString") && evalExpr(obj, env, depth + 1) !== "no") return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2911
|
+
}
|
|
2912
|
+
return "no";
|
|
2913
|
+
}
|
|
2914
|
+
function has4xx(node) {
|
|
2915
|
+
let number = false;
|
|
2916
|
+
let call = false;
|
|
2917
|
+
walk(node, (current) => {
|
|
2918
|
+
if (current.type === "NumericLiteral" && current.value >= 400 && current.value < 500) number = true;
|
|
2919
|
+
if (current.type === "CallExpression" && ["status", "code", "json", "send"].includes(current.callee?.property?.name)) call = true;
|
|
2920
|
+
});
|
|
2921
|
+
return number && call;
|
|
2922
|
+
}
|
|
2923
|
+
function rejectConsequent(node) {
|
|
2924
|
+
if (!node) return false;
|
|
2925
|
+
if (node.type === "BlockStatement") return (node.body ?? []).length === 1 && rejectConsequent(node.body[0]);
|
|
2926
|
+
if (node.type === "ThrowStatement") return true;
|
|
2927
|
+
if (node.type === "ReturnStatement" || node.type === "ExpressionStatement") {
|
|
2928
|
+
const value = node.argument ?? node.expression;
|
|
2929
|
+
return has4xx(value);
|
|
2930
|
+
}
|
|
2931
|
+
return false;
|
|
2932
|
+
}
|
|
2933
|
+
function allowlistIf(stmt, env) {
|
|
2934
|
+
if (stmt?.type !== "IfStatement" || stmt.alternate || env.fetchSeen) return false;
|
|
2935
|
+
const test = unwrap(stmt.test);
|
|
2936
|
+
if (test?.type !== "UnaryExpression" || test.operator !== "!") return false;
|
|
2937
|
+
const call = unwrap(test.argument);
|
|
2938
|
+
if (call?.type !== "CallExpression" || call.callee?.type !== "MemberExpression") return false;
|
|
2939
|
+
const setName = call.callee.object?.type === "Identifier" ? call.callee.object.name : "";
|
|
2940
|
+
if (!env.sets.has(setName) || call.callee.property?.name !== "has" && call.callee.property?.name !== "includes") return false;
|
|
2941
|
+
const arg = call.arguments?.[0];
|
|
2942
|
+
if (arg?.type !== "MemberExpression" || arg.computed || arg.property?.name !== "hostname" || arg.object?.type !== "Identifier") return false;
|
|
2943
|
+
if (env.allowed.get(arg.object.name) !== "url") return false;
|
|
2944
|
+
if (!rejectConsequent(stmt.consequent)) return false;
|
|
2945
|
+
env.rejected.add(arg.object.name);
|
|
2946
|
+
return true;
|
|
2947
|
+
}
|
|
2948
|
+
function bind(id, kind, env) {
|
|
2949
|
+
if (!id) return false;
|
|
2950
|
+
if (id.type === "Identifier") {
|
|
2951
|
+
env.allowed.set(id.name, kind);
|
|
2952
|
+
return true;
|
|
2953
|
+
}
|
|
2954
|
+
if (id.type === "ObjectPattern") {
|
|
2955
|
+
return (id.properties ?? []).every((prop) => prop?.type === "ObjectProperty" && bind(prop.value, kind, env));
|
|
2956
|
+
}
|
|
2957
|
+
return false;
|
|
2958
|
+
}
|
|
2959
|
+
function execStmt(stmt, env) {
|
|
2960
|
+
if (!stmt || stmt.type === "EmptyStatement") return true;
|
|
2961
|
+
if (allowlistIf(stmt, env)) return true;
|
|
2962
|
+
if (stmt.type === "VariableDeclaration") {
|
|
2963
|
+
if (stmt.kind === "var") return false;
|
|
2964
|
+
if (stmt.kind !== "const") {
|
|
2965
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2966
|
+
const init = unwrap(decl?.init);
|
|
2967
|
+
if (init?.type === "NewExpression" && init.callee?.type === "Identifier" && init.callee.name === "URL") return false;
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2971
|
+
const kind = evalExpr(decl.init, env);
|
|
2972
|
+
if (kind === "no" || !bind(decl.id, kind, env)) return false;
|
|
2973
|
+
}
|
|
2974
|
+
return true;
|
|
2975
|
+
}
|
|
2976
|
+
if (stmt.type === "ReturnStatement") {
|
|
2977
|
+
if (stmt.argument && evalExpr(stmt.argument, env) === "no") return false;
|
|
2978
|
+
env.responded = true;
|
|
2979
|
+
return true;
|
|
2980
|
+
}
|
|
2981
|
+
if (stmt.type === "ExpressionStatement") {
|
|
2982
|
+
const kind = evalExpr(stmt.expression, env);
|
|
2983
|
+
return kind !== "no";
|
|
2984
|
+
}
|
|
2985
|
+
return false;
|
|
2986
|
+
}
|
|
2987
|
+
function readOnlyBody(content, model, handler) {
|
|
2988
|
+
if (handler.method !== "get" && handler.method !== "head") return false;
|
|
2989
|
+
if (hasIdentity(handler.fn, handler.requestName)) return false;
|
|
2990
|
+
const env = {
|
|
2991
|
+
allowed: /* @__PURE__ */ new Map(),
|
|
2992
|
+
sets: model.sets,
|
|
2993
|
+
primitives: model.primitives,
|
|
2994
|
+
requestName: handler.requestName,
|
|
2995
|
+
replyName: handler.replyName,
|
|
2996
|
+
rejected: /* @__PURE__ */ new Set(),
|
|
2997
|
+
fetchSeen: false,
|
|
2998
|
+
responded: false,
|
|
2999
|
+
bad: false
|
|
3000
|
+
};
|
|
3001
|
+
for (const stmt of handler.statements) {
|
|
3002
|
+
if (!execStmt(stmt, env) || env.bad) return false;
|
|
3003
|
+
}
|
|
3004
|
+
return env.responded && !env.bad && content.length >= 0;
|
|
3005
|
+
}
|
|
3006
|
+
function sourceGuarded(content, handler) {
|
|
3007
|
+
const slice = content.slice(handler.fnStart, handler.fnEnd);
|
|
3008
|
+
return /requireUser|requireAuth|withAuth|getServerSession|\bauth\s*\(|passport|isAuthenticated|verifyAdmin|requireAdmin|verifyToken/.test(slice);
|
|
3009
|
+
}
|
|
3010
|
+
function publicReadOnlyHandler(content, filePath, index, strictApp = false) {
|
|
3011
|
+
try {
|
|
3012
|
+
fault("readOnly");
|
|
3013
|
+
const model = load(content, filePath);
|
|
3014
|
+
if (!model) return false;
|
|
3015
|
+
const handler = onLine(model, content, index);
|
|
3016
|
+
if (!handler || !readOnlyBody(content, model, handler)) return false;
|
|
3017
|
+
if (strictApp && handler.appRouter) {
|
|
3018
|
+
for (const other of model.handlers) {
|
|
3019
|
+
if (!other.appRouter || other === handler) continue;
|
|
3020
|
+
const ok = (other.method === "get" || other.method === "head") && readOnlyBody(content, model, other) || capabilityBody(model, other) || sourceGuarded(content, other);
|
|
3021
|
+
if (!ok) return false;
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
return true;
|
|
3025
|
+
} catch {
|
|
3026
|
+
return false;
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
function roleLiteral(node) {
|
|
3030
|
+
if (node?.type === "StringLiteral") return ROLE_WORD.test(String(node.value));
|
|
3031
|
+
if (node?.type === "ArrayExpression") {
|
|
3032
|
+
const elements = node.elements ?? [];
|
|
3033
|
+
return elements.length > 0 && elements.every((el) => el?.type === "StringLiteral" && ROLE_WORD.test(String(el.value)));
|
|
3034
|
+
}
|
|
3035
|
+
return false;
|
|
3036
|
+
}
|
|
3037
|
+
function argIsRole(node) {
|
|
3038
|
+
if (!node) return false;
|
|
3039
|
+
if (node.type === "Identifier") return node.name === "requireAdmin" || node.name === "verifyAdmin";
|
|
3040
|
+
if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "requireRole") {
|
|
3041
|
+
const args = node.arguments ?? [];
|
|
3042
|
+
return args.length > 0 && args.every((arg) => roleLiteral(arg));
|
|
3043
|
+
}
|
|
3044
|
+
if (node.type === "ArrayExpression") return (node.elements ?? []).some((el) => argIsRole(el));
|
|
3045
|
+
return false;
|
|
3046
|
+
}
|
|
3047
|
+
function lookupHasTwoParams(content, lookup, params) {
|
|
3048
|
+
const query = querySlice(content, lookup);
|
|
3049
|
+
if (!query) return false;
|
|
3050
|
+
const used = /* @__PURE__ */ new Set();
|
|
3051
|
+
const re = /req\.params\.([A-Za-z_$][\w$]*)/g;
|
|
3052
|
+
let match;
|
|
3053
|
+
while (match = re.exec(query)) used.add(match[1]);
|
|
3054
|
+
return [...used].filter((name) => params.includes(name)).length >= 2;
|
|
3055
|
+
}
|
|
3056
|
+
function memberScoped(content, handler, lookups) {
|
|
3057
|
+
const params = [...handler.path.matchAll(/:([A-Za-z_$][\w$]*)/g)].map((match) => match[1]);
|
|
3058
|
+
if (params.length < 2) return false;
|
|
3059
|
+
const inside = lookups.filter((index) => index >= handler.fnStart && index < handler.fnEnd);
|
|
3060
|
+
if (inside.length === 0) return false;
|
|
3061
|
+
return inside.every((lookup) => lookupHasTwoParams(content, lookup, params));
|
|
3062
|
+
}
|
|
3063
|
+
function narrowedGuard(content, model, handler, lookups) {
|
|
3064
|
+
const member = (args) => args.some((arg) => arg?.type === "Identifier" && arg.name === "requireMember") && memberScoped(content, handler, lookups);
|
|
3065
|
+
if (handler.routeArgs.some((arg) => argIsRole(arg)) || member(handler.routeArgs)) return true;
|
|
3066
|
+
for (const use of model.uses) {
|
|
3067
|
+
if (use.receiver !== handler.receiver || !handler.receiver) continue;
|
|
3068
|
+
if (use.start >= handler.regStart || use.scope === null || use.scope !== handler.scope || !use.constReceiver) continue;
|
|
3069
|
+
if (use.args.some((arg) => argIsRole(arg)) || member(use.args)) return true;
|
|
3070
|
+
}
|
|
3071
|
+
return false;
|
|
3072
|
+
}
|
|
3073
|
+
function paramAccess(node) {
|
|
3074
|
+
const value = unwrap(node);
|
|
3075
|
+
if (value?.type !== "MemberExpression" || value.computed || value.property?.type !== "Identifier") return null;
|
|
3076
|
+
const prop = String(value.property.name);
|
|
3077
|
+
const obj = value.object;
|
|
3078
|
+
if (obj?.type === "Identifier" && obj.name === "params") return prop;
|
|
3079
|
+
if (obj?.type === "MemberExpression" && !obj.computed && obj.property?.name === "params") return prop;
|
|
3080
|
+
return null;
|
|
3081
|
+
}
|
|
3082
|
+
function isNow(node) {
|
|
3083
|
+
const value = unwrap(node);
|
|
3084
|
+
if (value?.type === "CallExpression" && value.callee?.object?.name === "Date" && value.callee?.property?.name === "now" && (value.arguments ?? []).length === 0) return true;
|
|
3085
|
+
return value?.type === "NewExpression" && value.callee?.name === "Date" && (value.arguments ?? []).length === 0;
|
|
3086
|
+
}
|
|
3087
|
+
function filterOf(obj, hashFns, cryptoName) {
|
|
3088
|
+
let target = obj;
|
|
3089
|
+
if ((obj?.properties ?? []).length === 1 && propName(obj.properties[0]) === "where" && obj.properties[0].value?.type === "ObjectExpression") {
|
|
3090
|
+
target = obj.properties[0].value;
|
|
3091
|
+
}
|
|
3092
|
+
const props = target?.properties ?? [];
|
|
3093
|
+
if (props.length !== 2 || props.some((prop) => prop?.type !== "ObjectProperty")) return null;
|
|
3094
|
+
let field = "";
|
|
3095
|
+
let param = "";
|
|
3096
|
+
let expiry = "";
|
|
3097
|
+
for (const prop of props) {
|
|
3098
|
+
const key = propName(prop);
|
|
3099
|
+
const value = unwrap(prop.value);
|
|
3100
|
+
if (value?.type === "CallExpression" && value.callee?.type === "Identifier" && hashFns.has(value.callee.name)) {
|
|
3101
|
+
if ((value.arguments ?? []).length !== 1) return null;
|
|
3102
|
+
const accessed = paramAccess(value.arguments[0]);
|
|
3103
|
+
if (!accessed) return null;
|
|
3104
|
+
field = key;
|
|
3105
|
+
param = accessed;
|
|
3106
|
+
} else if (value?.type === "CallExpression") {
|
|
3107
|
+
const accessed = paramAccess(inlineUpdateArg(value, cryptoName));
|
|
3108
|
+
if (!accessed) return null;
|
|
3109
|
+
field = key;
|
|
3110
|
+
param = accessed;
|
|
3111
|
+
} else if (value?.type === "ObjectExpression" && (value.properties ?? []).length === 1) {
|
|
3112
|
+
const inner = value.properties[0];
|
|
3113
|
+
const name = propName(inner);
|
|
3114
|
+
if (name !== "$gt" && name !== "gt" || !isNow(inner.value)) return null;
|
|
3115
|
+
expiry = key;
|
|
3116
|
+
} else return null;
|
|
3117
|
+
}
|
|
3118
|
+
if (!field || !param || !expiry) return null;
|
|
3119
|
+
return { field, param, expiry };
|
|
3120
|
+
}
|
|
3121
|
+
function assignedFromRandom(ast, field, hashFns, randomNames, cryptoName) {
|
|
3122
|
+
let found = false;
|
|
3123
|
+
walk(ast, (node) => {
|
|
3124
|
+
if (node.type !== "AssignmentExpression" || node.left?.type !== "MemberExpression") return;
|
|
3125
|
+
if (propName(node.left) !== field && node.left.property?.name !== field) return;
|
|
3126
|
+
const right = unwrap(node.right);
|
|
3127
|
+
if (right?.type !== "CallExpression") return;
|
|
3128
|
+
if (right.callee?.type === "Identifier" && hashFns.has(right.callee.name)) {
|
|
3129
|
+
const arg2 = right.arguments?.[0];
|
|
3130
|
+
if (arg2?.type === "Identifier" && randomNames.has(arg2.name)) found = true;
|
|
3131
|
+
return;
|
|
3132
|
+
}
|
|
3133
|
+
const arg = inlineUpdateArg(right, cryptoName);
|
|
3134
|
+
if (arg?.type === "Identifier" && randomNames.has(arg.name)) found = true;
|
|
3135
|
+
});
|
|
3136
|
+
return found;
|
|
3137
|
+
}
|
|
3138
|
+
function inlineUpdateArg(node, cryptoName) {
|
|
3139
|
+
const digest2 = unwrap(node);
|
|
3140
|
+
if (!cryptoName || digest2?.type !== "CallExpression" || digest2.callee?.type !== "MemberExpression" || digest2.callee.property?.name !== "digest") return null;
|
|
3141
|
+
const update = digest2.callee.object;
|
|
3142
|
+
if (update?.type !== "CallExpression" || update.callee?.type !== "MemberExpression" || update.callee.property?.name !== "update") return null;
|
|
3143
|
+
if ((update.arguments ?? []).length !== 1) return null;
|
|
3144
|
+
const created = update.callee.object;
|
|
3145
|
+
if (created?.type !== "CallExpression" || created.callee?.type !== "MemberExpression") return null;
|
|
3146
|
+
if (created.callee.property?.name !== "createHash" || created.callee.object?.name !== cryptoName) return null;
|
|
3147
|
+
if ((created.arguments ?? []).length !== 1 || created.arguments[0]?.type !== "StringLiteral") return null;
|
|
3148
|
+
return update.arguments[0];
|
|
3149
|
+
}
|
|
3150
|
+
function isPasswordAssign(stmt, user, hashers) {
|
|
3151
|
+
if (stmt?.type !== "ExpressionStatement" || stmt.expression?.type !== "AssignmentExpression") return false;
|
|
3152
|
+
const left = stmt.expression.left;
|
|
3153
|
+
if (left?.type !== "MemberExpression" || left.object?.name !== user) return false;
|
|
3154
|
+
const right = unwrap(stmt.expression.right);
|
|
3155
|
+
if (right?.type !== "CallExpression" || right.callee?.type !== "MemberExpression" || right.callee.property?.name !== "hash") return false;
|
|
3156
|
+
if (right.callee.object?.type !== "Identifier" || !hashers.has(right.callee.object.name)) return false;
|
|
3157
|
+
let cur = right.arguments?.[0];
|
|
3158
|
+
let body = false;
|
|
3159
|
+
while (cur?.type === "MemberExpression") {
|
|
3160
|
+
if (cur.property?.name === "body") body = true;
|
|
3161
|
+
cur = cur.object;
|
|
3162
|
+
}
|
|
3163
|
+
return body && right.arguments?.[1]?.type === "NumericLiteral";
|
|
3164
|
+
}
|
|
3165
|
+
function isClear(stmt, user, field) {
|
|
3166
|
+
if (stmt?.type !== "ExpressionStatement" || stmt.expression?.type !== "AssignmentExpression") return false;
|
|
3167
|
+
const left = stmt.expression.left;
|
|
3168
|
+
if (left?.type !== "MemberExpression" || left.object?.name !== user || left.property?.name !== field) return false;
|
|
3169
|
+
const right = unwrap(stmt.expression.right);
|
|
3170
|
+
return right?.type === "Identifier" && right.name === "undefined" || right?.type === "NullLiteral";
|
|
3171
|
+
}
|
|
3172
|
+
function isSave(stmt, user) {
|
|
3173
|
+
if (stmt?.type !== "ExpressionStatement") return false;
|
|
3174
|
+
const call = unwrap(stmt.expression);
|
|
3175
|
+
return call?.type === "CallExpression" && call.callee?.type === "MemberExpression" && call.callee.property?.name === "save" && call.callee.object?.name === user && (call.arguments ?? []).length === 0;
|
|
3176
|
+
}
|
|
3177
|
+
function isSuccess(stmt, _user, _param) {
|
|
3178
|
+
const value = stmt?.type === "ReturnStatement" ? stmt.argument : stmt?.type === "ExpressionStatement" ? stmt.expression : null;
|
|
3179
|
+
const call = unwrap(value);
|
|
3180
|
+
if (call?.type !== "CallExpression") return false;
|
|
3181
|
+
const callee = call.callee;
|
|
3182
|
+
const name = callee?.property?.name;
|
|
3183
|
+
const ok = callee?.type === "MemberExpression" && (name === "json" || name === "send") && (callee.object?.name === "res" || callee.object?.name === "reply" || callee.object?.name === "NextResponse" || callee.object?.name === "Response");
|
|
3184
|
+
if (!ok || (call.arguments ?? []).length < 1) return false;
|
|
3185
|
+
return literalValue(call.arguments[0]);
|
|
3186
|
+
}
|
|
3187
|
+
function capabilityBody(model, handler) {
|
|
3188
|
+
if (handler.method !== "post" && handler.method !== "put" && handler.method !== "patch") return false;
|
|
3189
|
+
const stmts = handler.statements.filter((stmt) => stmt?.type !== "EmptyStatement");
|
|
3190
|
+
if (stmts.length < 2 || stmts[0]?.type !== "VariableDeclaration" || (stmts[0].declarations ?? []).length !== 1) return false;
|
|
3191
|
+
const decl = stmts[0].declarations[0];
|
|
3192
|
+
if (decl?.id?.type !== "Identifier") return false;
|
|
3193
|
+
const lookup = unwrap(decl.init);
|
|
3194
|
+
if (lookup?.type !== "CallExpression" || lookup.callee?.type !== "MemberExpression") return false;
|
|
3195
|
+
if (!["findOne", "findUnique", "findFirst"].includes(lookup.callee.property?.name)) return false;
|
|
3196
|
+
const filter = filterOf(lookup.arguments?.[0], model.hashFns, model.cryptoName);
|
|
3197
|
+
if (!filter) return false;
|
|
3198
|
+
if (!handler.appRouter && !handler.path.includes(`:${filter.param}`)) return false;
|
|
3199
|
+
if (!assignedFromRandom(model.ast, filter.field, model.hashFns, model.randomNames, model.cryptoName)) return false;
|
|
3200
|
+
const guard = stmts[1];
|
|
3201
|
+
if (guard?.type !== "IfStatement" || guard.alternate) return false;
|
|
3202
|
+
const test = unwrap(guard.test);
|
|
3203
|
+
if (test?.type !== "UnaryExpression" || test.operator !== "!" || test.argument?.type !== "Identifier" || test.argument.name !== decl.id.name) return false;
|
|
3204
|
+
if (!rejectConsequent(guard.consequent)) return false;
|
|
3205
|
+
let clearF = false;
|
|
3206
|
+
let clearE = false;
|
|
3207
|
+
let password = false;
|
|
3208
|
+
let saved = false;
|
|
3209
|
+
let done = false;
|
|
3210
|
+
for (const stmt of stmts.slice(2)) {
|
|
3211
|
+
if (done) return false;
|
|
3212
|
+
if (isPasswordAssign(stmt, decl.id.name, model.hasherNames)) {
|
|
3213
|
+
if (password || saved) return false;
|
|
3214
|
+
password = true;
|
|
3215
|
+
continue;
|
|
3216
|
+
}
|
|
3217
|
+
if (isClear(stmt, decl.id.name, filter.field)) {
|
|
3218
|
+
if (saved) return false;
|
|
3219
|
+
clearF = true;
|
|
3220
|
+
continue;
|
|
3221
|
+
}
|
|
3222
|
+
if (isClear(stmt, decl.id.name, filter.expiry)) {
|
|
3223
|
+
if (saved) return false;
|
|
3224
|
+
clearE = true;
|
|
3225
|
+
continue;
|
|
3226
|
+
}
|
|
3227
|
+
if (isSave(stmt, decl.id.name)) {
|
|
3228
|
+
if (!clearF || !clearE || !password || saved) return false;
|
|
3229
|
+
saved = true;
|
|
3230
|
+
continue;
|
|
3231
|
+
}
|
|
3232
|
+
if (isSuccess(stmt, decl.id.name, filter.param)) {
|
|
3233
|
+
if (!saved) return false;
|
|
3234
|
+
done = true;
|
|
3235
|
+
continue;
|
|
3236
|
+
}
|
|
3237
|
+
return false;
|
|
3238
|
+
}
|
|
3239
|
+
return done && clearF && clearE && password && saved;
|
|
3240
|
+
}
|
|
3241
|
+
function capabilityTokenHandler(content, filePath, index) {
|
|
3242
|
+
try {
|
|
3243
|
+
fault("capability");
|
|
3244
|
+
const model = load(content, filePath);
|
|
3245
|
+
if (!model) return false;
|
|
3246
|
+
const handler = onLine(model, content, index);
|
|
3247
|
+
return handler ? capabilityBody(model, handler) : false;
|
|
3248
|
+
} catch {
|
|
3249
|
+
return false;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
function bearerExpr(node) {
|
|
3253
|
+
const value = unwrap(node);
|
|
3254
|
+
if (value?.type !== "TemplateLiteral" || (value.expressions ?? []).length !== 1) return null;
|
|
3255
|
+
const lead = value.quasis?.[0]?.value?.cooked ?? "";
|
|
3256
|
+
const tail = value.quasis?.[1]?.value?.cooked ?? "";
|
|
3257
|
+
if (!/^Bearer $/i.test(lead) || tail !== "") return null;
|
|
3258
|
+
return value.expressions[0];
|
|
3259
|
+
}
|
|
3260
|
+
function bindPattern(id, init, map) {
|
|
3261
|
+
if (!id) return;
|
|
3262
|
+
if (id.type === "Identifier") map.set(id.name, init);
|
|
3263
|
+
if (id.type === "ObjectPattern") {
|
|
3264
|
+
for (const prop of id.properties ?? []) {
|
|
3265
|
+
if (prop?.type === "ObjectProperty") bindPattern(prop.value, { type: "Destructure", object: init, key: propName(prop) }, map);
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
function declaredNames(id, into) {
|
|
3270
|
+
if (!id) return;
|
|
3271
|
+
if (id.type === "Identifier") into.push(id.name);
|
|
3272
|
+
if (id.type === "ObjectPattern" || id.type === "ArrayPattern") {
|
|
3273
|
+
const parts = id.properties ?? id.elements ?? [];
|
|
3274
|
+
for (const part of parts) {
|
|
3275
|
+
if (part?.type === "ObjectProperty" || part?.type === "RestElement") declaredNames(part.value ?? part.argument, into);
|
|
3276
|
+
else declaredNames(part, into);
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
if (id.type === "AssignmentPattern") declaredNames(id.left, into);
|
|
3280
|
+
}
|
|
3281
|
+
function bindingMap(fn) {
|
|
3282
|
+
const map = /* @__PURE__ */ new Map();
|
|
3283
|
+
const body = fn?.body?.type === "BlockStatement" ? fn.body.body ?? [] : [];
|
|
3284
|
+
for (const stmt of body) {
|
|
3285
|
+
if (stmt?.type !== "VariableDeclaration" || stmt.kind !== "const") continue;
|
|
3286
|
+
for (const decl of stmt.declarations ?? []) {
|
|
3287
|
+
if (decl?.init) bindPattern(decl.id, unwrap(decl.init), map);
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3291
|
+
const assigned = /* @__PURE__ */ new Set();
|
|
3292
|
+
walk(fn, (node) => {
|
|
3293
|
+
if (node.type === "VariableDeclarator") {
|
|
3294
|
+
const names = [];
|
|
3295
|
+
declaredNames(node.id, names);
|
|
3296
|
+
for (const name of names) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
3297
|
+
}
|
|
3298
|
+
if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") {
|
|
3299
|
+
const names = [];
|
|
3300
|
+
declaredNames(node.left ?? node.argument, names);
|
|
3301
|
+
for (const name of names) assigned.add(name);
|
|
3302
|
+
}
|
|
3303
|
+
});
|
|
3304
|
+
for (const [name, count] of counts) if (count > 1) map.delete(name);
|
|
3305
|
+
for (const name of assigned) map.delete(name);
|
|
3306
|
+
return map;
|
|
3307
|
+
}
|
|
3308
|
+
function isCookieValue(node, map) {
|
|
3309
|
+
const member = unwrap(node);
|
|
3310
|
+
if (!member || member.type !== "MemberExpression" && member.type !== "OptionalMemberExpression" || member.property?.name !== "value") return false;
|
|
3311
|
+
const call = unwrap(member.object);
|
|
3312
|
+
if (call?.type !== "CallExpression" || call.callee?.type !== "MemberExpression" || call.callee.property?.name !== "get") return false;
|
|
3313
|
+
if (call.arguments?.[0]?.type !== "StringLiteral") return false;
|
|
3314
|
+
const obj = unwrap(call.callee.object);
|
|
3315
|
+
if (obj?.type === "CallExpression" && obj.callee?.name === "cookies") return true;
|
|
3316
|
+
if (obj?.type === "Identifier") {
|
|
3317
|
+
const bound = unwrap(map.get(obj.name));
|
|
3318
|
+
if (bound?.type === "CallExpression" && bound.callee?.name === "cookies") return true;
|
|
3319
|
+
}
|
|
3320
|
+
return false;
|
|
3321
|
+
}
|
|
3322
|
+
function isSessionToken(node, map) {
|
|
3323
|
+
const member = unwrap(node);
|
|
3324
|
+
if (!member || member.type !== "MemberExpression" && member.type !== "OptionalMemberExpression" || member.property?.name !== "access_token") return false;
|
|
3325
|
+
if (member.object?.type !== "Identifier") return false;
|
|
3326
|
+
let current = map.get(member.object.name);
|
|
3327
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3328
|
+
while (current && current.type === "Destructure" && !seen.has(current)) {
|
|
3329
|
+
seen.add(current);
|
|
3330
|
+
current = current.object;
|
|
3331
|
+
}
|
|
3332
|
+
const call = unwrap(current);
|
|
3333
|
+
if (call?.type !== "CallExpression" || call.callee?.property?.name !== "getSession" || call.callee?.object?.property?.name !== "auth") return false;
|
|
3334
|
+
const clientName = call.callee.object.object?.name;
|
|
3335
|
+
const client = unwrap(map.get(clientName));
|
|
3336
|
+
return client?.type === "CallExpression" && (client.callee?.name === "createClient" || client.callee?.property?.name === "createClient");
|
|
3337
|
+
}
|
|
3338
|
+
function fetchLiteral(node) {
|
|
3339
|
+
const call = unwrap(node);
|
|
3340
|
+
if (call?.type !== "CallExpression" || call.callee?.name !== "fetch") return null;
|
|
3341
|
+
return staticString(call.arguments?.[0]);
|
|
3342
|
+
}
|
|
3343
|
+
function isOAuthToken(node, map, here) {
|
|
3344
|
+
if (node?.type !== "Identifier") return false;
|
|
3345
|
+
let current = map.get(node.name);
|
|
3346
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3347
|
+
while (current && current.type === "Destructure" && !seen.has(current)) {
|
|
3348
|
+
seen.add(current);
|
|
3349
|
+
current = current.object;
|
|
3350
|
+
}
|
|
3351
|
+
const json = unwrap(current);
|
|
3352
|
+
if (json?.type !== "CallExpression" || json.callee?.property?.name !== "json" || json.callee?.object?.type !== "Identifier") return false;
|
|
3353
|
+
const tokenUrl = fetchLiteral(map.get(json.callee.object.name));
|
|
3354
|
+
if (!tokenUrl || !here) return false;
|
|
3355
|
+
if (!publicHttpsUrl(tokenUrl) || !publicHttpsUrl(here)) return false;
|
|
3356
|
+
const tokenHost = new URL(tokenUrl).hostname.toLowerCase();
|
|
3357
|
+
const hereHost = new URL(here).hostname.toLowerCase();
|
|
3358
|
+
return tokenHost === hereHost || hereHost.endsWith(`.${tokenHost}`);
|
|
3359
|
+
}
|
|
3360
|
+
function envUrl(node) {
|
|
3361
|
+
const value = unwrap(node);
|
|
3362
|
+
if (value?.type !== "TemplateLiteral" || (value.expressions ?? []).length !== 1) return false;
|
|
3363
|
+
if (!isProcessEnv(value.expressions[0]) || value.expressions[0]?.type === "LogicalExpression") return false;
|
|
3364
|
+
const lead = value.quasis?.[0]?.value?.cooked ?? "";
|
|
3365
|
+
const rest = value.quasis?.[1]?.value?.cooked ?? "";
|
|
3366
|
+
return lead === "" && rest.startsWith("/") && !rest.includes("?");
|
|
3367
|
+
}
|
|
3368
|
+
function headerQualifies(model, propPath) {
|
|
3369
|
+
const index = propPath.node.start;
|
|
3370
|
+
const options = propPath.parent;
|
|
3371
|
+
const call = propPath.parentPath?.parentPath?.node;
|
|
3372
|
+
if (options?.type !== "ObjectExpression" || call?.type !== "CallExpression") return false;
|
|
3373
|
+
if (call.arguments?.[1] !== options || call.callee?.name !== "fetch") return false;
|
|
3374
|
+
const headers = propPath.node.value;
|
|
3375
|
+
if (headers?.type !== "ObjectExpression") return false;
|
|
3376
|
+
const auth = (headers.properties ?? []).find((prop) => prop?.type === "ObjectProperty" && propName(prop).toLowerCase() === "authorization");
|
|
3377
|
+
const expr = bearerExpr(auth?.value);
|
|
3378
|
+
if (!expr) return false;
|
|
3379
|
+
const inner = model.functions.filter((fn) => fn.start <= index && index < fn.end).sort((a, b) => a.end - a.start - (b.end - b.start))[0];
|
|
3380
|
+
const handler = model.handlers.find((item) => item.fnStart === inner?.start && item.fnEnd === inner?.end);
|
|
3381
|
+
if (!handler || handler.method !== "serve" && !METHODS.has(handler.method)) return false;
|
|
3382
|
+
const map = bindingMap(handler.fn);
|
|
3383
|
+
const urlNode = call.arguments?.[0];
|
|
3384
|
+
const direct = unwrap(expr);
|
|
3385
|
+
const resolved = direct?.type === "Identifier" ? unwrap(map.get(direct.name)) ?? direct : direct;
|
|
3386
|
+
if (isCookieValue(direct, map) || isCookieValue(resolved, map) || isSessionToken(direct, map) || isSessionToken(resolved, map)) return envUrl(urlNode);
|
|
3387
|
+
const here = staticString(urlNode);
|
|
3388
|
+
return here !== null && isOAuthToken(unwrap(expr), map, here);
|
|
3389
|
+
}
|
|
3390
|
+
function bearerSpans(content, filePath, model) {
|
|
3391
|
+
const key = `${filePath}\0${digest(content)}`;
|
|
3392
|
+
const hit = bearerSpanCache.get(key);
|
|
3393
|
+
if (hit && hit.content === content) return hit.spans;
|
|
3394
|
+
const spans = [];
|
|
3395
|
+
traverse(model.ast, {
|
|
3396
|
+
ObjectProperty(path) {
|
|
3397
|
+
const node = path.node;
|
|
3398
|
+
if (typeof node.start !== "number" || typeof node.end !== "number") return;
|
|
3399
|
+
if (propName(node).toLowerCase() !== "headers") return;
|
|
3400
|
+
spans.push({ start: node.start, end: node.end, ok: headerQualifies(model, path) });
|
|
3401
|
+
}
|
|
3402
|
+
});
|
|
3403
|
+
bearerSpanCache.set(key, { content, spans });
|
|
3404
|
+
if (bearerSpanCache.size > 128) {
|
|
3405
|
+
const first = bearerSpanCache.keys().next().value;
|
|
3406
|
+
if (first !== void 0) bearerSpanCache.delete(first);
|
|
3407
|
+
}
|
|
3408
|
+
return spans;
|
|
3409
|
+
}
|
|
3410
|
+
function bearerProvenanceSafe(content, filePath, index) {
|
|
3411
|
+
try {
|
|
3412
|
+
fault("bearer");
|
|
3413
|
+
if (!content.includes("fetch")) return false;
|
|
3414
|
+
const model = load(content, filePath);
|
|
3415
|
+
if (!model) return false;
|
|
3416
|
+
let count = 0;
|
|
3417
|
+
let ok = false;
|
|
3418
|
+
for (const span of bearerSpans(content, filePath, model)) {
|
|
3419
|
+
if (index < span.start || index >= span.end) continue;
|
|
3420
|
+
count += 1;
|
|
3421
|
+
ok = span.ok;
|
|
3422
|
+
}
|
|
3423
|
+
return count === 1 && ok;
|
|
3424
|
+
} catch {
|
|
3425
|
+
return false;
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
var LOOKUP_RE = /findUnique|findFirst|findById|\.findOne\b|\.find\s*\(\s*\{|WHERE[\s\S]{0,120}?(?:params|req\.(?:body|query))|\.get\([^)]{0,500}(?:params|req\.(?:body|query))/gi;
|
|
3429
|
+
var REF_RE = /params\.id|params\.(?:slug|uuid)|req\.params\.\w+|req\.params\b|req\.(?:body|query)\.\w*id/gi;
|
|
3430
|
+
var OWNER_RE = /userId|ownerId|createdBy|user_id|owner_id|AND.*user|where.*user|authorize|canAccess|checkPermission|isOwner|belongsTo/i;
|
|
3431
|
+
var AUTH_RE = /requireUser|requireUserForApi|requireAuth|withAuth|getServerSession|auth\(\)|passport|isAuthenticated/i;
|
|
3432
|
+
function maskLocal(content) {
|
|
3433
|
+
let open = content.indexOf("/*");
|
|
3434
|
+
let blocked2 = content;
|
|
3435
|
+
if (open !== -1) {
|
|
3436
|
+
const parts = [];
|
|
3437
|
+
let copied = 0;
|
|
3438
|
+
while (open !== -1) {
|
|
3439
|
+
const close = content.indexOf("*/", open + 2);
|
|
3440
|
+
if (close === -1) break;
|
|
3441
|
+
parts.push(content.slice(copied, open), content.slice(open, close + 2).replace(/[^\n]/g, " "));
|
|
3442
|
+
copied = close + 2;
|
|
3443
|
+
open = content.indexOf("/*", copied);
|
|
3444
|
+
}
|
|
3445
|
+
parts.push(content.slice(copied));
|
|
3446
|
+
blocked2 = parts.join("");
|
|
3447
|
+
}
|
|
3448
|
+
return blocked2.replace(/(^|[^:])\/\/[^\n]*/gm, (match, lead) => lead + " ".repeat(match.length - lead.length));
|
|
3449
|
+
}
|
|
3450
|
+
function matchIndexes(text, re) {
|
|
3451
|
+
const copy = new RegExp(re.source, re.flags);
|
|
3452
|
+
const out = [];
|
|
3453
|
+
let match;
|
|
3454
|
+
while (match = copy.exec(text)) {
|
|
3455
|
+
out.push(match.index);
|
|
3456
|
+
if (match[0].length === 0) copy.lastIndex += 1;
|
|
3457
|
+
if (out.length > LOOKUP_LIMIT) break;
|
|
3458
|
+
}
|
|
3459
|
+
return out;
|
|
3460
|
+
}
|
|
3461
|
+
function balancedCall(content, open) {
|
|
3462
|
+
let depth = 0;
|
|
3463
|
+
for (let i = open; i < content.length; i++) {
|
|
3464
|
+
const c = content[i];
|
|
3465
|
+
if (c === "(") depth += 1;
|
|
3466
|
+
else if (c === ")") {
|
|
3467
|
+
depth -= 1;
|
|
3468
|
+
if (depth === 0) return content.slice(open, i + 1);
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
return null;
|
|
3472
|
+
}
|
|
3473
|
+
function querySlice(content, index) {
|
|
3474
|
+
if (/^where\b/i.test(content.slice(index, index + 5))) {
|
|
3475
|
+
let depth = 0;
|
|
3476
|
+
for (let i = index; i >= 0; i--) {
|
|
3477
|
+
const c = content[i];
|
|
3478
|
+
if (c === ")") depth += 1;
|
|
3479
|
+
else if (c === "(") {
|
|
3480
|
+
if (depth === 0) return balancedCall(content, i);
|
|
3481
|
+
depth -= 1;
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
const open = content.indexOf("(", index);
|
|
3486
|
+
if (open === -1 || open - index > 80) return null;
|
|
3487
|
+
return balancedCall(content, open);
|
|
3488
|
+
}
|
|
3489
|
+
function handlerAt(model, index) {
|
|
3490
|
+
const found = model.handlers.filter((handler) => handler.fnStart <= index && index < handler.fnEnd);
|
|
3491
|
+
found.sort((a, b) => a.fnEnd - a.fnStart - (b.fnEnd - b.fnStart));
|
|
3492
|
+
return found[0] ?? null;
|
|
3493
|
+
}
|
|
3494
|
+
function handlerQualifies(content, filePath, handler, lookups) {
|
|
3495
|
+
const slice = content.slice(handler.fnStart, handler.fnEnd);
|
|
3496
|
+
const registered = content.slice(handler.regStart, handler.fnEnd);
|
|
3497
|
+
if (AUTH_RE.test(registered)) return false;
|
|
3498
|
+
const lookup = lookups.find((index) => index >= handler.fnStart && index < handler.fnEnd);
|
|
3499
|
+
if (lookup === void 0) return false;
|
|
3500
|
+
const query = querySlice(content, lookup) ?? slice;
|
|
3501
|
+
if (OWNER_RE.test(query)) return false;
|
|
3502
|
+
const reads = /req\.params\b|req\.(?:body|query)\.\w*id\b|params\.id|params\.(?:slug|uuid)/i.test(slice);
|
|
3503
|
+
if (!reads) return false;
|
|
3504
|
+
if (handler.appRouter) return /\/api\//i.test(filePath) && /^(get|put|patch|delete)$/.test(handler.method);
|
|
3505
|
+
return METHODS.has(handler.method);
|
|
3506
|
+
}
|
|
3507
|
+
function refineDirectObjectFindings(content, filePath, legacyLines) {
|
|
3508
|
+
try {
|
|
3509
|
+
fault("refine");
|
|
3510
|
+
if (content.length > PARSE_BYTES) return null;
|
|
3511
|
+
const masked = maskLocal(content);
|
|
3512
|
+
const lookups = matchIndexes(masked, LOOKUP_RE);
|
|
3513
|
+
if (lookups.length > LOOKUP_LIMIT) return null;
|
|
3514
|
+
const model = load(content, filePath);
|
|
3515
|
+
if (!model || model.handlers.length === 0) return null;
|
|
3516
|
+
const refs = matchIndexes(masked, REF_RE);
|
|
3517
|
+
if (refs.length === 0) return null;
|
|
3518
|
+
const cleared = (handler) => narrowedGuard(content, model, handler, lookups) || capabilityTokenHandler(content, filePath, handler.regStart);
|
|
3519
|
+
let every = true;
|
|
3520
|
+
for (const ref of refs) {
|
|
3521
|
+
const handler = handlerAt(model, ref);
|
|
3522
|
+
if (!handler || !cleared(handler)) every = false;
|
|
3523
|
+
}
|
|
3524
|
+
const lines = /* @__PURE__ */ new Set();
|
|
3525
|
+
if (!every) for (const line of legacyLines) lines.add(line);
|
|
3526
|
+
for (const handler of model.handlers) {
|
|
3527
|
+
if (cleared(handler) || !handlerQualifies(content, filePath, handler, lookups)) continue;
|
|
3528
|
+
const ref = refs.find((index) => index >= handler.fnStart && index < handler.fnEnd);
|
|
3529
|
+
if (ref === void 0) continue;
|
|
3530
|
+
lines.add(lineAt(content, ref));
|
|
3531
|
+
}
|
|
3532
|
+
return [...lines].sort((a, b) => a - b);
|
|
3533
|
+
} catch {
|
|
3534
|
+
return null;
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
// src/auth-scope.ts
|
|
3539
|
+
var GUARD_NAMES = ["requireAdmin", "requireMember", "requireRole", "requireUser", "verifyToken", "verifyAdmin"];
|
|
3540
|
+
var PUBLIC_LAST = /^(?:login|logout|signup|register|forgot(?:-password)?|reset(?:-password)?|callback)$/i;
|
|
3541
|
+
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;
|
|
3542
|
+
function blankComments(content) {
|
|
3543
|
+
let open = content.indexOf("/*");
|
|
3544
|
+
let blocked2 = content;
|
|
3545
|
+
if (open !== -1) {
|
|
3546
|
+
const parts = [];
|
|
3547
|
+
let copied = 0;
|
|
3548
|
+
while (open !== -1) {
|
|
3549
|
+
const close = content.indexOf("*/", open + 2);
|
|
3550
|
+
if (close === -1) break;
|
|
3551
|
+
parts.push(content.slice(copied, open), content.slice(open, close + 2).replace(/[^\n]/g, " "));
|
|
3552
|
+
copied = close + 2;
|
|
3553
|
+
open = content.indexOf("/*", copied);
|
|
3554
|
+
}
|
|
3555
|
+
parts.push(content.slice(copied));
|
|
3556
|
+
blocked2 = parts.join("");
|
|
3557
|
+
}
|
|
3558
|
+
return blocked2.replace(/(^|[^:])\/\/[^\n]*/gm, (m, lead) => lead + " ".repeat(m.length - lead.length));
|
|
3559
|
+
}
|
|
3560
|
+
var ARG_CAP = 300;
|
|
3561
|
+
var IF_BODY_CAP = 2e3;
|
|
3562
|
+
var BRACE_CAP = 2e4;
|
|
3563
|
+
function matchingCloser(text, open, openCh, closeCh, maxLen = Infinity) {
|
|
3564
|
+
let depth = 0;
|
|
3565
|
+
let quote = "";
|
|
3566
|
+
const end = maxLen === Infinity ? text.length : Math.min(text.length, open + maxLen);
|
|
3567
|
+
for (let i = open; i < end; i++) {
|
|
3568
|
+
const c = text[i];
|
|
3569
|
+
if (quote) {
|
|
3570
|
+
if (c === "\\") {
|
|
3571
|
+
i++;
|
|
3572
|
+
continue;
|
|
3573
|
+
}
|
|
3574
|
+
if (c === quote) quote = "";
|
|
3575
|
+
continue;
|
|
3576
|
+
}
|
|
3577
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
3578
|
+
quote = c;
|
|
3579
|
+
continue;
|
|
3580
|
+
}
|
|
3581
|
+
if (c === openCh) depth++;
|
|
3582
|
+
else if (c === closeCh) {
|
|
3583
|
+
depth--;
|
|
3584
|
+
if (depth === 0) return i;
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
return -1;
|
|
3588
|
+
}
|
|
3589
|
+
function escapeRegExp(value) {
|
|
3590
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3591
|
+
}
|
|
3592
|
+
function maskStrings(content) {
|
|
3593
|
+
const chars = content.split("");
|
|
3594
|
+
let i = 0;
|
|
3595
|
+
while (i < chars.length) {
|
|
3596
|
+
const c = chars[i];
|
|
3597
|
+
if (c === "'" || c === '"') {
|
|
3598
|
+
const quote = c;
|
|
3599
|
+
chars[i] = " ";
|
|
3600
|
+
i++;
|
|
3601
|
+
while (i < chars.length) {
|
|
3602
|
+
if (chars[i] === "\\") {
|
|
3603
|
+
chars[i] = " ";
|
|
3604
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
3605
|
+
i += 2;
|
|
3606
|
+
continue;
|
|
3607
|
+
}
|
|
3608
|
+
if (chars[i] === "\n") break;
|
|
3609
|
+
if (chars[i] === quote) {
|
|
3610
|
+
chars[i] = " ";
|
|
3611
|
+
i++;
|
|
3612
|
+
break;
|
|
3613
|
+
}
|
|
3614
|
+
chars[i] = " ";
|
|
3615
|
+
i++;
|
|
3616
|
+
}
|
|
3617
|
+
continue;
|
|
3618
|
+
}
|
|
3619
|
+
if (c === "`") {
|
|
3620
|
+
chars[i] = " ";
|
|
3621
|
+
i++;
|
|
3622
|
+
let expr = 0;
|
|
3623
|
+
while (i < chars.length) {
|
|
3624
|
+
if (expr === 0 && chars[i] === "\\") {
|
|
3625
|
+
chars[i] = " ";
|
|
3626
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
3627
|
+
i += 2;
|
|
3628
|
+
continue;
|
|
3629
|
+
}
|
|
3630
|
+
if (expr === 0 && chars[i] === "`") {
|
|
3631
|
+
chars[i] = " ";
|
|
3632
|
+
i++;
|
|
3633
|
+
break;
|
|
3634
|
+
}
|
|
3635
|
+
if (expr === 0 && chars[i] === "$" && chars[i + 1] === "{") {
|
|
3636
|
+
chars[i] = " ";
|
|
3637
|
+
chars[i + 1] = " ";
|
|
3638
|
+
expr = 1;
|
|
3639
|
+
i += 2;
|
|
3640
|
+
continue;
|
|
3641
|
+
}
|
|
3642
|
+
if (expr > 0) {
|
|
3643
|
+
if (chars[i] === "{") expr++;
|
|
3644
|
+
else if (chars[i] === "}") expr--;
|
|
3645
|
+
i++;
|
|
3646
|
+
continue;
|
|
3647
|
+
}
|
|
3648
|
+
if (chars[i] !== "\n") chars[i] = " ";
|
|
3649
|
+
i++;
|
|
3650
|
+
}
|
|
3651
|
+
continue;
|
|
3652
|
+
}
|
|
3653
|
+
i++;
|
|
3654
|
+
}
|
|
3655
|
+
return chars.join("");
|
|
3656
|
+
}
|
|
3657
|
+
var REJECT_RE = /\bthrow\b|\bredirect\s*\(|\b(?:status(?:Code)?|sendStatus)\s*[:(=]\s*40[13]\b/;
|
|
3658
|
+
function localImportedNames(clause) {
|
|
3659
|
+
const names = [];
|
|
3660
|
+
for (const part of clause.split(",")) {
|
|
3661
|
+
const bits = part.trim().split(/\s+as\s+/i);
|
|
3662
|
+
const local = (bits[1] ?? bits[0] ?? "").replace(/^\s*type\s+/, "").trim();
|
|
3663
|
+
const ident = /^([A-Za-z_$][\w$]*)$/.exec(local);
|
|
3664
|
+
if (ident) names.push(ident[1]);
|
|
3665
|
+
}
|
|
3666
|
+
return names;
|
|
3667
|
+
}
|
|
3668
|
+
function isImportedName(content, name) {
|
|
3669
|
+
const id = escapeRegExp(name);
|
|
3670
|
+
if (new RegExp(`\\bimport\\s+${id}\\s+from\\b`).test(content)) return true;
|
|
3671
|
+
if (new RegExp(`\\b(?:const|let|var)\\s+${id}\\s*=\\s*require\\s*\\(`).test(content)) return true;
|
|
3672
|
+
for (const match of content.matchAll(/\bimport\s+(?:type\s+)?\{([^}]+)\}\s*from/g)) {
|
|
3673
|
+
if (localImportedNames(match[1]).includes(name)) return true;
|
|
3674
|
+
}
|
|
3675
|
+
for (const match of content.matchAll(/\b(?:const|let|var)\s*\{([^}]+)\}\s*=\s*require\s*\(/g)) {
|
|
3676
|
+
if (localImportedNames(match[1]).includes(name)) return true;
|
|
3677
|
+
}
|
|
3678
|
+
return false;
|
|
3679
|
+
}
|
|
3680
|
+
function jwtBindingSpan(file, name) {
|
|
3681
|
+
const id = escapeRegExp(name);
|
|
3682
|
+
const patterns = [
|
|
3683
|
+
new RegExp(`\\bimport\\s+${id}\\s+from\\s+["']jsonwebtoken["']`),
|
|
3684
|
+
new RegExp(`\\bimport\\s*\\*\\s*as\\s+${id}\\s+from\\s+["']jsonwebtoken["']`),
|
|
3685
|
+
new RegExp(
|
|
3686
|
+
`(?:const|let|var)\\s+${id}\\s*=\\s*require\\(\\s*["']jsonwebtoken["']\\s*\\)\\s*;?(?=\\s*(?:$|\\n|\\r))`
|
|
3687
|
+
)
|
|
3688
|
+
];
|
|
3689
|
+
for (const pattern of patterns) {
|
|
3690
|
+
const match = pattern.exec(file);
|
|
3691
|
+
if (!match || match.index === void 0) continue;
|
|
3692
|
+
return [match.index, match.index + match[0].length];
|
|
3693
|
+
}
|
|
3694
|
+
return null;
|
|
3695
|
+
}
|
|
3696
|
+
function bindingIsShadowed(file, name, span) {
|
|
3697
|
+
const id = escapeRegExp(name);
|
|
3698
|
+
const checks = [
|
|
3699
|
+
new RegExp(`\\b(?:const|let|var)\\s+${id}\\b`, "g"),
|
|
3700
|
+
new RegExp(`\\b${id}\\s*=(?!=)`, "g"),
|
|
3701
|
+
new RegExp(`[(,]\\s*${id}\\s*[,)=:]`, "g")
|
|
3702
|
+
];
|
|
3703
|
+
for (const pattern of checks) {
|
|
3704
|
+
let match;
|
|
3705
|
+
while (match = pattern.exec(file)) {
|
|
3706
|
+
if (match.index >= span[0] && match.index < span[1]) continue;
|
|
3707
|
+
return true;
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
return false;
|
|
3711
|
+
}
|
|
3712
|
+
function identifierIsObjectLiteral(file, name) {
|
|
3713
|
+
const id = escapeRegExp(name);
|
|
3714
|
+
return new RegExp(`(?:\\b(?:const|let|var)\\s+|(?<![\\w$.]))${id}\\s*=(?!=)\\s*\\{`).test(file);
|
|
3715
|
+
}
|
|
3716
|
+
function verifyCallForm(source, callIndex, file) {
|
|
3717
|
+
const open = source.indexOf("(", callIndex);
|
|
3718
|
+
if (open < 0) return "none";
|
|
3719
|
+
const close = matchingCloser(source, open, "(", ")", ARG_CAP);
|
|
3720
|
+
if (close < 0) return "none";
|
|
3721
|
+
const args = splitArgs(source.slice(open + 1, close)).map((part) => part.trim()).filter(Boolean);
|
|
3722
|
+
if (args.length === 2) return "sync";
|
|
3723
|
+
if (args.length >= 4) return "callback";
|
|
3724
|
+
if (args.length !== 3) return "none";
|
|
3725
|
+
const third = args[2];
|
|
3726
|
+
if (/=>/.test(third) || /^\s*(?:async\s+)?function\b/.test(third)) return "callback";
|
|
3727
|
+
if (/^\s*\{/.test(third)) return "sync";
|
|
3728
|
+
const ident = /^\s*([A-Za-z_$][\w$]*)\s*$/.exec(third);
|
|
3729
|
+
if (!ident) return "callback";
|
|
3730
|
+
return identifierIsObjectLiteral(file, ident[1]) ? "sync" : "callback";
|
|
3731
|
+
}
|
|
3732
|
+
function syncJwtCredits(body, file) {
|
|
3733
|
+
const masked = maskStrings(body);
|
|
3734
|
+
const re = /\b([A-Za-z_$][\w$]*)\s*\.\s*verify\s*\(/g;
|
|
3735
|
+
let match;
|
|
3736
|
+
while (match = re.exec(masked)) {
|
|
3737
|
+
const span = jwtBindingSpan(file, match[1]);
|
|
3738
|
+
if (!span || bindingIsShadowed(file, match[1], span)) continue;
|
|
3739
|
+
if (verifyCallForm(masked, match.index, file) !== "sync") continue;
|
|
3740
|
+
if (!errorPathRejects(masked, match.index)) continue;
|
|
3741
|
+
return true;
|
|
3742
|
+
}
|
|
3743
|
+
return false;
|
|
3744
|
+
}
|
|
3745
|
+
var fnCacheContent = null;
|
|
3746
|
+
var fnCacheSpans = [];
|
|
3747
|
+
function headerIsFunction(content, brace) {
|
|
3748
|
+
const header = content.slice(Math.max(0, brace - 180), brace);
|
|
3749
|
+
const last = header.slice(header.lastIndexOf("\n") + 1);
|
|
3750
|
+
if (/=>\s*$/.test(last) || /\bfunction\b/.test(last)) return true;
|
|
3751
|
+
const method = /^\s*(?:(?:public|private|protected|static|async|override)\s+)*([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*(?::\s*[^{]+)?$/.exec(last);
|
|
3752
|
+
if (!method) return false;
|
|
3753
|
+
return !/^(?:if|for|while|switch|catch|function|return|else|try)$/.test(method[1]);
|
|
3754
|
+
}
|
|
3755
|
+
function buildFnSpans(content) {
|
|
3756
|
+
const spans = [];
|
|
3757
|
+
const stack = [];
|
|
3758
|
+
let quote = "";
|
|
3759
|
+
for (let i = 0; i < content.length; i++) {
|
|
3760
|
+
const c = content[i];
|
|
3761
|
+
if (quote) {
|
|
3762
|
+
if (c === "\\" && quote !== "`") {
|
|
3763
|
+
i++;
|
|
3764
|
+
continue;
|
|
3765
|
+
}
|
|
3766
|
+
if (c === quote) quote = "";
|
|
3767
|
+
else if (quote !== "`" && c === "\n") quote = "";
|
|
3768
|
+
continue;
|
|
3769
|
+
}
|
|
3770
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
3771
|
+
quote = c;
|
|
3772
|
+
continue;
|
|
3773
|
+
}
|
|
3774
|
+
if (c === "{") stack.push({ open: i, isFn: headerIsFunction(content, i) });
|
|
3775
|
+
else if (c === "}" && stack.length) {
|
|
3776
|
+
const frame = stack.pop();
|
|
3777
|
+
if (frame?.isFn) spans.push({ open: frame.open, close: i });
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
for (const frame of stack) {
|
|
3781
|
+
if (frame.isFn) spans.push({ open: frame.open, close: content.length });
|
|
3782
|
+
}
|
|
3783
|
+
return spans;
|
|
3784
|
+
}
|
|
3785
|
+
var fnPrefixMax = [];
|
|
3786
|
+
function prepareFnCache(content) {
|
|
3787
|
+
if (fnCacheContent === content) return;
|
|
3788
|
+
fnCacheContent = content;
|
|
3789
|
+
fnCacheSpans = buildFnSpans(content).sort((a, b) => a.open - b.open || a.close - b.close);
|
|
3790
|
+
fnPrefixMax = new Array(fnCacheSpans.length);
|
|
3791
|
+
for (let i = 0; i < fnCacheSpans.length; i++) {
|
|
3792
|
+
fnPrefixMax[i] = i === 0 ? fnCacheSpans[i].close : Math.max(fnPrefixMax[i - 1], fnCacheSpans[i].close);
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
function fnKeyAt(content, index) {
|
|
3796
|
+
prepareFnCache(content);
|
|
3797
|
+
const spans = fnCacheSpans;
|
|
3798
|
+
let lo = 0;
|
|
3799
|
+
let hi = spans.length - 1;
|
|
3800
|
+
let found = -1;
|
|
3801
|
+
while (lo <= hi) {
|
|
3802
|
+
const mid = lo + hi >> 1;
|
|
3803
|
+
if (spans[mid].open < index) {
|
|
3804
|
+
found = mid;
|
|
3805
|
+
lo = mid + 1;
|
|
3806
|
+
} else {
|
|
3807
|
+
hi = mid - 1;
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
for (let i = found; i >= 0; i--) {
|
|
3811
|
+
if (fnPrefixMax[i] < index) break;
|
|
3812
|
+
const span = spans[i];
|
|
3813
|
+
if (index <= span.close) {
|
|
3814
|
+
if (index - span.open > BRACE_CAP) return "exhausted";
|
|
3815
|
+
return "fn@" + span.open;
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
return "top";
|
|
3819
|
+
}
|
|
3820
|
+
function firstSideEffect(handler) {
|
|
3821
|
+
SIDE_EFFECT_RE.lastIndex = 0;
|
|
3822
|
+
const match = SIDE_EFFECT_RE.exec(handler);
|
|
3823
|
+
return match ? match.index : -1;
|
|
3824
|
+
}
|
|
3825
|
+
function beforeSideEffect(handler, index) {
|
|
3826
|
+
const at = firstSideEffect(handler);
|
|
3827
|
+
return at === -1 || index < at;
|
|
3828
|
+
}
|
|
3829
|
+
function localGuardBody(content, name) {
|
|
3830
|
+
const id = escapeRegExp(name);
|
|
3831
|
+
const fn = new RegExp(`\\b(?:async\\s+)?function\\s+${id}\\s*\\([^)]*\\)\\s*\\{`).exec(content);
|
|
3832
|
+
if (fn && fn.index !== void 0) {
|
|
3833
|
+
const brace = content.indexOf("{", fn.index);
|
|
3834
|
+
const end = matchingCloser(content, brace, "{", "}", BRACE_CAP);
|
|
3835
|
+
return end < 0 ? "" : content.slice(brace + 1, end);
|
|
3836
|
+
}
|
|
3837
|
+
const arrow = new RegExp(
|
|
3838
|
+
`\\b(?:const|let|var)\\s+${id}\\s*=\\s*(?:async\\s*)?(?:function\\s*\\([^)]*\\)|(?:\\([^)]*\\)|[A-Za-z_]\\w*)\\s*=>)`
|
|
3839
|
+
).exec(content);
|
|
3840
|
+
if (!arrow || arrow.index === void 0) return null;
|
|
3841
|
+
const after = arrow.index + arrow[0].length;
|
|
3842
|
+
const rest = content.slice(after);
|
|
3843
|
+
if (/^\s*\{/.test(rest)) {
|
|
3844
|
+
const brace = content.indexOf("{", after);
|
|
3845
|
+
const end = matchingCloser(content, brace, "{", "}", BRACE_CAP);
|
|
3846
|
+
return end < 0 ? "" : content.slice(brace + 1, end);
|
|
3847
|
+
}
|
|
3848
|
+
const semi = content.indexOf(";", after);
|
|
3849
|
+
return content.slice(after, semi === -1 ? content.length : semi);
|
|
3850
|
+
}
|
|
3851
|
+
function guardBodyQualifies(body, file) {
|
|
3852
|
+
const masked = maskStrings(body);
|
|
3853
|
+
const flat = masked.replace(/\s+/g, " ").trim();
|
|
3854
|
+
if (!flat) return false;
|
|
3855
|
+
if (/^(?:return\s+)?next\s*\(\s*\)\s*;?$/.test(flat)) return false;
|
|
3856
|
+
if (REJECT_RE.test(masked)) return true;
|
|
3857
|
+
return syncJwtCredits(body, file);
|
|
3858
|
+
}
|
|
3859
|
+
var guardCacheContent = null;
|
|
3860
|
+
var guardCache = /* @__PURE__ */ new Map();
|
|
3861
|
+
function guardNameCounts(content, name) {
|
|
3862
|
+
if (guardCacheContent !== content) {
|
|
3863
|
+
guardCacheContent = content;
|
|
3864
|
+
guardCache.clear();
|
|
3865
|
+
}
|
|
3866
|
+
const cached = guardCache.get(name);
|
|
3867
|
+
if (cached !== void 0) return cached;
|
|
3868
|
+
const body = localGuardBody(content, name);
|
|
3869
|
+
const result = body === null ? isImportedName(content, name) : guardBodyQualifies(body, content);
|
|
3870
|
+
guardCache.set(name, result);
|
|
3871
|
+
return result;
|
|
3872
|
+
}
|
|
3873
|
+
function guardMentioned(content, args) {
|
|
3874
|
+
return GUARD_NAMES.some((name) => new RegExp(`\\b${escapeRegExp(name)}\\b`).test(args) && guardNameCounts(content, name));
|
|
3875
|
+
}
|
|
3876
|
+
function handlerBodyOpen(handler) {
|
|
3877
|
+
const arrow = handler.search(/=>\s*\{/);
|
|
3878
|
+
const fn = handler.search(/\)\s*\{/);
|
|
3879
|
+
const at = [arrow, fn].filter((index) => index >= 0);
|
|
3880
|
+
if (at.length === 0) return handler.indexOf("{");
|
|
3881
|
+
return handler.indexOf("{", Math.min(...at));
|
|
3882
|
+
}
|
|
3883
|
+
function guardStatementCounts(handler, callIndex) {
|
|
3884
|
+
const bodyOpen = handlerBodyOpen(handler);
|
|
3885
|
+
if (bodyOpen < 0 || callIndex <= bodyOpen) return false;
|
|
3886
|
+
let brace = 0;
|
|
3887
|
+
let paren = 0;
|
|
3888
|
+
let bracket = 0;
|
|
3889
|
+
let quote = "";
|
|
3890
|
+
let stmtStart = bodyOpen + 1;
|
|
3891
|
+
for (let i = bodyOpen; i < callIndex; i++) {
|
|
3892
|
+
const c = handler[i];
|
|
3893
|
+
if (quote) {
|
|
3894
|
+
if (c === "\\") {
|
|
3895
|
+
i++;
|
|
3896
|
+
continue;
|
|
3897
|
+
}
|
|
3898
|
+
if (c === quote) quote = "";
|
|
3899
|
+
continue;
|
|
3900
|
+
}
|
|
3901
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
3902
|
+
quote = c;
|
|
3903
|
+
continue;
|
|
3904
|
+
}
|
|
3905
|
+
if (c === "{") {
|
|
3906
|
+
brace++;
|
|
3907
|
+
if (brace === 1) stmtStart = i + 1;
|
|
3908
|
+
} else if (c === "}") {
|
|
3909
|
+
brace--;
|
|
3910
|
+
if (brace === 1) stmtStart = i + 1;
|
|
3911
|
+
} else if (c === "(") paren++;
|
|
3912
|
+
else if (c === ")") paren--;
|
|
3913
|
+
else if (c === "[") bracket++;
|
|
3914
|
+
else if (c === "]") bracket--;
|
|
3915
|
+
else if (c === "\n" && brace === 1 && paren === 0 && bracket === 0) {
|
|
3916
|
+
let j = i - 1;
|
|
3917
|
+
while (j > bodyOpen && /[ \t\r]/.test(handler[j])) j--;
|
|
3918
|
+
const prev = handler[j] ?? "";
|
|
3919
|
+
if (!",([{+-*/=&|?:.".includes(prev)) stmtStart = i + 1;
|
|
3920
|
+
} else if (c === ";" && brace === 1 && paren === 0 && bracket === 0) stmtStart = i + 1;
|
|
3921
|
+
}
|
|
3922
|
+
if (brace !== 1 || paren !== 0 || bracket !== 0) return false;
|
|
3923
|
+
const stmt = handler.slice(stmtStart, callIndex);
|
|
3924
|
+
if (/&&|\|\||\?\?|\?(?!\.)/.test(stmt)) return false;
|
|
3925
|
+
if (/\b(?:if|else|while|for|switch|catch|try)\b/.test(stmt)) return false;
|
|
3926
|
+
if (!/\b(?:const|let|var)\b|=/.test(stmt)) return true;
|
|
3927
|
+
const assigned = lastAssignedName(stmt);
|
|
3928
|
+
if (!assigned) return false;
|
|
3929
|
+
return new RegExp(`\\b${escapeRegExp(assigned)}\\b`).test(handler.slice(callIndex + 1));
|
|
3930
|
+
}
|
|
3931
|
+
function lastAssignedName(stmt) {
|
|
3932
|
+
let name;
|
|
3933
|
+
let at = -1;
|
|
3934
|
+
for (const match of stmt.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
3935
|
+
if (match.index !== void 0 && match.index >= at) {
|
|
3936
|
+
at = match.index;
|
|
3937
|
+
name = match[1];
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
for (const match of stmt.matchAll(/([A-Za-z_$][\w$]*)\s*=(?!=)/g)) {
|
|
3941
|
+
if (match.index !== void 0 && match.index >= at) {
|
|
3942
|
+
at = match.index;
|
|
3943
|
+
name = match[1];
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
return name;
|
|
3947
|
+
}
|
|
3948
|
+
function guardCallBeforeSideEffect(content, handler) {
|
|
3949
|
+
const re = new RegExp(`\\b(${GUARD_NAMES.join("|")})\\s*\\(`, "g");
|
|
3950
|
+
let match;
|
|
3951
|
+
while (match = re.exec(handler)) {
|
|
3952
|
+
const pre = handler.slice(Math.max(0, match.index - 24), match.index);
|
|
3953
|
+
if (/\bfunction\s+$/.test(pre)) continue;
|
|
3954
|
+
if (!beforeSideEffect(handler, match.index)) continue;
|
|
3955
|
+
if (!guardStatementCounts(handler, match.index)) continue;
|
|
3956
|
+
if (guardNameCounts(content, match[1])) return true;
|
|
3957
|
+
}
|
|
3958
|
+
return false;
|
|
3959
|
+
}
|
|
3960
|
+
function routeArgsQualify(content, handler) {
|
|
3961
|
+
const match = handler.match(/\.(?:get|post|put|patch|delete|all)\s*\(\s*["'`][^"'`]+["'`]\s*,/i);
|
|
3962
|
+
if (!match || match.index === void 0) return false;
|
|
3963
|
+
const start = match.index + match[0].length;
|
|
3964
|
+
const brace = handler.indexOf("{", start);
|
|
3965
|
+
const args = handler.slice(start, brace === -1 ? handler.length : brace);
|
|
3966
|
+
return guardMentioned(content, args);
|
|
3967
|
+
}
|
|
3968
|
+
function authPrefixCovers(prefix, path) {
|
|
3969
|
+
const normalized = prefix.length > 1 ? prefix.replace(/\/+$/, "") : prefix;
|
|
3970
|
+
return path === normalized || path.startsWith(normalized + "/");
|
|
3971
|
+
}
|
|
3972
|
+
var useCacheContent = null;
|
|
3973
|
+
var useCacheByKey = /* @__PURE__ */ new Map();
|
|
3974
|
+
function usesInScope(content, key) {
|
|
3975
|
+
if (useCacheContent === content) return useCacheByKey.get(key) ?? [];
|
|
3976
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
3977
|
+
const re = /\b([A-Za-z_$][\w$]*)\s*\.\s*use\s*\(/g;
|
|
3978
|
+
let match;
|
|
3979
|
+
while (match = re.exec(content)) {
|
|
3980
|
+
const open = match.index + match[0].length - 1;
|
|
3981
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP);
|
|
3982
|
+
if (close < 0) continue;
|
|
3983
|
+
const args = content.slice(open + 1, close);
|
|
3984
|
+
const siteKey = fnKeyAt(content, match.index);
|
|
3985
|
+
const site = {
|
|
3986
|
+
index: match.index,
|
|
3987
|
+
receiver: match[1],
|
|
3988
|
+
args,
|
|
3989
|
+
first: (splitArgs(args)[0] ?? "").trim(),
|
|
3990
|
+
key: siteKey
|
|
3991
|
+
};
|
|
3992
|
+
const list = byKey.get(siteKey);
|
|
3993
|
+
if (list) list.push(site);
|
|
3994
|
+
else byKey.set(siteKey, [site]);
|
|
3995
|
+
}
|
|
3996
|
+
useCacheContent = content;
|
|
3997
|
+
useCacheByKey = byKey;
|
|
3998
|
+
return byKey.get(key) ?? [];
|
|
3999
|
+
}
|
|
4000
|
+
function useCoversRoute(content, index) {
|
|
4001
|
+
const lineStart = content.lastIndexOf("\n", Math.max(0, index - 1)) + 1;
|
|
4002
|
+
const lineEnd = content.indexOf("\n", index);
|
|
4003
|
+
const line = content.slice(lineStart, lineEnd === -1 ? content.length : lineEnd);
|
|
4004
|
+
const route = line.match(/\b([A-Za-z_$][\w$]*)\s*\.\s*(?:get|post|put|patch|delete|all)\s*\(\s*["'`]([^"'`]+)["'`]/i);
|
|
4005
|
+
if (!route) return false;
|
|
4006
|
+
const receiver = route[1];
|
|
4007
|
+
const path = route[2];
|
|
4008
|
+
const routeKey = fnKeyAt(content, index);
|
|
4009
|
+
if (routeKey === "exhausted") return false;
|
|
4010
|
+
for (const site of usesInScope(content, routeKey)) {
|
|
4011
|
+
if (site.receiver !== receiver || site.index >= lineStart) continue;
|
|
4012
|
+
const stringPrefix2 = /^\s*["'`]([^"'`]*)["'`]/.exec(site.first)?.[1];
|
|
4013
|
+
const firstIsGuard = /^[A-Za-z_$][\w$]*$/.test(site.first) && GUARD_NAMES.includes(site.first) && guardNameCounts(content, site.first);
|
|
4014
|
+
if (stringPrefix2 === void 0 && !firstIsGuard) continue;
|
|
4015
|
+
const prefix = stringPrefix2 ?? "";
|
|
4016
|
+
if (prefix && !authPrefixCovers(prefix, path)) continue;
|
|
4017
|
+
if (!guardMentioned(content, site.args) && !firstIsGuard) continue;
|
|
4018
|
+
return true;
|
|
4019
|
+
}
|
|
4020
|
+
return false;
|
|
4021
|
+
}
|
|
4022
|
+
function isAnchoredPublicAuthPath(routePath) {
|
|
4023
|
+
const parts = routePath.split("/").filter(Boolean);
|
|
4024
|
+
if (parts.length === 0) return false;
|
|
4025
|
+
const last = parts[parts.length - 1];
|
|
4026
|
+
if (!PUBLIC_LAST.test(last)) return false;
|
|
4027
|
+
if (parts.length === 1) return true;
|
|
4028
|
+
return parts[parts.length - 2].toLowerCase() === "auth";
|
|
4029
|
+
}
|
|
4030
|
+
function isOgRoutePath(routePath) {
|
|
4031
|
+
return routePath.split("/").some((part) => part.toLowerCase() === "og");
|
|
4032
|
+
}
|
|
4033
|
+
function routePathFromFile(filePath) {
|
|
4034
|
+
const norm = filePath.replace(/\\/g, "/");
|
|
4035
|
+
const app = norm.match(/(?:^|\/)app\/(.*?)\/route\.[mc]?[jt]sx?$/);
|
|
4036
|
+
if (app) return "/" + app[1];
|
|
4037
|
+
const pages = norm.match(/(?:^|\/)pages\/api\/(.*)\.[mc]?[jt]sx?$/);
|
|
4038
|
+
if (pages) return "/api/" + pages[1].replace(/\/index$/, "");
|
|
4039
|
+
return null;
|
|
4040
|
+
}
|
|
4041
|
+
function expressRoutePath(handler) {
|
|
4042
|
+
const bodyOpen = handlerBodyOpen(handler);
|
|
4043
|
+
const header = bodyOpen < 0 ? handler : handler.slice(0, bodyOpen);
|
|
4044
|
+
const match = header.match(/\b[A-Za-z_$][\w$]*\s*\.\s*(?:get|post|put|patch|delete|all)\s*\(\s*["'`](\/[^"'`]*)["'`]/i);
|
|
4045
|
+
return match ? match[1] : null;
|
|
4046
|
+
}
|
|
4047
|
+
function mutatesKeyedOnParams(handler) {
|
|
4048
|
+
const mutates = /\.(?:updateMany|updateOne|deleteMany|deleteOne|findByIdAndUpdate|findByIdAndDelete|update|delete|save|remove|destroy)\s*\(/i.test(handler) || /\b(?:UPDATE|DELETE)\b/.test(handler);
|
|
4049
|
+
if (!mutates) return false;
|
|
4050
|
+
return /\b(?:req|request|ctx)\s*\.\s*params\b|\bparams\s*\.\s*[A-Za-z_]/.test(handler);
|
|
4051
|
+
}
|
|
4052
|
+
function splitArgs(args) {
|
|
4053
|
+
const parts = [];
|
|
4054
|
+
let start = 0;
|
|
4055
|
+
let depth = 0;
|
|
4056
|
+
let quote = "";
|
|
4057
|
+
for (let i = 0; i < args.length; i++) {
|
|
4058
|
+
const c = args[i];
|
|
4059
|
+
if (quote) {
|
|
4060
|
+
if (c === "\\") {
|
|
4061
|
+
i++;
|
|
4062
|
+
continue;
|
|
4063
|
+
}
|
|
4064
|
+
if (c === quote) quote = "";
|
|
4065
|
+
continue;
|
|
4066
|
+
}
|
|
4067
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
4068
|
+
quote = c;
|
|
4069
|
+
continue;
|
|
4070
|
+
}
|
|
4071
|
+
if (c === "(" || c === "{" || c === "[") depth++;
|
|
4072
|
+
else if (c === ")" || c === "}" || c === "]") depth--;
|
|
4073
|
+
else if (c === "," && depth === 0) {
|
|
4074
|
+
parts.push(args.slice(start, i));
|
|
4075
|
+
start = i + 1;
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
parts.push(args.slice(start));
|
|
4079
|
+
return parts;
|
|
4080
|
+
}
|
|
4081
|
+
function unwrapSecret(value) {
|
|
4082
|
+
let bare = value.trim().replace(/!+$/, "").trim();
|
|
4083
|
+
for (let n = 0; n < 4; n++) {
|
|
4084
|
+
if (!bare.startsWith("(")) break;
|
|
4085
|
+
const end = matchingCloser(bare, 0, "(", ")", ARG_CAP);
|
|
4086
|
+
if (end < 0 || end !== bare.length - 1) break;
|
|
4087
|
+
bare = bare.slice(1, -1).trim().replace(/!+$/, "").trim();
|
|
4088
|
+
}
|
|
4089
|
+
return bare;
|
|
4090
|
+
}
|
|
4091
|
+
function secretValueReal(value) {
|
|
4092
|
+
const bare = unwrapSecret(value);
|
|
4093
|
+
if (bare === '""' || bare === "''" || bare === "``" || bare === "undefined" || bare === "") return false;
|
|
4094
|
+
if (/(\|\||\?\?)\s*(["'`])[^"'`]*\2\s*$/.test(bare)) return false;
|
|
4095
|
+
return true;
|
|
4096
|
+
}
|
|
4097
|
+
function secretArgOk(args) {
|
|
4098
|
+
const parts = splitArgs(args).map((part) => part.trim()).filter(Boolean);
|
|
4099
|
+
if (parts.length >= 3) return secretValueReal(parts[2]);
|
|
4100
|
+
if (parts.length === 1 && parts[0].startsWith("{")) {
|
|
4101
|
+
const prop = parts[0].match(/\b(?:secret|signingKey|currentSigningKey|token)\s*:\s*([^,}\n]+)/i);
|
|
4102
|
+
if (!prop) return false;
|
|
4103
|
+
return secretValueReal(prop[1]);
|
|
4104
|
+
}
|
|
4105
|
+
return false;
|
|
4106
|
+
}
|
|
4107
|
+
function errorPathRejects(handler, callIndex) {
|
|
4108
|
+
const tryRe = /\btry\b/g;
|
|
4109
|
+
let tryIndex = -1;
|
|
4110
|
+
let match;
|
|
4111
|
+
while (match = tryRe.exec(handler)) {
|
|
4112
|
+
if (match.index < callIndex) tryIndex = match.index;
|
|
4113
|
+
else break;
|
|
4114
|
+
}
|
|
4115
|
+
if (tryIndex < 0) return true;
|
|
4116
|
+
const catchRe = /\bcatch\b/g;
|
|
4117
|
+
catchRe.lastIndex = callIndex;
|
|
4118
|
+
const caught = catchRe.exec(handler);
|
|
4119
|
+
if (!caught) return true;
|
|
4120
|
+
const brace = handler.indexOf("{", caught.index);
|
|
4121
|
+
if (brace < 0) return false;
|
|
4122
|
+
const end = matchingCloser(handler, brace, "{", "}", BRACE_CAP);
|
|
4123
|
+
if (end < 0) return false;
|
|
4124
|
+
const body = handler.slice(brace, end);
|
|
4125
|
+
return /\bthrow\b/.test(body) || /\breturn\b/.test(body) && /\b4\d\d\b/.test(body);
|
|
4126
|
+
}
|
|
4127
|
+
function signatureCheckQualifies(handler) {
|
|
4128
|
+
const callRe = /(?:\bconstructEvent|\bverifyQstashSignature)\s*\(/g;
|
|
4129
|
+
let match;
|
|
4130
|
+
while (match = callRe.exec(handler)) {
|
|
4131
|
+
const open = match.index + match[0].length - 1;
|
|
4132
|
+
const close = matchingCloser(handler, open, "(", ")", ARG_CAP);
|
|
4133
|
+
if (close < 0) continue;
|
|
4134
|
+
const args = handler.slice(open + 1, close);
|
|
4135
|
+
if (!/\.text\s*\(/.test(handler) && !/\.text\s*\(/.test(args)) continue;
|
|
4136
|
+
if (!/stripe-signature|upstash-signature/i.test(handler)) continue;
|
|
4137
|
+
if (!secretArgOk(args)) continue;
|
|
4138
|
+
if (!beforeSideEffect(handler, match.index)) continue;
|
|
4139
|
+
if (!errorPathRejects(handler, match.index)) continue;
|
|
4140
|
+
return true;
|
|
4141
|
+
}
|
|
4142
|
+
return false;
|
|
4143
|
+
}
|
|
4144
|
+
function ifBranchBody(handler, closeParen) {
|
|
4145
|
+
let i = closeParen + 1;
|
|
4146
|
+
while (i < handler.length && /\s/.test(handler[i])) i++;
|
|
4147
|
+
if (i >= handler.length) return null;
|
|
4148
|
+
if (handler[i] === "{") {
|
|
4149
|
+
const end = matchingCloser(handler, i, "{", "}", IF_BODY_CAP);
|
|
4150
|
+
if (end < 0) return null;
|
|
4151
|
+
return handler.slice(i + 1, end);
|
|
4152
|
+
}
|
|
4153
|
+
const limit = Math.min(handler.length, i + IF_BODY_CAP);
|
|
4154
|
+
const semi = handler.indexOf(";", i);
|
|
4155
|
+
if (semi < 0 || semi >= limit) return null;
|
|
4156
|
+
return handler.slice(i, semi);
|
|
4157
|
+
}
|
|
4158
|
+
function branchRejects401(body) {
|
|
4159
|
+
return /\breturn\b/.test(body) && /\b401\b/.test(body) || /\b(?:status|sendStatus)\s*\(\s*401\b/.test(body);
|
|
4160
|
+
}
|
|
4161
|
+
function cronSecretGates(handler) {
|
|
4162
|
+
const re = /\bif\s*\(/g;
|
|
4163
|
+
let match;
|
|
4164
|
+
while (match = re.exec(handler)) {
|
|
4165
|
+
const open = match.index + match[0].length - 1;
|
|
4166
|
+
const close = matchingCloser(handler, open, "(", ")", ARG_CAP);
|
|
4167
|
+
if (close < 0) continue;
|
|
4168
|
+
const cond = handler.slice(open + 1, close);
|
|
4169
|
+
if (!/\bCRON_SECRET\b/.test(cond)) continue;
|
|
4170
|
+
if (/CRON_SECRET\s*(?:&&|\?)/.test(cond)) continue;
|
|
4171
|
+
if (!/(?:!==|!=(?!=))/.test(cond)) continue;
|
|
4172
|
+
if (!beforeSideEffect(handler, match.index)) continue;
|
|
4173
|
+
const body = ifBranchBody(handler, close);
|
|
4174
|
+
if (body && branchRejects401(body)) return true;
|
|
4175
|
+
}
|
|
4176
|
+
return false;
|
|
4177
|
+
}
|
|
4178
|
+
function handlerVerb(content, index, _handler) {
|
|
2328
4179
|
const lineStart = content.lastIndexOf("\n", Math.max(0, index - 1)) + 1;
|
|
2329
|
-
const lineEnd = content.indexOf("\n", index);
|
|
4180
|
+
const lineEnd = content.indexOf("\n", Math.max(index, lineStart));
|
|
2330
4181
|
const line = content.slice(lineStart, lineEnd === -1 ? content.length : lineEnd);
|
|
2331
|
-
const
|
|
2332
|
-
if (
|
|
2333
|
-
const
|
|
2334
|
-
const
|
|
2335
|
-
const
|
|
4182
|
+
const registered = line.match(/\b[A-Za-z_$][\w$]*\s*\.\s*(get|head|post|put|patch|delete|all)\s*\(\s*["'`]/i);
|
|
4183
|
+
if (registered) return registered[1].toLowerCase();
|
|
4184
|
+
const windowStart = Math.max(0, index - 120);
|
|
4185
|
+
const window = content.slice(windowStart, index + 180);
|
|
4186
|
+
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;
|
|
4187
|
+
let best = null;
|
|
2336
4188
|
let match;
|
|
2337
|
-
while (match =
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
const
|
|
2341
|
-
if (
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
4189
|
+
while (match = re.exec(window)) {
|
|
4190
|
+
const at = windowStart + match.index;
|
|
4191
|
+
if (at > index) continue;
|
|
4192
|
+
const verb = (match[1] || match[2]).toLowerCase();
|
|
4193
|
+
if (!best || Math.abs(at - index) < Math.abs(best.at - index)) best = { at, verb };
|
|
4194
|
+
}
|
|
4195
|
+
return best ? best.verb : null;
|
|
4196
|
+
}
|
|
4197
|
+
var authFaultForTest = false;
|
|
4198
|
+
function widenedAuthSuppressesBody(content, filePath, index, handler) {
|
|
4199
|
+
if (!handler) return false;
|
|
4200
|
+
const masked = blankComments(content);
|
|
4201
|
+
const maskedHandler = blankComments(handler);
|
|
4202
|
+
prepareFnCache(masked);
|
|
4203
|
+
if (guardCallBeforeSideEffect(masked, maskedHandler)) return true;
|
|
4204
|
+
if (routeArgsQualify(masked, maskedHandler)) return true;
|
|
4205
|
+
if (useCoversRoute(masked, index)) return true;
|
|
4206
|
+
const routePath = routePathFromFile(filePath) ?? expressRoutePath(maskedHandler);
|
|
4207
|
+
if (routePath && isAnchoredPublicAuthPath(routePath) && !mutatesKeyedOnParams(maskedHandler)) return true;
|
|
4208
|
+
if (routePath && isOgRoutePath(routePath)) {
|
|
4209
|
+
const verb = handlerVerb(masked, index, maskedHandler);
|
|
4210
|
+
if (verb === "get" || verb === "head") return true;
|
|
2346
4211
|
}
|
|
4212
|
+
if (signatureCheckQualifies(maskedHandler)) return true;
|
|
4213
|
+
if (cronSecretGates(maskedHandler)) return true;
|
|
2347
4214
|
return false;
|
|
2348
4215
|
}
|
|
2349
|
-
function
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
4216
|
+
function widenedAuthSuppresses(content, filePath, index, handler, rawContent, capability = false, strictApp = false) {
|
|
4217
|
+
try {
|
|
4218
|
+
if (authFaultForTest) throw new Error("injected");
|
|
4219
|
+
if (widenedAuthSuppressesBody(content, filePath, index, handler)) return true;
|
|
4220
|
+
if (!rawContent) return false;
|
|
4221
|
+
if (publicReadOnlyHandler(rawContent, filePath, index, strictApp)) return true;
|
|
4222
|
+
return capability && capabilityTokenHandler(rawContent, filePath, index);
|
|
4223
|
+
} catch {
|
|
4224
|
+
return false;
|
|
4225
|
+
}
|
|
2356
4226
|
}
|
|
2357
|
-
|
|
2358
|
-
|
|
4227
|
+
|
|
4228
|
+
// src/weak-hash.ts
|
|
4229
|
+
var ARG_CAP2 = 300;
|
|
4230
|
+
var PF_RE = /password|passwd|passphrase|pwd/;
|
|
4231
|
+
var TOKEN_WORDS = ["token", "code", "otp", "nonce"];
|
|
4232
|
+
var RESET_WORDS = ["reset", "forgot", "recover"];
|
|
4233
|
+
var HASH_VERBS = ["hash", "encrypt", "digest", "verify"];
|
|
4234
|
+
var KEY_BLOCK = ["token", "code", "otp", "nonce", "reset", "forgot", "recover"];
|
|
4235
|
+
function escapeRegExp2(value) {
|
|
4236
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4237
|
+
}
|
|
4238
|
+
function nameTokens(text) {
|
|
4239
|
+
const out = [];
|
|
4240
|
+
for (const part of text.split(/[^A-Za-z0-9]+/)) {
|
|
4241
|
+
if (!part) continue;
|
|
4242
|
+
const bits = part.split(
|
|
4243
|
+
/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[A-Za-z])(?=\d)|(?<=\d)(?=[A-Za-z])/
|
|
4244
|
+
);
|
|
4245
|
+
for (const bit of bits) if (bit) out.push(bit.toLowerCase());
|
|
4246
|
+
const lower = part.toLowerCase();
|
|
4247
|
+
if (PF_RE.test(lower) && !lower.includes("passwordless") && !bits.some((bit) => bit && PF_RE.test(bit.toLowerCase()))) {
|
|
4248
|
+
out.push(lower);
|
|
4249
|
+
}
|
|
4250
|
+
}
|
|
4251
|
+
return out;
|
|
2359
4252
|
}
|
|
2360
|
-
function
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
4253
|
+
function isPf(token) {
|
|
4254
|
+
return PF_RE.test(token) && !token.includes("passwordless");
|
|
4255
|
+
}
|
|
4256
|
+
function wordIn(tokens, word) {
|
|
4257
|
+
if (tokens.some((token) => token === word)) return true;
|
|
4258
|
+
return tokens.some((token) => isPf(token) && token.includes(word));
|
|
4259
|
+
}
|
|
4260
|
+
function hasPf(text) {
|
|
4261
|
+
return nameTokens(text).some(isPf);
|
|
4262
|
+
}
|
|
4263
|
+
var TOKEN_PARTS = /* @__PURE__ */ new Set(["token", "code", "otp", "nonce"]);
|
|
4264
|
+
var METHOD_NAMES = /* @__PURE__ */ new Set(["encode", "hexdigest", "toString"]);
|
|
4265
|
+
var RUN_TOGETHER = /^(?:reset|forgot|recover|change)?(?:password|passwd|passphrase|pwd)(?:reset|forgot|recover|change)?(?:token|code|otp|nonce)$/;
|
|
4266
|
+
function languageOf(filePath) {
|
|
4267
|
+
if (filePath.endsWith(".py")) return "py";
|
|
4268
|
+
if (filePath.endsWith(".rb")) return "rb";
|
|
4269
|
+
return "js";
|
|
4270
|
+
}
|
|
4271
|
+
function namesIn(text) {
|
|
4272
|
+
const names = [];
|
|
4273
|
+
const re = /[A-Za-z_$][\w$]*/g;
|
|
4274
|
+
let match;
|
|
4275
|
+
while (match = re.exec(text)) {
|
|
4276
|
+
if (!METHOD_NAMES.has(match[0])) names.push(match[0]);
|
|
4277
|
+
}
|
|
4278
|
+
return names;
|
|
4279
|
+
}
|
|
4280
|
+
function nameHasPassword(name) {
|
|
4281
|
+
return nameTokens(name).some(isPf);
|
|
4282
|
+
}
|
|
4283
|
+
function nameHasToken(name) {
|
|
4284
|
+
const parts = nameTokens(name);
|
|
4285
|
+
if (parts.some((part) => TOKEN_PARTS.has(part))) return true;
|
|
4286
|
+
return name === name.toLowerCase() && RUN_TOGETHER.test(name);
|
|
4287
|
+
}
|
|
4288
|
+
function argumentHasPasswordOnly(expr) {
|
|
4289
|
+
return namesIn(expr).some((name) => nameHasPassword(name) && !nameHasToken(name));
|
|
4290
|
+
}
|
|
4291
|
+
function argumentGivesTokenCredit(expr) {
|
|
4292
|
+
const names = namesIn(expr);
|
|
4293
|
+
if (names.some((name) => nameHasPassword(name) && !nameHasToken(name))) return false;
|
|
4294
|
+
return names.some((name) => nameHasToken(name));
|
|
4295
|
+
}
|
|
4296
|
+
function isTokenValue(expr) {
|
|
4297
|
+
return argumentGivesTokenCredit(expr);
|
|
4298
|
+
}
|
|
4299
|
+
function containsPasswordWord(text) {
|
|
4300
|
+
const lower = text.toLowerCase().replace(/passwordless/g, "");
|
|
4301
|
+
return PF_RE.test(lower);
|
|
4302
|
+
}
|
|
4303
|
+
function isBracketKey(raw, start, end) {
|
|
4304
|
+
let j = start - 1;
|
|
4305
|
+
while (j >= 0 && /\s/.test(raw[j])) j--;
|
|
4306
|
+
if (j < 0 || raw[j] !== "[") return false;
|
|
4307
|
+
const prev = raw[j - 1] ?? "";
|
|
4308
|
+
const prev2 = raw[j - 2] ?? "";
|
|
4309
|
+
const member = /[A-Za-z0-9_$)\]]/.test(prev) || prev === "." && prev2 === "?";
|
|
4310
|
+
if (!member) return false;
|
|
4311
|
+
let a = end + 1;
|
|
4312
|
+
while (a < raw.length && /\s/.test(raw[a])) a++;
|
|
4313
|
+
return raw[a] === "]";
|
|
4314
|
+
}
|
|
4315
|
+
function isLookupCallArg(raw, start, end) {
|
|
4316
|
+
if (!/(?:\.(?:get|getItem|getAttribute|param)\s*\(\s*)$/.test(raw.slice(0, start))) return false;
|
|
4317
|
+
let a = end + 1;
|
|
4318
|
+
while (a < raw.length && /\s/.test(raw[a])) a++;
|
|
4319
|
+
return raw[a] === ")";
|
|
4320
|
+
}
|
|
4321
|
+
function applyString(chars, raw, open, close, content, lookup) {
|
|
4322
|
+
const ident = /^[A-Za-z_$][\w$]*$/.test(content);
|
|
4323
|
+
if (lookup && ident) {
|
|
4324
|
+
chars[open] = " ";
|
|
4325
|
+
chars[close] = " ";
|
|
4326
|
+
return;
|
|
4327
|
+
}
|
|
4328
|
+
if (lookup && containsPasswordWord(content)) {
|
|
4329
|
+
const marker = "pwd";
|
|
4330
|
+
for (let k = open; k <= close; k++) if (chars[k] !== "\n") chars[k] = " ";
|
|
4331
|
+
for (let k = 0; k < marker.length && open + 1 + k < close; k++) chars[open + 1 + k] = marker[k];
|
|
4332
|
+
return;
|
|
4333
|
+
}
|
|
4334
|
+
for (let k = open; k <= close; k++) if (chars[k] !== "\n") chars[k] = " ";
|
|
4335
|
+
}
|
|
4336
|
+
function stringPrefix(chars, quoteAt) {
|
|
4337
|
+
for (let len = 2; len >= 1; len--) {
|
|
4338
|
+
if (quoteAt - len < 0) continue;
|
|
4339
|
+
let ok = true;
|
|
4340
|
+
for (let j = 1; j <= len; j++) {
|
|
4341
|
+
if (!/[rRbBuUfF]/.test(chars[quoteAt - j] ?? "")) ok = false;
|
|
4342
|
+
}
|
|
4343
|
+
const before = chars[quoteAt - len - 1] ?? "";
|
|
4344
|
+
if (before && /[A-Za-z0-9_]/.test(before)) ok = false;
|
|
4345
|
+
if (ok) return len;
|
|
4346
|
+
}
|
|
4347
|
+
return 0;
|
|
4348
|
+
}
|
|
4349
|
+
function maskArgument(raw, lang) {
|
|
4350
|
+
const chars = raw.split("");
|
|
4351
|
+
const n = chars.length;
|
|
4352
|
+
let i = 0;
|
|
4353
|
+
const blank = (from, to) => {
|
|
4354
|
+
for (let k = from; k < to && k < n; k++) if (chars[k] !== "\n") chars[k] = " ";
|
|
4355
|
+
};
|
|
4356
|
+
while (i < n) {
|
|
4357
|
+
if (lang === "js" && chars[i] === "/" && chars[i + 1] === "/") {
|
|
4358
|
+
const start = i;
|
|
4359
|
+
while (i < n && chars[i] !== "\n") i++;
|
|
4360
|
+
blank(start, i);
|
|
4361
|
+
continue;
|
|
4362
|
+
}
|
|
4363
|
+
if (lang === "js" && chars[i] === "/" && chars[i + 1] === "*") {
|
|
4364
|
+
const start = i;
|
|
4365
|
+
i += 2;
|
|
4366
|
+
while (i < n && !(chars[i] === "*" && chars[i + 1] === "/")) i++;
|
|
4367
|
+
if (i < n) i += 2;
|
|
4368
|
+
blank(start, i);
|
|
4369
|
+
continue;
|
|
4370
|
+
}
|
|
4371
|
+
if ((lang === "py" || lang === "rb") && chars[i] === "#") {
|
|
4372
|
+
const start = i;
|
|
4373
|
+
while (i < n && chars[i] !== "\n") i++;
|
|
4374
|
+
blank(start, i);
|
|
4375
|
+
continue;
|
|
4376
|
+
}
|
|
4377
|
+
const quote = chars[i];
|
|
4378
|
+
const prefix = quote === "'" || quote === '"' ? stringPrefix(chars, i) : 0;
|
|
4379
|
+
const fstring = prefix > 0 && /[fF]/.test(chars.slice(i - prefix, i).join(""));
|
|
4380
|
+
if ((quote === "'" || quote === '"') && i + 2 < n && chars[i + 1] === quote && chars[i + 2] === quote) {
|
|
4381
|
+
const start = i - prefix;
|
|
4382
|
+
i += 3;
|
|
4383
|
+
const keptTriple = [];
|
|
4384
|
+
while (i + 2 < n && !(chars[i] === quote && chars[i + 1] === quote && chars[i + 2] === quote)) {
|
|
4385
|
+
if (fstring && chars[i] === "{") {
|
|
4386
|
+
const from = i;
|
|
4387
|
+
let depth = 1;
|
|
4388
|
+
i++;
|
|
4389
|
+
while (i < n && depth > 0) {
|
|
4390
|
+
if (chars[i] === "{") depth++;
|
|
4391
|
+
else if (chars[i] === "}") depth--;
|
|
4392
|
+
i++;
|
|
4393
|
+
}
|
|
4394
|
+
keptTriple.push([from, i]);
|
|
4395
|
+
continue;
|
|
4396
|
+
}
|
|
4397
|
+
if (lang === "rb" && quote === '"' && chars[i] === "#" && chars[i + 1] === "{") {
|
|
4398
|
+
i += 2;
|
|
4399
|
+
let depth = 1;
|
|
4400
|
+
while (i < n && depth > 0) {
|
|
4401
|
+
if (chars[i] === "{") depth++;
|
|
4402
|
+
else if (chars[i] === "}") depth--;
|
|
4403
|
+
i++;
|
|
4404
|
+
}
|
|
4405
|
+
continue;
|
|
4406
|
+
}
|
|
4407
|
+
i++;
|
|
4408
|
+
}
|
|
4409
|
+
const end = Math.min(n, i + 3);
|
|
4410
|
+
blank(start, end);
|
|
4411
|
+
for (const [from, to] of keptTriple) {
|
|
4412
|
+
for (let k = from; k < to && k < n; k++) chars[k] = raw[k];
|
|
4413
|
+
}
|
|
4414
|
+
i = end;
|
|
4415
|
+
continue;
|
|
4416
|
+
}
|
|
4417
|
+
if (quote === "'" || quote === '"') {
|
|
4418
|
+
const start = i - prefix;
|
|
4419
|
+
i++;
|
|
4420
|
+
const kept = [];
|
|
4421
|
+
while (i < n) {
|
|
4422
|
+
if (chars[i] === "\\") {
|
|
4423
|
+
i += 2;
|
|
4424
|
+
continue;
|
|
4425
|
+
}
|
|
4426
|
+
if (chars[i] === "\n") break;
|
|
4427
|
+
if (fstring && chars[i] === "{") {
|
|
4428
|
+
const from = i;
|
|
4429
|
+
let depth = 1;
|
|
4430
|
+
i++;
|
|
4431
|
+
while (i < n && depth > 0) {
|
|
4432
|
+
if (chars[i] === "{") depth++;
|
|
4433
|
+
else if (chars[i] === "}") depth--;
|
|
4434
|
+
i++;
|
|
4435
|
+
}
|
|
4436
|
+
kept.push([from, i]);
|
|
4437
|
+
continue;
|
|
4438
|
+
}
|
|
4439
|
+
if (lang === "rb" && quote === '"' && chars[i] === "#" && chars[i + 1] === "{") {
|
|
4440
|
+
const from = i;
|
|
4441
|
+
i += 2;
|
|
4442
|
+
let depth = 1;
|
|
4443
|
+
while (i < n && depth > 0) {
|
|
4444
|
+
if (chars[i] === "{") depth++;
|
|
4445
|
+
else if (chars[i] === "}") depth--;
|
|
4446
|
+
i++;
|
|
4447
|
+
}
|
|
4448
|
+
kept.push([from, i]);
|
|
4449
|
+
continue;
|
|
4450
|
+
}
|
|
4451
|
+
if (chars[i] === quote) break;
|
|
4452
|
+
i++;
|
|
4453
|
+
}
|
|
4454
|
+
const end = i < n && chars[i] === quote ? i : i;
|
|
4455
|
+
if (kept.length === 0 && end < n && chars[end] === quote) {
|
|
4456
|
+
const content = raw.slice(start + prefix + 1, end);
|
|
4457
|
+
const lookup = isBracketKey(raw, start + prefix, end) || isLookupCallArg(raw, start + prefix, end);
|
|
4458
|
+
applyString(chars, raw, start, end, content, lookup);
|
|
4459
|
+
} else {
|
|
4460
|
+
blank(start, end + (end < n && chars[end] === quote ? 1 : 0));
|
|
4461
|
+
for (const [from, to] of kept) {
|
|
4462
|
+
for (let k = from; k < to; k++) chars[k] = raw[k];
|
|
4463
|
+
}
|
|
4464
|
+
}
|
|
4465
|
+
i = end < n && chars[end] === quote ? end + 1 : end;
|
|
4466
|
+
continue;
|
|
4467
|
+
}
|
|
4468
|
+
if (quote === "`") {
|
|
4469
|
+
const start = i;
|
|
4470
|
+
i++;
|
|
4471
|
+
const kept = [];
|
|
4472
|
+
while (i < n) {
|
|
4473
|
+
if (chars[i] === "\\") {
|
|
4474
|
+
i += 2;
|
|
4475
|
+
continue;
|
|
4476
|
+
}
|
|
4477
|
+
if (chars[i] === "`") break;
|
|
4478
|
+
if (chars[i] === "$" && chars[i + 1] === "{") {
|
|
4479
|
+
const from = i;
|
|
4480
|
+
i += 2;
|
|
4481
|
+
let depth = 1;
|
|
4482
|
+
while (i < n && depth > 0) {
|
|
4483
|
+
if (chars[i] === "{") depth++;
|
|
4484
|
+
else if (chars[i] === "}") depth--;
|
|
4485
|
+
i++;
|
|
4486
|
+
}
|
|
4487
|
+
kept.push([from, i]);
|
|
4488
|
+
continue;
|
|
4489
|
+
}
|
|
4490
|
+
i++;
|
|
4491
|
+
}
|
|
4492
|
+
const end = i < n && chars[i] === "`" ? i : i;
|
|
4493
|
+
blank(start, end + (end < n && chars[end] === "`" ? 1 : 0));
|
|
4494
|
+
for (const [from, to] of kept) {
|
|
4495
|
+
for (let k = from; k < to; k++) chars[k] = raw[k];
|
|
4496
|
+
}
|
|
4497
|
+
i = end < n && chars[end] === "`" ? end + 1 : end;
|
|
4498
|
+
continue;
|
|
4499
|
+
}
|
|
4500
|
+
i++;
|
|
4501
|
+
}
|
|
4502
|
+
return chars.join("");
|
|
4503
|
+
}
|
|
4504
|
+
function digestLhsNames(content, digestAt) {
|
|
4505
|
+
const lineStart = content.lastIndexOf("\n", Math.max(0, digestAt - 1)) + 1;
|
|
4506
|
+
const line = content.slice(lineStart, digestAt);
|
|
4507
|
+
const assigned = /([A-Za-z_@][\w.]*)\s*=\s*$/.exec(line);
|
|
4508
|
+
if (!assigned) return [];
|
|
4509
|
+
return assigned[1].split(".").map((part) => part.replace(/^@/, "")).filter(Boolean);
|
|
4510
|
+
}
|
|
4511
|
+
function pushCall(content, open, items, veto, emptySkips) {
|
|
4512
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
4513
|
+
if (close < 0) {
|
|
4514
|
+
items.push({ kind: "fail", text: "", veto });
|
|
4515
|
+
return;
|
|
4516
|
+
}
|
|
4517
|
+
const raw = content.slice(open + 1, close);
|
|
4518
|
+
if (raw.trim() === "") {
|
|
4519
|
+
items.push({ kind: emptySkips ? "skip" : "fail", text: "", veto });
|
|
4520
|
+
return;
|
|
4521
|
+
}
|
|
4522
|
+
items.push({ kind: "arg", text: raw, veto });
|
|
4523
|
+
}
|
|
4524
|
+
function scopeSlice(slice, lang, hitIndent) {
|
|
4525
|
+
if (lang !== "js") {
|
|
4526
|
+
const re = /\n([ \t]*)(?:async[ \t]+)?(?:def|class)[ \t]/g;
|
|
4527
|
+
let m;
|
|
4528
|
+
while (m = re.exec(slice)) {
|
|
4529
|
+
const head = slice.slice(0, m.index);
|
|
4530
|
+
if ((head.split('"""').length - 1) % 2 === 1 || (head.split("'''").length - 1) % 2 === 1) continue;
|
|
4531
|
+
if (m[1].length < hitIndent) return slice.slice(0, m.index);
|
|
4532
|
+
}
|
|
4533
|
+
return slice;
|
|
4534
|
+
}
|
|
4535
|
+
let depth = 0, paren = 0, q = "";
|
|
4536
|
+
for (let i = 0; i < slice.length; i++) {
|
|
4537
|
+
const c = slice[i];
|
|
4538
|
+
if (q) {
|
|
4539
|
+
if (c === "\\") i++;
|
|
4540
|
+
else if (c === q) q = "";
|
|
4541
|
+
continue;
|
|
4542
|
+
}
|
|
4543
|
+
if (c === "'" || c === '"' || c === "`") q = c;
|
|
4544
|
+
else if (c === "(") paren++;
|
|
4545
|
+
else if (c === ")") paren--;
|
|
4546
|
+
else if (paren <= 0 && c === "{") depth++;
|
|
4547
|
+
else if (paren <= 0 && c === "}" && --depth < 0) return slice.slice(0, i);
|
|
4548
|
+
}
|
|
4549
|
+
return slice;
|
|
4550
|
+
}
|
|
4551
|
+
function collectArguments(content, lineStart, filePath) {
|
|
4552
|
+
const scanEnd = Math.min(content.length, lineStart + ARG_CAP2 + 40);
|
|
4553
|
+
const hitIndent = (/^[ \t]*/.exec(content.slice(lineStart)) ?? [""])[0].length;
|
|
4554
|
+
const slice = scopeSlice(content.slice(lineStart, scanEnd), languageOf(filePath), hitIndent);
|
|
4555
|
+
const items = [];
|
|
4556
|
+
const updateRe = /\.update\s*\(/g;
|
|
4557
|
+
let match;
|
|
4558
|
+
while (match = updateRe.exec(slice)) {
|
|
4559
|
+
if (match.index >= ARG_CAP2) break;
|
|
4560
|
+
const open = lineStart + match.index + match[0].lastIndexOf("(");
|
|
4561
|
+
pushCall(content, open, items, [], false);
|
|
4562
|
+
}
|
|
4563
|
+
const ctorRe = /hashlib\s*\.\s*[A-Za-z_]\w*\s*\(|Digest::[A-Za-z0-9_]+\s*\.\s*hexdigest\s*\(/g;
|
|
4564
|
+
while (match = ctorRe.exec(slice)) {
|
|
4565
|
+
if (match.index >= ARG_CAP2) break;
|
|
4566
|
+
const at = lineStart + match.index;
|
|
4567
|
+
const open = at + match[0].lastIndexOf("(");
|
|
4568
|
+
const veto = match[0].includes("Digest") ? digestLhsNames(content, at) : [];
|
|
4569
|
+
pushCall(content, open, items, veto, true);
|
|
4570
|
+
}
|
|
4571
|
+
const lang = languageOf(filePath);
|
|
4572
|
+
return items.map((item) => item.kind === "arg" ? { ...item, text: maskArgument(item.text, lang) } : item);
|
|
4573
|
+
}
|
|
4574
|
+
function gatherTokenDecision(content, lineStart, filePath) {
|
|
4575
|
+
const items = collectArguments(content, lineStart, filePath);
|
|
4576
|
+
const veto = items.flatMap((item) => item.veto);
|
|
4577
|
+
if (veto.some((name) => nameHasPassword(name) && !nameHasToken(name))) return false;
|
|
4578
|
+
const kept = items.filter((item) => item.kind !== "skip");
|
|
4579
|
+
if (kept.length === 0) return false;
|
|
4580
|
+
if (kept.some((item) => item.kind === "fail")) return false;
|
|
4581
|
+
if (kept.some((item) => argumentHasPasswordOnly(item.text))) return false;
|
|
4582
|
+
return kept.every((item) => argumentGivesTokenCredit(item.text));
|
|
4583
|
+
}
|
|
4584
|
+
function blocked(text, words) {
|
|
4585
|
+
const tokens = nameTokens(text);
|
|
4586
|
+
return words.some((word) => wordIn(tokens, word));
|
|
4587
|
+
}
|
|
4588
|
+
function namedHasher(name, expr, tokenIs) {
|
|
4589
|
+
if (!hasPf(name)) return false;
|
|
4590
|
+
const token = tokenIs === void 0 ? isTokenValue(expr) : tokenIs;
|
|
4591
|
+
if (blocked(name, RESET_WORDS) && token) return false;
|
|
4592
|
+
return true;
|
|
4593
|
+
}
|
|
4594
|
+
function hasHashVerb(name) {
|
|
4595
|
+
const tokens = nameTokens(name);
|
|
4596
|
+
return HASH_VERBS.some((word) => wordIn(tokens, word));
|
|
4597
|
+
}
|
|
4598
|
+
function perCallKeeps(name, expr, tokenIs) {
|
|
4599
|
+
const token = tokenIs === void 0 ? isTokenValue(expr) : tokenIs;
|
|
4600
|
+
if (token) return namedHasher(name, expr, token) && hasHashVerb(name);
|
|
4601
|
+
return hasPf(expr) || namedHasher(name, expr, token);
|
|
4602
|
+
}
|
|
4603
|
+
function hashedExprAt(content, index) {
|
|
4604
|
+
const slice = content.slice(index, index + ARG_CAP2);
|
|
4605
|
+
const updateAt = slice.search(/\.update\s*\(/);
|
|
4606
|
+
if (updateAt >= 0) {
|
|
4607
|
+
const open = index + slice.indexOf("(", updateAt);
|
|
4608
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
4609
|
+
return close < 0 ? "" : content.slice(open + 1, close);
|
|
4610
|
+
}
|
|
4611
|
+
const libAt = slice.search(/hashlib\s*\.\s*(?:md5|sha1|sha256)\s*\(/);
|
|
4612
|
+
if (libAt >= 0) {
|
|
4613
|
+
const open = index + slice.indexOf("(", libAt);
|
|
4614
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
4615
|
+
return close < 0 ? "" : content.slice(open + 1, close);
|
|
4616
|
+
}
|
|
4617
|
+
return slice.slice(0, 160);
|
|
4618
|
+
}
|
|
4619
|
+
var METHOD_RE = /^\s*(?:(?:public|private|protected|static|async|override)\s+)*([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*(?::\s*[^{]+)?$/;
|
|
4620
|
+
var METHOD_SKIP = /* @__PURE__ */ new Set(["if", "for", "while", "switch", "catch", "function", "return"]);
|
|
4621
|
+
function methodHeaderName(header) {
|
|
4622
|
+
const last = header.slice(header.lastIndexOf("\n") + 1);
|
|
4623
|
+
const method = METHOD_RE.exec(last);
|
|
4624
|
+
if (!method || METHOD_SKIP.has(method[1])) return "";
|
|
4625
|
+
return method[1];
|
|
4626
|
+
}
|
|
4627
|
+
var memo = null;
|
|
4628
|
+
var helperFault = false;
|
|
4629
|
+
function lineStartsOf(content) {
|
|
4630
|
+
const starts = [0];
|
|
4631
|
+
for (let i = 0; i < content.length; i++) if (content[i] === "\n") starts.push(i + 1);
|
|
4632
|
+
return starts;
|
|
4633
|
+
}
|
|
4634
|
+
function lineNoAt(content, index) {
|
|
4635
|
+
const starts = memo && memo.content === content ? memo.lineStarts : lineStartsOf(content);
|
|
4636
|
+
let lo = 0;
|
|
4637
|
+
let hi = starts.length - 1;
|
|
4638
|
+
while (lo < hi) {
|
|
4639
|
+
const mid = lo + hi + 1 >> 1;
|
|
4640
|
+
if (starts[mid] <= index) lo = mid;
|
|
4641
|
+
else hi = mid - 1;
|
|
4642
|
+
}
|
|
4643
|
+
return lo + 1;
|
|
4644
|
+
}
|
|
4645
|
+
function maskCallSites(content, py) {
|
|
4646
|
+
const chars = content.split("");
|
|
4647
|
+
let i = 0;
|
|
4648
|
+
const blankUntil = (pred) => {
|
|
4649
|
+
while (i < chars.length && !pred(i)) {
|
|
4650
|
+
if (chars[i] !== "\n") chars[i] = " ";
|
|
4651
|
+
i++;
|
|
4652
|
+
}
|
|
4653
|
+
};
|
|
4654
|
+
while (i < chars.length) {
|
|
4655
|
+
const c = chars[i];
|
|
4656
|
+
if (!py && c === "/" && chars[i + 1] === "/") {
|
|
4657
|
+
while (i < chars.length && chars[i] !== "\n") {
|
|
4658
|
+
chars[i] = " ";
|
|
4659
|
+
i++;
|
|
4660
|
+
}
|
|
4661
|
+
continue;
|
|
4662
|
+
}
|
|
4663
|
+
if (!py && c === "/" && chars[i + 1] === "*") {
|
|
4664
|
+
chars[i] = " ";
|
|
4665
|
+
chars[i + 1] = " ";
|
|
4666
|
+
i += 2;
|
|
4667
|
+
blankUntil((n) => chars[n] === "*" && chars[n + 1] === "/");
|
|
4668
|
+
if (i < chars.length) {
|
|
4669
|
+
chars[i] = " ";
|
|
4670
|
+
chars[i + 1] = " ";
|
|
4671
|
+
i += 2;
|
|
4672
|
+
}
|
|
4673
|
+
continue;
|
|
4674
|
+
}
|
|
4675
|
+
if (py && c === "#") {
|
|
4676
|
+
while (i < chars.length && chars[i] !== "\n") {
|
|
4677
|
+
chars[i] = " ";
|
|
4678
|
+
i++;
|
|
4679
|
+
}
|
|
4680
|
+
continue;
|
|
4681
|
+
}
|
|
4682
|
+
if ((c === '"' || c === "'") && chars[i + 1] === c && chars[i + 2] === c) {
|
|
4683
|
+
const q = c;
|
|
4684
|
+
chars[i] = chars[i + 1] = chars[i + 2] = " ";
|
|
4685
|
+
i += 3;
|
|
4686
|
+
blankUntil((n) => chars[n] === q && chars[n + 1] === q && chars[n + 2] === q);
|
|
4687
|
+
if (i < chars.length) {
|
|
4688
|
+
chars[i] = chars[i + 1] = chars[i + 2] = " ";
|
|
4689
|
+
i += 3;
|
|
4690
|
+
}
|
|
4691
|
+
continue;
|
|
4692
|
+
}
|
|
4693
|
+
if (c === "'" || c === '"') {
|
|
4694
|
+
const q = c;
|
|
4695
|
+
chars[i] = " ";
|
|
4696
|
+
i++;
|
|
4697
|
+
while (i < chars.length) {
|
|
4698
|
+
if (chars[i] === "\\") {
|
|
4699
|
+
chars[i] = " ";
|
|
4700
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
4701
|
+
i += 2;
|
|
4702
|
+
continue;
|
|
4703
|
+
}
|
|
4704
|
+
if (chars[i] === "\n") break;
|
|
4705
|
+
if (chars[i] === q) {
|
|
4706
|
+
chars[i] = " ";
|
|
4707
|
+
i++;
|
|
4708
|
+
break;
|
|
4709
|
+
}
|
|
4710
|
+
chars[i] = " ";
|
|
4711
|
+
i++;
|
|
4712
|
+
}
|
|
4713
|
+
continue;
|
|
4714
|
+
}
|
|
4715
|
+
if (c === "`") {
|
|
4716
|
+
chars[i] = " ";
|
|
4717
|
+
i++;
|
|
4718
|
+
let expr = 0;
|
|
4719
|
+
while (i < chars.length) {
|
|
4720
|
+
if (expr === 0 && chars[i] === "\\") {
|
|
4721
|
+
chars[i] = " ";
|
|
4722
|
+
if (i + 1 < chars.length && chars[i + 1] !== "\n") chars[i + 1] = " ";
|
|
4723
|
+
i += 2;
|
|
4724
|
+
continue;
|
|
4725
|
+
}
|
|
4726
|
+
if (expr === 0 && chars[i] === "`") {
|
|
4727
|
+
chars[i] = " ";
|
|
4728
|
+
i++;
|
|
4729
|
+
break;
|
|
4730
|
+
}
|
|
4731
|
+
if (expr === 0 && chars[i] === "$" && chars[i + 1] === "{") {
|
|
4732
|
+
chars[i] = " ";
|
|
4733
|
+
chars[i + 1] = " ";
|
|
4734
|
+
expr = 1;
|
|
4735
|
+
i += 2;
|
|
4736
|
+
continue;
|
|
4737
|
+
}
|
|
4738
|
+
if (expr > 0) {
|
|
4739
|
+
if (chars[i] === "{") expr++;
|
|
4740
|
+
else if (chars[i] === "}") expr--;
|
|
4741
|
+
i++;
|
|
4742
|
+
continue;
|
|
4743
|
+
}
|
|
4744
|
+
if (chars[i] !== "\n") chars[i] = " ";
|
|
4745
|
+
i++;
|
|
4746
|
+
}
|
|
4747
|
+
continue;
|
|
4748
|
+
}
|
|
4749
|
+
i++;
|
|
4750
|
+
}
|
|
4751
|
+
return chars.join("");
|
|
2367
4752
|
}
|
|
2368
|
-
function
|
|
2369
|
-
const
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
4753
|
+
function remember(content, filePath) {
|
|
4754
|
+
const py = filePath.endsWith(".py");
|
|
4755
|
+
if (memo && memo.content === content && memo.py === py) return memo;
|
|
4756
|
+
memo = {
|
|
4757
|
+
content,
|
|
4758
|
+
py,
|
|
4759
|
+
masked: maskCallSites(content, py),
|
|
4760
|
+
lineStarts: lineStartsOf(content)
|
|
4761
|
+
};
|
|
4762
|
+
return memo;
|
|
4763
|
+
}
|
|
4764
|
+
function argIsParam(expr, param) {
|
|
4765
|
+
const trimmed = expr.trim();
|
|
4766
|
+
const id = escapeRegExp2(param);
|
|
4767
|
+
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);
|
|
4768
|
+
}
|
|
4769
|
+
function argumentOf(content, chain, base) {
|
|
4770
|
+
const update = /createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\s*\)/.exec(chain);
|
|
4771
|
+
if (update) {
|
|
4772
|
+
const after = chain.slice(update.index + update[0].length);
|
|
4773
|
+
const upd = /\.update\s*\(/.exec(after);
|
|
4774
|
+
if (!upd) return null;
|
|
4775
|
+
const open2 = base + update.index + update[0].length + upd.index + upd[0].lastIndexOf("(");
|
|
4776
|
+
const close2 = matchingCloser(content, open2, "(", ")", ARG_CAP2);
|
|
4777
|
+
if (close2 < 0) return null;
|
|
4778
|
+
return { expr: content.slice(open2 + 1, close2), at: base + update.index };
|
|
4779
|
+
}
|
|
4780
|
+
const lib = /hashlib\s*\.\s*(?:md5|sha1|sha256)\s*\(/.exec(chain);
|
|
4781
|
+
if (!lib) return null;
|
|
4782
|
+
const open = base + lib.index + lib[0].lastIndexOf("(");
|
|
4783
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
4784
|
+
if (close < 0) return null;
|
|
4785
|
+
return { expr: content.slice(open + 1, close), at: base + lib.index };
|
|
4786
|
+
}
|
|
4787
|
+
function onlyReturn(body) {
|
|
4788
|
+
const lines = body.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
4789
|
+
if (lines.length !== 1) return null;
|
|
4790
|
+
const match = /^return\s+([\s\S]+?);?$/.exec(lines[0]);
|
|
4791
|
+
return match ? match[1].replace(/;$/, "").trim() : null;
|
|
4792
|
+
}
|
|
4793
|
+
function qualifyingHelpers(content) {
|
|
4794
|
+
const found = [];
|
|
4795
|
+
const counts = /* @__PURE__ */ new Map();
|
|
4796
|
+
const note = (name) => counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
4797
|
+
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;
|
|
4798
|
+
let match;
|
|
4799
|
+
while (match = arrow.exec(content)) {
|
|
4800
|
+
const name = match[1];
|
|
4801
|
+
const param = match[2] || match[3];
|
|
4802
|
+
note(name);
|
|
4803
|
+
if (!param) continue;
|
|
4804
|
+
const at = match.index + match[0].length;
|
|
4805
|
+
const rest = content.slice(at);
|
|
4806
|
+
let chain = "";
|
|
4807
|
+
let base = at;
|
|
4808
|
+
if (/^\s*\{/.test(rest)) {
|
|
4809
|
+
const brace = content.indexOf("{", at);
|
|
4810
|
+
const end = matchingCloser(content, brace, "{", "}", 2e4);
|
|
4811
|
+
if (end < 0) continue;
|
|
4812
|
+
const body = onlyReturn(content.slice(brace + 1, end));
|
|
4813
|
+
if (body === null) continue;
|
|
4814
|
+
chain = body;
|
|
4815
|
+
base = brace + 1 + content.slice(brace + 1, end).indexOf(body);
|
|
4816
|
+
} else {
|
|
4817
|
+
const lineEnd = content.indexOf("\n", at);
|
|
4818
|
+
const semi = content.indexOf(";", at);
|
|
4819
|
+
let stop = lineEnd < 0 ? content.length : lineEnd;
|
|
4820
|
+
if (semi >= 0 && semi < stop) stop = semi;
|
|
4821
|
+
chain = content.slice(at, stop);
|
|
4822
|
+
base = at;
|
|
4823
|
+
}
|
|
4824
|
+
const hashed = argumentOf(content, chain, base);
|
|
4825
|
+
if (hashed && argIsParam(hashed.expr, param)) found.push({ name, at: hashed.at });
|
|
4826
|
+
}
|
|
4827
|
+
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;
|
|
4828
|
+
while (match = fn.exec(content)) {
|
|
4829
|
+
const name = match[1];
|
|
4830
|
+
const param = match[2];
|
|
4831
|
+
note(name);
|
|
4832
|
+
const brace = content.indexOf("{", match.index);
|
|
4833
|
+
const end = matchingCloser(content, brace, "{", "}", 2e4);
|
|
4834
|
+
if (end < 0) continue;
|
|
4835
|
+
const body = onlyReturn(content.slice(brace + 1, end));
|
|
4836
|
+
if (body === null) continue;
|
|
4837
|
+
const base = brace + 1 + content.slice(brace + 1, end).indexOf(body);
|
|
4838
|
+
const hashed = argumentOf(content, body, base);
|
|
4839
|
+
if (hashed && argIsParam(hashed.expr, param)) found.push({ name, at: hashed.at });
|
|
4840
|
+
}
|
|
4841
|
+
const lines = content.split("\n");
|
|
4842
|
+
let offset = 0;
|
|
4843
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4844
|
+
const line = lines[i];
|
|
4845
|
+
const same = /^(\s*)def\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)\s*:\s*return\s+(.+)$/.exec(line);
|
|
4846
|
+
if (same) {
|
|
4847
|
+
note(same[2]);
|
|
4848
|
+
const chainAt = offset + line.indexOf(same[4]);
|
|
4849
|
+
const hashed = argumentOf(content, same[4], chainAt);
|
|
4850
|
+
if (hashed && argIsParam(hashed.expr, same[3])) found.push({ name: same[2], at: hashed.at });
|
|
4851
|
+
} else {
|
|
4852
|
+
const head = /^(\s*)def\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)\s*:\s*$/.exec(line);
|
|
4853
|
+
if (head) {
|
|
4854
|
+
note(head[2]);
|
|
4855
|
+
const next = lines[i + 1] ?? "";
|
|
4856
|
+
const body = /^(\s+)return\s+(.+)$/.exec(next);
|
|
4857
|
+
if (body && body[1].length > head[1].length) {
|
|
4858
|
+
let more = false;
|
|
4859
|
+
for (let j = i + 2; j < lines.length; j++) {
|
|
4860
|
+
if (!lines[j].trim()) continue;
|
|
4861
|
+
const ind = /^[ \t]*/.exec(lines[j])?.[0].length ?? 0;
|
|
4862
|
+
if (ind > head[1].length) more = true;
|
|
4863
|
+
break;
|
|
4864
|
+
}
|
|
4865
|
+
if (!more) {
|
|
4866
|
+
const chainAt = offset + line.length + 1 + next.indexOf(body[2]);
|
|
4867
|
+
const hashed = argumentOf(content, body[2], chainAt);
|
|
4868
|
+
if (hashed && argIsParam(hashed.expr, head[3])) found.push({ name: head[2], at: hashed.at });
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
offset += line.length + 1;
|
|
4874
|
+
}
|
|
4875
|
+
const good = /* @__PURE__ */ new Map();
|
|
4876
|
+
for (const helper of found) good.set(helper.name, (good.get(helper.name) ?? 0) + 1);
|
|
4877
|
+
const kept = /* @__PURE__ */ new Set();
|
|
4878
|
+
for (const [name, count] of counts) {
|
|
4879
|
+
if (good.get(name) === count) kept.add(name);
|
|
4880
|
+
}
|
|
4881
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4882
|
+
return found.filter((helper) => {
|
|
4883
|
+
if (!kept.has(helper.name) || seen.has(helper.name)) return false;
|
|
4884
|
+
seen.add(helper.name);
|
|
4885
|
+
return true;
|
|
4886
|
+
});
|
|
2373
4887
|
}
|
|
2374
|
-
function
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
4888
|
+
function hasConditionalQuestion(window) {
|
|
4889
|
+
let depth = 0;
|
|
4890
|
+
let quote = "";
|
|
4891
|
+
let open = false;
|
|
4892
|
+
for (let i = 0; i < window.length; i++) {
|
|
4893
|
+
const c = window[i];
|
|
4894
|
+
if (quote) {
|
|
4895
|
+
if (c === "\\") {
|
|
4896
|
+
i++;
|
|
4897
|
+
continue;
|
|
4898
|
+
}
|
|
4899
|
+
if (c === quote) quote = "";
|
|
4900
|
+
continue;
|
|
4901
|
+
}
|
|
4902
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
4903
|
+
quote = c;
|
|
4904
|
+
continue;
|
|
4905
|
+
}
|
|
4906
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
4907
|
+
else if (c === ")" || c === "]" || c === "}") depth = Math.max(0, depth - 1);
|
|
4908
|
+
else if (depth === 0 && (c === ";" || c === "\n")) open = false;
|
|
4909
|
+
else if (c === "?" && depth === 0 && window[i + 1] !== "?" && window[i + 1] !== "." && window[i - 1] !== "?") {
|
|
4910
|
+
open = true;
|
|
4911
|
+
}
|
|
4912
|
+
}
|
|
4913
|
+
return open;
|
|
4914
|
+
}
|
|
4915
|
+
function rawNames(content, callIndex) {
|
|
4916
|
+
const start = Math.max(0, callIndex - 200);
|
|
4917
|
+
const slice = content.slice(start, callIndex);
|
|
4918
|
+
const nl = slice.lastIndexOf("\n");
|
|
4919
|
+
const window = nl < 0 ? slice : slice.slice(nl + 1);
|
|
4920
|
+
const names = [];
|
|
4921
|
+
if (!hasConditionalQuestion(window)) {
|
|
4922
|
+
const key = /(["']?)([A-Za-z_$][\w$]*)\1\s*:\s*$/.exec(window);
|
|
4923
|
+
if (key) names.push(key[2]);
|
|
4924
|
+
}
|
|
4925
|
+
const assigned = /([A-Za-z_$][\w$.]*)(?:\s*:\s*[^=]{1,80}?)?\s*=\s*$/.exec(window);
|
|
4926
|
+
if (assigned) names.push(assigned[1]);
|
|
4927
|
+
const sub = /\[\s*(["'])([A-Za-z_$][\w$]*)\1\s*\]\s*=\s*$/.exec(window);
|
|
4928
|
+
if (sub) names.push(sub[2]);
|
|
4929
|
+
return names;
|
|
2378
4930
|
}
|
|
2379
|
-
function
|
|
2380
|
-
const
|
|
2381
|
-
|
|
4931
|
+
function firstArg(content, open) {
|
|
4932
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
4933
|
+
if (close < 0) return null;
|
|
2382
4934
|
let depth = 0;
|
|
2383
4935
|
let quote = "";
|
|
2384
|
-
for (let i =
|
|
2385
|
-
const c =
|
|
4936
|
+
for (let i = open + 1; i < close; i++) {
|
|
4937
|
+
const c = content[i];
|
|
2386
4938
|
if (quote) {
|
|
2387
4939
|
if (c === "\\") {
|
|
2388
4940
|
i++;
|
|
@@ -2397,95 +4949,61 @@ function splitArgs(args) {
|
|
|
2397
4949
|
}
|
|
2398
4950
|
if (c === "(" || c === "{" || c === "[") depth++;
|
|
2399
4951
|
else if (c === ")" || c === "}" || c === "]") depth--;
|
|
2400
|
-
else if (c === "," && depth === 0)
|
|
2401
|
-
parts.push(args.slice(start, i));
|
|
2402
|
-
start = i + 1;
|
|
2403
|
-
}
|
|
4952
|
+
else if (c === "," && depth === 0) return content.slice(open + 1, i);
|
|
2404
4953
|
}
|
|
2405
|
-
|
|
2406
|
-
return parts;
|
|
4954
|
+
return content.slice(open + 1, close);
|
|
2407
4955
|
}
|
|
2408
|
-
function
|
|
2409
|
-
const
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
4956
|
+
function callQualifies(content, masked, name) {
|
|
4957
|
+
const re = new RegExp(`(?<![\\w$.])${escapeRegExp2(name)}\\(`, "g");
|
|
4958
|
+
let match;
|
|
4959
|
+
while (match = re.exec(masked)) {
|
|
4960
|
+
const before = masked.slice(Math.max(0, match.index - 24), match.index);
|
|
4961
|
+
if (/\b(?:function|def)\s+$/.test(before)) continue;
|
|
4962
|
+
if (/\b(?:const|let|var)\s+$/.test(before)) continue;
|
|
4963
|
+
const arg = firstArg(masked, match.index + name.length);
|
|
4964
|
+
if (arg === null) continue;
|
|
4965
|
+
const names = rawNames(content, match.index);
|
|
4966
|
+
const argOk = hasPf(arg) && !blocked(arg, TOKEN_WORDS);
|
|
4967
|
+
const nameOk = names.some((label) => hasPf(label) && !blocked(label, KEY_BLOCK));
|
|
4968
|
+
if (argOk || nameOk) return true;
|
|
2419
4969
|
}
|
|
2420
4970
|
return false;
|
|
2421
4971
|
}
|
|
2422
|
-
function
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
4972
|
+
function helperWeakIndexes(content, filePath) {
|
|
4973
|
+
try {
|
|
4974
|
+
if (helperFault) throw new Error("injected");
|
|
4975
|
+
const slot = remember(content, filePath);
|
|
4976
|
+
const helpers = qualifyingHelpers(content);
|
|
4977
|
+
const indexes = [];
|
|
4978
|
+
for (const helper of helpers) {
|
|
4979
|
+
if (callQualifies(content, slot.masked, helper.name)) indexes.push(helper.at);
|
|
4980
|
+
}
|
|
4981
|
+
return indexes;
|
|
4982
|
+
} catch {
|
|
4983
|
+
remember(content, filePath);
|
|
4984
|
+
return [];
|
|
2429
4985
|
}
|
|
2430
|
-
if (tryIndex < 0) return true;
|
|
2431
|
-
const catchRe = /\bcatch\b/g;
|
|
2432
|
-
catchRe.lastIndex = callIndex;
|
|
2433
|
-
const caught = catchRe.exec(handler);
|
|
2434
|
-
if (!caught) return true;
|
|
2435
|
-
const brace = handler.indexOf("{", caught.index);
|
|
2436
|
-
if (brace < 0) return false;
|
|
2437
|
-
const end = matchingCloser(handler, brace, "{", "}");
|
|
2438
|
-
if (end < 0) return false;
|
|
2439
|
-
const body = handler.slice(brace, end);
|
|
2440
|
-
return /\bthrow\b/.test(body) || /\breturn\b/.test(body) && /\b4\d\d\b/.test(body);
|
|
2441
4986
|
}
|
|
2442
|
-
function
|
|
2443
|
-
const
|
|
4987
|
+
function pythonDefs(content) {
|
|
4988
|
+
const defs = [];
|
|
4989
|
+
const re = /^([ \t]*)def\s+([A-Za-z_]\w*)\s*\(/gm;
|
|
2444
4990
|
let match;
|
|
2445
|
-
while (match =
|
|
2446
|
-
|
|
2447
|
-
const close = matchingCloser(handler, open, "(", ")");
|
|
2448
|
-
if (close < 0) continue;
|
|
2449
|
-
const args = handler.slice(open + 1, close);
|
|
2450
|
-
if (!/\.text\s*\(/.test(handler) && !/\.text\s*\(/.test(args)) continue;
|
|
2451
|
-
if (!/stripe-signature|upstash-signature/i.test(handler)) continue;
|
|
2452
|
-
if (!secretArgOk(args)) continue;
|
|
2453
|
-
if (!beforeSideEffect(handler, match.index)) continue;
|
|
2454
|
-
if (!errorPathRejects(handler, match.index)) continue;
|
|
2455
|
-
return true;
|
|
4991
|
+
while (match = re.exec(content)) {
|
|
4992
|
+
defs.push({ name: match[2], indent: match[1].length, at: match.index });
|
|
2456
4993
|
}
|
|
2457
|
-
return
|
|
4994
|
+
return defs;
|
|
2458
4995
|
}
|
|
2459
|
-
function
|
|
2460
|
-
const
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
if (
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
if (!/(?:!==|!=(?!=))/.test(cond)) continue;
|
|
2469
|
-
if (!beforeSideEffect(handler, match.index)) continue;
|
|
2470
|
-
const after = handler.slice(close, close + 400);
|
|
2471
|
-
if (/\breturn\b/.test(after) && /\b401\b/.test(after)) return true;
|
|
2472
|
-
if (/\bstatus\s*\(\s*401\b/.test(after)) return true;
|
|
4996
|
+
function pythonDefName(content, index, defs) {
|
|
4997
|
+
const lineStart = content.lastIndexOf("\n", Math.max(0, index - 1)) + 1;
|
|
4998
|
+
const indent = /^[ \t]*/.exec(content.slice(lineStart))?.[0].length ?? 0;
|
|
4999
|
+
let name = "";
|
|
5000
|
+
let defIndent = -1;
|
|
5001
|
+
for (const def of defs) {
|
|
5002
|
+
if (def.at >= index) break;
|
|
5003
|
+
name = def.name;
|
|
5004
|
+
defIndent = def.indent;
|
|
2473
5005
|
}
|
|
2474
|
-
return
|
|
2475
|
-
}
|
|
2476
|
-
function widenedAuthSuppresses(content, filePath, index, handler) {
|
|
2477
|
-
if (!handler) return false;
|
|
2478
|
-
const masked = blankComments(content);
|
|
2479
|
-
const maskedHandler = blankComments(handler);
|
|
2480
|
-
if (guardCallBeforeSideEffect(masked, maskedHandler)) return true;
|
|
2481
|
-
if (routeArgsQualify(masked, maskedHandler)) return true;
|
|
2482
|
-
if (useCoversRoute(masked, index)) return true;
|
|
2483
|
-
const routePath = routePathFromFile(filePath) ?? expressRoutePath(maskedHandler);
|
|
2484
|
-
if (routePath && isAnchoredPublicAuthPath(routePath) && !mutatesKeyedOnParams(maskedHandler)) return true;
|
|
2485
|
-
if (routePath && isOgRoutePath(routePath)) return true;
|
|
2486
|
-
if (signatureCheckQualifies(maskedHandler)) return true;
|
|
2487
|
-
if (cronSecretGates(maskedHandler)) return true;
|
|
2488
|
-
return false;
|
|
5006
|
+
return name && indent > defIndent ? name : "";
|
|
2489
5007
|
}
|
|
2490
5008
|
|
|
2491
5009
|
// src/public-env.ts
|
|
@@ -2559,69 +5077,9 @@ function dotenvValue(raw) {
|
|
|
2559
5077
|
return (hash === -1 ? v : v.slice(0, hash)).trim();
|
|
2560
5078
|
}
|
|
2561
5079
|
|
|
2562
|
-
// src/ast/parse.ts
|
|
2563
|
-
var import_parser = require("@babel/parser");
|
|
2564
|
-
var MAX_CACHE = 256;
|
|
2565
|
-
var cache = /* @__PURE__ */ new Map();
|
|
2566
|
-
function cacheKey(filename, contentHash) {
|
|
2567
|
-
return `${filename}:${contentHash}`;
|
|
2568
|
-
}
|
|
2569
|
-
function quickHash(s) {
|
|
2570
|
-
let h = 5381;
|
|
2571
|
-
const step = Math.max(1, Math.floor(s.length / 32));
|
|
2572
|
-
for (let i = 0; i < s.length; i += step) {
|
|
2573
|
-
h = (h << 5) + h + s.charCodeAt(i) | 0;
|
|
2574
|
-
}
|
|
2575
|
-
return h * 31 + s.length | 0;
|
|
2576
|
-
}
|
|
2577
|
-
function pickLanguage(filename) {
|
|
2578
|
-
if (/\.tsx$/i.test(filename)) return "tsx";
|
|
2579
|
-
if (/\.jsx$/i.test(filename)) return "jsx";
|
|
2580
|
-
if (/\.(ts|cts|mts)$/i.test(filename)) return "ts";
|
|
2581
|
-
if (/\.(js|cjs|mjs)$/i.test(filename)) return "js";
|
|
2582
|
-
return null;
|
|
2583
|
-
}
|
|
2584
|
-
function parseFile(content, filename) {
|
|
2585
|
-
const lang = pickLanguage(filename);
|
|
2586
|
-
if (!lang) return null;
|
|
2587
|
-
if (!content || content.length === 0) return null;
|
|
2588
|
-
const key = cacheKey(filename, quickHash(content));
|
|
2589
|
-
if (cache.has(key)) return cache.get(key) ?? null;
|
|
2590
|
-
const plugins = [];
|
|
2591
|
-
if (lang === "ts" || lang === "tsx") plugins.push("typescript");
|
|
2592
|
-
if (lang === "jsx" || lang === "tsx") plugins.push("jsx");
|
|
2593
|
-
plugins.push("decorators-legacy", "classProperties", "dynamicImport", "topLevelAwait");
|
|
2594
|
-
let ast = null;
|
|
2595
|
-
try {
|
|
2596
|
-
ast = (0, import_parser.parse)(content, {
|
|
2597
|
-
sourceType: "unambiguous",
|
|
2598
|
-
allowImportExportEverywhere: true,
|
|
2599
|
-
allowReturnOutsideFunction: true,
|
|
2600
|
-
allowAwaitOutsideFunction: true,
|
|
2601
|
-
allowUndeclaredExports: true,
|
|
2602
|
-
errorRecovery: true,
|
|
2603
|
-
plugins
|
|
2604
|
-
});
|
|
2605
|
-
} catch {
|
|
2606
|
-
cache.set(key, null);
|
|
2607
|
-
if (cache.size > MAX_CACHE) {
|
|
2608
|
-
const firstKey = cache.keys().next().value;
|
|
2609
|
-
if (firstKey !== void 0) cache.delete(firstKey);
|
|
2610
|
-
}
|
|
2611
|
-
return null;
|
|
2612
|
-
}
|
|
2613
|
-
const entry = { ast, language: lang };
|
|
2614
|
-
cache.set(key, entry);
|
|
2615
|
-
if (cache.size > MAX_CACHE) {
|
|
2616
|
-
const firstKey = cache.keys().next().value;
|
|
2617
|
-
if (firstKey !== void 0) cache.delete(firstKey);
|
|
2618
|
-
}
|
|
2619
|
-
return entry;
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
5080
|
// src/ast/taint.ts
|
|
2623
|
-
var
|
|
2624
|
-
var
|
|
5081
|
+
var import_traverse2 = __toESM(require("@babel/traverse"), 1);
|
|
5082
|
+
var traverse2 = typeof import_traverse2.default === "function" ? import_traverse2.default : import_traverse2.default.default;
|
|
2625
5083
|
var TAINTED_PROP_SUFFIXES = /* @__PURE__ */ new Set([
|
|
2626
5084
|
"body",
|
|
2627
5085
|
"query",
|
|
@@ -2792,8 +5250,8 @@ function buildTaintMap(parsed) {
|
|
|
2792
5250
|
if (!node) return false;
|
|
2793
5251
|
if (node.type === "MemberExpression") {
|
|
2794
5252
|
const prop = node.property;
|
|
2795
|
-
const
|
|
2796
|
-
if (TAINTED_PROP_SUFFIXES.has(
|
|
5253
|
+
const propName2 = prop.type === "Identifier" ? prop.name : prop.type === "StringLiteral" ? prop.value : "";
|
|
5254
|
+
if (TAINTED_PROP_SUFFIXES.has(propName2)) {
|
|
2797
5255
|
const obj = node.object;
|
|
2798
5256
|
if (obj.type === "Identifier" && TAINTED_REQUEST_OBJECTS.has(obj.name)) {
|
|
2799
5257
|
return true;
|
|
@@ -2886,7 +5344,7 @@ function buildTaintMap(parsed) {
|
|
|
2886
5344
|
const pt = computePassthrough(fn);
|
|
2887
5345
|
if (pt.size > 0) fnPassthrough.set(name, pt);
|
|
2888
5346
|
};
|
|
2889
|
-
|
|
5347
|
+
traverse2(parsed.ast, {
|
|
2890
5348
|
FunctionDeclaration(path) {
|
|
2891
5349
|
const n = path.node;
|
|
2892
5350
|
if (n.type === "FunctionDeclaration" && n.id && n.id.type === "Identifier") {
|
|
@@ -2909,7 +5367,7 @@ function buildTaintMap(parsed) {
|
|
|
2909
5367
|
(a, i) => pt.has(i) && a.type !== "SpreadElement" && rec(a)
|
|
2910
5368
|
);
|
|
2911
5369
|
}
|
|
2912
|
-
|
|
5370
|
+
traverse2(parsed.ast, {
|
|
2913
5371
|
VariableDeclarator(path) {
|
|
2914
5372
|
const node = path.node;
|
|
2915
5373
|
if (node.type !== "VariableDeclarator") return;
|
|
@@ -3031,10 +5489,10 @@ function buildTaintMap(parsed) {
|
|
|
3031
5489
|
}
|
|
3032
5490
|
|
|
3033
5491
|
// src/ast/traverse.ts
|
|
3034
|
-
var
|
|
3035
|
-
var
|
|
5492
|
+
var import_traverse3 = __toESM(require("@babel/traverse"), 1);
|
|
5493
|
+
var traverse3 = typeof import_traverse3.default === "function" ? import_traverse3.default : import_traverse3.default.default;
|
|
3036
5494
|
function visitBinary(parsed, visit) {
|
|
3037
|
-
|
|
5495
|
+
traverse3(parsed.ast, {
|
|
3038
5496
|
BinaryExpression(path) {
|
|
3039
5497
|
const line = path.node.loc?.start.line ?? 1;
|
|
3040
5498
|
visit(path.node, line);
|
|
@@ -3042,7 +5500,7 @@ function visitBinary(parsed, visit) {
|
|
|
3042
5500
|
});
|
|
3043
5501
|
}
|
|
3044
5502
|
function visitCalls(parsed, matchCallee, visit) {
|
|
3045
|
-
|
|
5503
|
+
traverse3(parsed.ast, {
|
|
3046
5504
|
CallExpression(path) {
|
|
3047
5505
|
const node = path.node;
|
|
3048
5506
|
if (!matchCallee(node.callee)) return;
|
|
@@ -4162,9 +6620,9 @@ function maskOutboundAuthNoise(code) {
|
|
|
4162
6620
|
/\bapi_?key["']?\s{0,20}:\s{0,20}(?:process\.env\.\w{1,80}|Deno\.env\.get\(\s*["'][\w-]{1,80}["']\s*\)|import\.meta\.env\.\w{1,80}|[A-Z][A-Z0-9_]{2,79}\b)/gi,
|
|
4163
6621
|
blankKeepLines
|
|
4164
6622
|
);
|
|
4165
|
-
let
|
|
6623
|
+
let bindingMap2 = null;
|
|
4166
6624
|
const bindingSource = out;
|
|
4167
|
-
const bindings = () =>
|
|
6625
|
+
const bindings = () => bindingMap2 ??= collectBindings(bindingSource);
|
|
4168
6626
|
out = out.replace(
|
|
4169
6627
|
/\b\w{0,40}[Hh]eaders\s*\.\s*(?:set|append)\s*\(\s*["'](?:authorization|x-api-key|api-key|x-goog-api-key)["']\s*,([^\n]{0,300})/gi,
|
|
4170
6628
|
(call, value, at) => credentialValueReadsCaller(value, at, bindings) ? call : blankKeepLines(call)
|
|
@@ -4339,10 +6797,10 @@ function unauthenticatedTanStackHandlers(masked, filePath) {
|
|
|
4339
6797
|
return hasAuthMiddleware(handlersAt === -1 ? block : block.slice(0, handlersAt));
|
|
4340
6798
|
})();
|
|
4341
6799
|
if (!routeLevelAuth) {
|
|
4342
|
-
const
|
|
6800
|
+
const METHOD_RE2 = /\b(GET|POST|PUT|PATCH|DELETE)\s*:\s*(?:async\s+)?(?:\(|function\b|\{|[A-Za-z_$][\w$]{0,40}\s*=>)/g;
|
|
4343
6801
|
const methodStarts = [];
|
|
4344
6802
|
let m;
|
|
4345
|
-
while ((m =
|
|
6803
|
+
while ((m = METHOD_RE2.exec(masked)) !== null && methodStarts.length < 200) methodStarts.push(m.index);
|
|
4346
6804
|
for (let k = 0; k < methodStarts.length; k++) {
|
|
4347
6805
|
const start = methodStarts[k];
|
|
4348
6806
|
const limit = k + 1 < methodStarts.length ? methodStarts[k + 1] : Math.min(masked.length, start + 4e4);
|
|
@@ -4557,7 +7015,7 @@ var missingAuthMiddleware = {
|
|
|
4557
7015
|
const unauthenticated = matches.filter((m) => {
|
|
4558
7016
|
const index = indexOfLine(m.line);
|
|
4559
7017
|
if (isPublicRootGet(index) || handlerHasAuth(index)) return false;
|
|
4560
|
-
if (widenedAuthSuppresses(maskedForScope, filePath, index, scopeAt(index))) return false;
|
|
7018
|
+
if (widenedAuthSuppresses(maskedForScope, filePath, index, scopeAt(index), content, true, true)) return false;
|
|
4561
7019
|
const namedExport = NAMED_ROUTE_EXPORT_RE.exec(lineText(index));
|
|
4562
7020
|
if (namedExport && secretGuarded && /^[A-Z]+$/.test(namedExport[1])) return false;
|
|
4563
7021
|
if (useServerPatterns.length > 0 && (!routeLines.has(m.line) || namedExport !== null && !/^[A-Z]+$/.test(namedExport[1]))) {
|
|
@@ -5873,8 +8331,8 @@ var weakHashing = {
|
|
|
5873
8331
|
() => "Use bcrypt, scrypt, or argon2 for password hashing \u2014 they're intentionally slow. Example: const hash = await bcrypt.hash(password, 12);"
|
|
5874
8332
|
));
|
|
5875
8333
|
}
|
|
5876
|
-
const
|
|
5877
|
-
const
|
|
8334
|
+
const defs = pythonDefs(content);
|
|
8335
|
+
const nameAt = /* @__PURE__ */ new Map();
|
|
5878
8336
|
const weakCallPatterns = [
|
|
5879
8337
|
/createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\s*\)/gi,
|
|
5880
8338
|
/hashlib\.(?:md5|sha1|sha256)\s*\(/gi,
|
|
@@ -5889,58 +8347,49 @@ var weakHashing = {
|
|
|
5889
8347
|
}
|
|
5890
8348
|
return at;
|
|
5891
8349
|
};
|
|
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
8350
|
const braceEnclosingName = (index) => {
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
8351
|
+
const cached = nameAt.get(index);
|
|
8352
|
+
if (cached !== void 0) return cached;
|
|
8353
|
+
let name = "";
|
|
8354
|
+
try {
|
|
8355
|
+
let searchFrom = index;
|
|
8356
|
+
for (let level = 0; level < 8 && index - searchFrom < 2e4; level++) {
|
|
8357
|
+
let depth = 0;
|
|
8358
|
+
let open = -1;
|
|
8359
|
+
const limit = Math.max(0, index - 2e4);
|
|
8360
|
+
for (let i = searchFrom; i >= limit; i--) {
|
|
8361
|
+
const c = content[i];
|
|
8362
|
+
if (c === "}") depth++;
|
|
8363
|
+
else if (c === "{") {
|
|
8364
|
+
if (depth === 0) {
|
|
8365
|
+
open = i;
|
|
8366
|
+
break;
|
|
8367
|
+
}
|
|
8368
|
+
depth--;
|
|
5916
8369
|
}
|
|
5917
|
-
depth--;
|
|
5918
8370
|
}
|
|
8371
|
+
if (open < 0) break;
|
|
8372
|
+
const header = content.slice(Math.max(0, open - 180), open);
|
|
8373
|
+
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);
|
|
8374
|
+
if (named?.[1]) {
|
|
8375
|
+
name = named[1];
|
|
8376
|
+
break;
|
|
8377
|
+
}
|
|
8378
|
+
const method = methodHeaderName(header);
|
|
8379
|
+
if (method) {
|
|
8380
|
+
name = method;
|
|
8381
|
+
break;
|
|
8382
|
+
}
|
|
8383
|
+
searchFrom = open - 1;
|
|
5919
8384
|
}
|
|
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;
|
|
8385
|
+
if (!name) name = pythonDefName(content, index, defs);
|
|
8386
|
+
} catch {
|
|
8387
|
+
name = "";
|
|
5940
8388
|
}
|
|
5941
|
-
|
|
8389
|
+
nameAt.set(index, name);
|
|
8390
|
+
return name;
|
|
5942
8391
|
};
|
|
5943
|
-
const
|
|
8392
|
+
const rawHits = [];
|
|
5944
8393
|
for (const p of weakCallPatterns) {
|
|
5945
8394
|
const raw = findMatches(
|
|
5946
8395
|
content,
|
|
@@ -5949,16 +8398,23 @@ var weakHashing = {
|
|
|
5949
8398
|
filePath,
|
|
5950
8399
|
() => "Use bcrypt, scrypt, or argon2 for password hashing. These algorithms are intentionally slow so brute-force attacks are infeasible."
|
|
5951
8400
|
);
|
|
8401
|
+
rawHits.push(...raw);
|
|
5952
8402
|
for (const m of raw) {
|
|
5953
8403
|
if (matches.some((existing) => existing.line === m.line)) continue;
|
|
5954
8404
|
const lineStart = indexOfLineNo(m.line);
|
|
5955
|
-
const expr =
|
|
5956
|
-
const
|
|
5957
|
-
const
|
|
5958
|
-
if (!
|
|
8405
|
+
const expr = hashedExprAt(content, lineStart);
|
|
8406
|
+
const token = gatherTokenDecision(content, lineStart, filePath);
|
|
8407
|
+
const name = braceEnclosingName(lineStart);
|
|
8408
|
+
if (!perCallKeeps(name, expr, token)) continue;
|
|
5959
8409
|
matches.push(m);
|
|
5960
8410
|
}
|
|
5961
8411
|
}
|
|
8412
|
+
for (const at of helperWeakIndexes(content, filePath)) {
|
|
8413
|
+
const line = lineNoAt(content, at);
|
|
8414
|
+
if (matches.some((existing) => existing.line === line)) continue;
|
|
8415
|
+
const hit = rawHits.find((m) => m.line === line);
|
|
8416
|
+
if (hit) matches.push(hit);
|
|
8417
|
+
}
|
|
5962
8418
|
return matches;
|
|
5963
8419
|
}
|
|
5964
8420
|
};
|
|
@@ -9667,7 +12123,7 @@ function isClientTarget(file) {
|
|
|
9667
12123
|
function isServerTarget(file) {
|
|
9668
12124
|
return !file.excluded && file.isServer;
|
|
9669
12125
|
}
|
|
9670
|
-
function
|
|
12126
|
+
function lineAt2(content, index) {
|
|
9671
12127
|
let line = 1;
|
|
9672
12128
|
for (let i = 0; i < index && i < content.length; i++) {
|
|
9673
12129
|
if (content[i] === "\n") line++;
|
|
@@ -9770,7 +12226,7 @@ var silentFailedRead = {
|
|
|
9770
12226
|
if (!allValuesEmpty(payload)) continue;
|
|
9771
12227
|
if (HAS_MARKER.test(payload)) continue;
|
|
9772
12228
|
if (/\bstatus\s*:\s*[45]\d\d/.test(body)) continue;
|
|
9773
|
-
hits.push({ file: file.path, line:
|
|
12229
|
+
hits.push({ file: file.path, line: lineAt2(file.content, index) });
|
|
9774
12230
|
break;
|
|
9775
12231
|
}
|
|
9776
12232
|
}
|
|
@@ -9780,8 +12236,8 @@ var silentFailedRead = {
|
|
|
9780
12236
|
};
|
|
9781
12237
|
|
|
9782
12238
|
// src/quality/rules/silent-failed-write.ts
|
|
9783
|
-
var
|
|
9784
|
-
var
|
|
12239
|
+
var import_traverse5 = __toESM(require("@babel/traverse"), 1);
|
|
12240
|
+
var traverse4 = typeof import_traverse5.default === "function" ? import_traverse5.default : import_traverse5.default.default;
|
|
9785
12241
|
var EXTRA_EXCLUDED_PATHS = [
|
|
9786
12242
|
/(?:^|\/)generated\//i,
|
|
9787
12243
|
/(?:^|\/)__generated__\//i,
|
|
@@ -9915,7 +12371,7 @@ function collectFunctions(file) {
|
|
|
9915
12371
|
const byNode = /* @__PURE__ */ new Map();
|
|
9916
12372
|
if (!parsed) return { reachable: /* @__PURE__ */ new Map() };
|
|
9917
12373
|
const handlerRefNames = /* @__PURE__ */ new Set();
|
|
9918
|
-
|
|
12374
|
+
traverse4(parsed.ast, {
|
|
9919
12375
|
JSXAttribute(path) {
|
|
9920
12376
|
const name = path.node.name;
|
|
9921
12377
|
if (name.type !== "JSXIdentifier" || !HANDLER_ATTRIBUTE.test(name.name)) return;
|
|
@@ -9925,7 +12381,7 @@ function collectFunctions(file) {
|
|
|
9925
12381
|
if (expr.type === "Identifier") handlerRefNames.add(expr.name);
|
|
9926
12382
|
}
|
|
9927
12383
|
});
|
|
9928
|
-
|
|
12384
|
+
traverse4(parsed.ast, {
|
|
9929
12385
|
Function(path) {
|
|
9930
12386
|
const info = {
|
|
9931
12387
|
path,
|
|
@@ -9942,7 +12398,7 @@ function collectFunctions(file) {
|
|
|
9942
12398
|
byNode.set(path.node, info);
|
|
9943
12399
|
}
|
|
9944
12400
|
});
|
|
9945
|
-
|
|
12401
|
+
traverse4(parsed.ast, {
|
|
9946
12402
|
CallExpression(path) {
|
|
9947
12403
|
const name = calleeName(path.node.callee);
|
|
9948
12404
|
if (!name) return;
|
|
@@ -10130,7 +12586,7 @@ var silentFailedWrite = {
|
|
|
10130
12586
|
const reachableByNode = /* @__PURE__ */ new Map();
|
|
10131
12587
|
for (const info of reachable.keys()) reachableByNode.set(info.path.node, info);
|
|
10132
12588
|
const reportedUnits = /* @__PURE__ */ new Set();
|
|
10133
|
-
|
|
12589
|
+
traverse4(parsed.ast, {
|
|
10134
12590
|
CallExpression(path) {
|
|
10135
12591
|
if (!isFetchCallee(path.node.callee)) return;
|
|
10136
12592
|
if (inAmbientContext(path)) return;
|
|
@@ -10178,7 +12634,7 @@ var silentFailedWrite = {
|
|
|
10178
12634
|
reportedUnits.add(unit.start);
|
|
10179
12635
|
hits.push({
|
|
10180
12636
|
file: file.path,
|
|
10181
|
-
line:
|
|
12637
|
+
line: lineAt2(file.content, nodeStart(call)),
|
|
10182
12638
|
detail: okShape === true ? `${unit.name ? `\`${unit.name}\` ` : "This handler "}checks the response status and then does nothing with the failure \u2014 it falls through to the same success message, optimistic update or redirect it would show on a 200. The user is told a destructive change landed when it may not have.` : void 0
|
|
10183
12639
|
});
|
|
10184
12640
|
}
|
|
@@ -10706,8 +13162,8 @@ var stateBeforeEffect = {
|
|
|
10706
13162
|
const columnLabel = `${transition.table.replace(/["'`]/g, "")}.${transition.column.replace(/["'`]/g, "")}`;
|
|
10707
13163
|
hits.push({
|
|
10708
13164
|
file: file.path,
|
|
10709
|
-
line:
|
|
10710
|
-
detail: `\`${columnLabel}\` is moved out of \`${normValue(consumed.value)}\` on line ${
|
|
13165
|
+
line: lineAt2(file.content, effect.index),
|
|
13166
|
+
detail: `\`${columnLabel}\` is moved out of \`${normValue(consumed.value)}\` on line ${lineAt2(file.content, transition.index)}, and only then does \`${effect.label}\` run \u2014 with its failure caught and swallowed. If the transfer fails, the row says it was paid, the money never moved, and the pending query will never select that row again.`
|
|
10711
13167
|
});
|
|
10712
13168
|
}
|
|
10713
13169
|
}
|
|
@@ -10725,22 +13181,22 @@ var SKIP_KEYS = /* @__PURE__ */ new Set([
|
|
|
10725
13181
|
"trailingComments",
|
|
10726
13182
|
"innerComments"
|
|
10727
13183
|
]);
|
|
10728
|
-
function
|
|
13184
|
+
function walk2(node, visit) {
|
|
10729
13185
|
if (!node || typeof node !== "object") return;
|
|
10730
13186
|
if (Array.isArray(node)) {
|
|
10731
|
-
for (const child of node)
|
|
13187
|
+
for (const child of node) walk2(child, visit);
|
|
10732
13188
|
return;
|
|
10733
13189
|
}
|
|
10734
13190
|
const record = node;
|
|
10735
13191
|
if (typeof record.type === "string") visit(node);
|
|
10736
13192
|
for (const key of Object.keys(record)) {
|
|
10737
13193
|
if (SKIP_KEYS.has(key)) continue;
|
|
10738
|
-
|
|
13194
|
+
walk2(record[key], visit);
|
|
10739
13195
|
}
|
|
10740
13196
|
}
|
|
10741
13197
|
function containsType(root, types) {
|
|
10742
13198
|
let found = false;
|
|
10743
|
-
|
|
13199
|
+
walk2(root, (n) => {
|
|
10744
13200
|
if (types.includes(n.type)) found = true;
|
|
10745
13201
|
});
|
|
10746
13202
|
return found;
|
|
@@ -10854,7 +13310,7 @@ function hasEnvSchemaFor(code, name) {
|
|
|
10854
13310
|
}
|
|
10855
13311
|
function readsRequestHeader(node, facts) {
|
|
10856
13312
|
let found = false;
|
|
10857
|
-
|
|
13313
|
+
walk2(node, (n) => {
|
|
10858
13314
|
if (found) return;
|
|
10859
13315
|
if (n.type === "Identifier" && n.name === "headers") found = true;
|
|
10860
13316
|
if (n.type === "CallExpression" || n.type === "OptionalCallExpression") {
|
|
@@ -10874,7 +13330,7 @@ function collectFacts(file) {
|
|
|
10874
13330
|
};
|
|
10875
13331
|
const ast = file.parsed?.ast;
|
|
10876
13332
|
if (!ast) return facts;
|
|
10877
|
-
|
|
13333
|
+
walk2(ast, (n) => {
|
|
10878
13334
|
if (n.type !== "VariableDeclarator" || !n.init) return;
|
|
10879
13335
|
const init = n.init;
|
|
10880
13336
|
let source = init;
|
|
@@ -10920,13 +13376,13 @@ function collectFacts(file) {
|
|
|
10920
13376
|
}
|
|
10921
13377
|
});
|
|
10922
13378
|
const names = /* @__PURE__ */ new Set([...facts.envAlias.values()]);
|
|
10923
|
-
|
|
13379
|
+
walk2(ast, (n) => {
|
|
10924
13380
|
if (n.type === "MemberExpression" || n.type === "CallExpression") {
|
|
10925
13381
|
const direct = envVarName(n);
|
|
10926
13382
|
if (direct) names.add(direct);
|
|
10927
13383
|
}
|
|
10928
13384
|
});
|
|
10929
|
-
|
|
13385
|
+
walk2(ast, (n) => {
|
|
10930
13386
|
if (n.type === "IfStatement") {
|
|
10931
13387
|
for (const name of names) {
|
|
10932
13388
|
if (facts.guarded.has(name)) continue;
|
|
@@ -11247,7 +13703,7 @@ var mouseOnlyControl = {
|
|
|
11247
13703
|
if (isAsChildTrigger(jsxParent)) return;
|
|
11248
13704
|
const dressed = attributeSource(findAttribute(opening, "className"), file.code) + " " + attributeSource(findAttribute(opening, "class"), file.code) + " " + attributeSource(findAttribute(opening, "style"), file.code);
|
|
11249
13705
|
if (!AFFORDANCE.test(dressed)) return;
|
|
11250
|
-
const line = opening.loc?.start.line ??
|
|
13706
|
+
const line = opening.loc?.start.line ?? lineAt2(file.content, opening.start ?? 0);
|
|
11251
13707
|
hits.push({ file: file.path, line });
|
|
11252
13708
|
});
|
|
11253
13709
|
}
|
|
@@ -11495,7 +13951,7 @@ var undeclaredModal = {
|
|
|
11495
13951
|
if (!hasFocusableDescendant(element)) continue;
|
|
11496
13952
|
if (declaresSemantics(element)) continue;
|
|
11497
13953
|
if (!isOpenGated(element, parents, baseName2)) continue;
|
|
11498
|
-
const line = opening.loc?.start.line ??
|
|
13954
|
+
const line = opening.loc?.start.line ?? lineAt2(file.content, opening.start ?? 0);
|
|
11499
13955
|
hits.push({ file: file.path, line });
|
|
11500
13956
|
break;
|
|
11501
13957
|
}
|
|
@@ -11715,7 +14171,7 @@ var unboundedList = {
|
|
|
11715
14171
|
if (REDUCING_MEMBER.test(afterQuery)) return;
|
|
11716
14172
|
const binding = resultBinding(statement);
|
|
11717
14173
|
if (binding && nextUseReduces(file.code, binding, end)) return;
|
|
11718
|
-
const line = node.loc?.start.line ??
|
|
14174
|
+
const line = node.loc?.start.line ?? lineAt2(file.content, node.start ?? 0);
|
|
11719
14175
|
hits.push({ file: file.path, line });
|
|
11720
14176
|
reported = true;
|
|
11721
14177
|
});
|
|
@@ -11871,7 +14327,7 @@ var unassociatedLabel = {
|
|
|
11871
14327
|
const field = fieldAfter(element.end, openings);
|
|
11872
14328
|
if (!field) continue;
|
|
11873
14329
|
if (fieldIsNamed(field)) continue;
|
|
11874
|
-
const line = opening.loc?.start.line ??
|
|
14330
|
+
const line = opening.loc?.start.line ?? lineAt2(file.content, opening.start ?? 0);
|
|
11875
14331
|
hits.push({ file: file.path, line });
|
|
11876
14332
|
}
|
|
11877
14333
|
}
|
|
@@ -11880,11 +14336,11 @@ var unassociatedLabel = {
|
|
|
11880
14336
|
};
|
|
11881
14337
|
|
|
11882
14338
|
// src/quality/rules/failed-read-empty-state.ts
|
|
11883
|
-
var
|
|
14339
|
+
var import_traverse6 = __toESM(require("@babel/traverse"), 1);
|
|
11884
14340
|
var import_types = require("@babel/types");
|
|
11885
14341
|
|
|
11886
14342
|
// src/quality/rules/scope.ts
|
|
11887
|
-
function
|
|
14343
|
+
function unwrap2(node) {
|
|
11888
14344
|
let cur = node;
|
|
11889
14345
|
while (cur.type === "TSAsExpression" || cur.type === "TSNonNullExpression" || cur.type === "TSTypeAssertion" || cur.type === "TSSatisfiesExpression") {
|
|
11890
14346
|
cur = cur.expression;
|
|
@@ -11930,7 +14386,7 @@ function isEmptyInitial(node) {
|
|
|
11930
14386
|
}
|
|
11931
14387
|
|
|
11932
14388
|
// src/quality/rules/failed-read-empty-state.ts
|
|
11933
|
-
var
|
|
14389
|
+
var traverse5 = typeof import_traverse6.default === "function" ? import_traverse6.default : import_traverse6.default.default;
|
|
11934
14390
|
var READ_ERROR_PATH_SIGNALS = ERROR_PATH_SIGNALS.filter(
|
|
11935
14391
|
(re) => re.source !== /\.catch\s*\(/.source
|
|
11936
14392
|
);
|
|
@@ -11951,10 +14407,10 @@ function mentionsJsonParse(node, code) {
|
|
|
11951
14407
|
return /\.json\s*\(/.test(code.slice(nodeStart(node), nodeEnd(node)));
|
|
11952
14408
|
}
|
|
11953
14409
|
function chainParsesBody(node, code) {
|
|
11954
|
-
let cur =
|
|
14410
|
+
let cur = unwrap2(node);
|
|
11955
14411
|
for (; ; ) {
|
|
11956
14412
|
if (cur.type === "CallExpression" || cur.type === "OptionalCallExpression") {
|
|
11957
|
-
const callee =
|
|
14413
|
+
const callee = unwrap2(cur.callee);
|
|
11958
14414
|
if ((callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") && callee.property.type === "Identifier") {
|
|
11959
14415
|
const method = callee.property.name;
|
|
11960
14416
|
if (method === "json") return true;
|
|
@@ -11964,14 +14420,14 @@ function chainParsesBody(node, code) {
|
|
|
11964
14420
|
return true;
|
|
11965
14421
|
}
|
|
11966
14422
|
}
|
|
11967
|
-
cur =
|
|
14423
|
+
cur = unwrap2(callee.object);
|
|
11968
14424
|
continue;
|
|
11969
14425
|
}
|
|
11970
14426
|
cur = callee;
|
|
11971
14427
|
continue;
|
|
11972
14428
|
}
|
|
11973
14429
|
if (cur.type === "MemberExpression" || cur.type === "OptionalMemberExpression") {
|
|
11974
|
-
cur =
|
|
14430
|
+
cur = unwrap2(cur.object);
|
|
11975
14431
|
continue;
|
|
11976
14432
|
}
|
|
11977
14433
|
return false;
|
|
@@ -11985,7 +14441,7 @@ function parsedBodyBindings(unit, code) {
|
|
|
11985
14441
|
const names = /* @__PURE__ */ new Set();
|
|
11986
14442
|
const record = (id, init) => {
|
|
11987
14443
|
if (!id || !init) return;
|
|
11988
|
-
const awaited =
|
|
14444
|
+
const awaited = unwrap2(init);
|
|
11989
14445
|
if (awaited.type !== "AwaitExpression") return;
|
|
11990
14446
|
if (!chainParsesBody(awaited.argument, code)) return;
|
|
11991
14447
|
boundNames(id, names);
|
|
@@ -12021,12 +14477,12 @@ function parsedBodyBindings(unit, code) {
|
|
|
12021
14477
|
return names;
|
|
12022
14478
|
}
|
|
12023
14479
|
function derivesFromParsedBody(node, bodies, code) {
|
|
12024
|
-
let cur =
|
|
14480
|
+
let cur = unwrap2(node);
|
|
12025
14481
|
while (cur && (cur.type === "MemberExpression" || cur.type === "OptionalMemberExpression")) {
|
|
12026
|
-
cur =
|
|
14482
|
+
cur = unwrap2(cur.object);
|
|
12027
14483
|
}
|
|
12028
14484
|
if (cur.type === "Identifier") return bodies.has(cur.name);
|
|
12029
|
-
if (cur.type === "AwaitExpression") cur =
|
|
14485
|
+
if (cur.type === "AwaitExpression") cur = unwrap2(cur.argument);
|
|
12030
14486
|
return chainParsesBody(cur, code);
|
|
12031
14487
|
}
|
|
12032
14488
|
function emptyFallbackArgument(node) {
|
|
@@ -12081,7 +14537,7 @@ var failedReadEmptyState = {
|
|
|
12081
14537
|
const parsed = file.parsed;
|
|
12082
14538
|
if (!parsed) continue;
|
|
12083
14539
|
const examined = /* @__PURE__ */ new Set();
|
|
12084
|
-
|
|
14540
|
+
traverse5(parsed.ast, {
|
|
12085
14541
|
CallExpression(path) {
|
|
12086
14542
|
if (!isFetchCallee(path.node.callee)) return;
|
|
12087
14543
|
const unit = unitFor(path);
|
|
@@ -12103,7 +14559,7 @@ var failedReadEmptyState = {
|
|
|
12103
14559
|
const fallback = emptyFallbackArgument(arg);
|
|
12104
14560
|
if (!fallback) return;
|
|
12105
14561
|
if (!derivesFromParsedBody(fallback.left, bodies, file.code)) return;
|
|
12106
|
-
hit = { line:
|
|
14562
|
+
hit = { line: lineAt2(file.content, nodeStart(fallback)), setter: name };
|
|
12107
14563
|
}
|
|
12108
14564
|
});
|
|
12109
14565
|
if (!hit) return;
|
|
@@ -12121,8 +14577,8 @@ var failedReadEmptyState = {
|
|
|
12121
14577
|
};
|
|
12122
14578
|
|
|
12123
14579
|
// src/quality/rules/autosave-armed-by-failed-load.ts
|
|
12124
|
-
var
|
|
12125
|
-
var
|
|
14580
|
+
var import_traverse7 = __toESM(require("@babel/traverse"), 1);
|
|
14581
|
+
var traverse6 = typeof import_traverse7.default === "function" ? import_traverse7.default : import_traverse7.default.default;
|
|
12126
14582
|
function writerTouchesEmptyState(writers) {
|
|
12127
14583
|
for (const writer of writers) {
|
|
12128
14584
|
let found = false;
|
|
@@ -12202,7 +14658,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12202
14658
|
if (!parsed) continue;
|
|
12203
14659
|
if (!EMPTY_INITIAL.test(file.code)) continue;
|
|
12204
14660
|
const armedInFinally = /* @__PURE__ */ new Map();
|
|
12205
|
-
|
|
14661
|
+
traverse6(parsed.ast, {
|
|
12206
14662
|
TryStatement(path) {
|
|
12207
14663
|
const finalizer = path.get("finalizer");
|
|
12208
14664
|
if (!finalizer || Array.isArray(finalizer) || !finalizer.node) return;
|
|
@@ -12220,7 +14676,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12220
14676
|
});
|
|
12221
14677
|
if (armedInFinally.size === 0) continue;
|
|
12222
14678
|
const writingFunctions = /* @__PURE__ */ new Map();
|
|
12223
|
-
|
|
14679
|
+
traverse6(parsed.ast, {
|
|
12224
14680
|
Function(path) {
|
|
12225
14681
|
const src = file.code.slice(nodeStart(path.node), nodeEnd(path.node));
|
|
12226
14682
|
if (!PERSISTENT_WRITE.test(src)) return;
|
|
@@ -12241,7 +14697,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12241
14697
|
}
|
|
12242
14698
|
});
|
|
12243
14699
|
const reported = /* @__PURE__ */ new Set();
|
|
12244
|
-
|
|
14700
|
+
traverse6(parsed.ast, {
|
|
12245
14701
|
CallExpression(path) {
|
|
12246
14702
|
if (!isEffectCall2(path.node)) return;
|
|
12247
14703
|
const cb = path.get("arguments.0");
|
|
@@ -12265,7 +14721,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12265
14721
|
reported.add(state);
|
|
12266
14722
|
hits.push({
|
|
12267
14723
|
file: file.path,
|
|
12268
|
-
line:
|
|
14724
|
+
line: lineAt2(file.content, armLine),
|
|
12269
14725
|
detail: `\`${state}\` is what permits this component to write the user's state back, and it is set in a \`finally\` \u2014 so a load that threw arms the write exactly like one that succeeded, while the component still holds its initial empty values.`
|
|
12270
14726
|
});
|
|
12271
14727
|
}
|
|
@@ -12277,8 +14733,8 @@ var autosaveArmedByFailedLoad = {
|
|
|
12277
14733
|
};
|
|
12278
14734
|
|
|
12279
14735
|
// src/quality/rules/config-skipped-work.ts
|
|
12280
|
-
var
|
|
12281
|
-
var
|
|
14736
|
+
var import_traverse8 = __toESM(require("@babel/traverse"), 1);
|
|
14737
|
+
var traverse7 = typeof import_traverse8.default === "function" ? import_traverse8.default : import_traverse8.default.default;
|
|
12282
14738
|
var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
12283
14739
|
var DURABLE_WRITE = /\b(?:INSERT\s+INTO\b|UPDATE\s+\w+\s+SET\b|DELETE\s+FROM\b)|\bprisma\s*\.\s*\w+\s*\.\s*(?:create|createMany|update|updateMany|delete|deleteMany|upsert)\s*\(|\.from\s*\([^)]*\)\s*\.\s*(?:insert|update|delete|upsert)\s*\(|\b(?:db|tx|trx)\s*\.\s*(?:insert|update|delete)\s*\(/i;
|
|
12284
14740
|
var EXTERNAL_MUTATION = /\b\w+\s*\.\s*\w+\s*\.\s*(?:create|send|update|delete|cancel|charge|capture|refund)\s*\(|\bfetch\s*\([^)]{0,300}?method\s*:\s*["'`](?:POST|PUT|PATCH|DELETE)["'`]/is;
|
|
@@ -12331,7 +14787,7 @@ var configSkippedWork = {
|
|
|
12331
14787
|
if (BOOKKEEPING.test(file.path)) continue;
|
|
12332
14788
|
const parsed = file.parsed;
|
|
12333
14789
|
if (!parsed) continue;
|
|
12334
|
-
|
|
14790
|
+
traverse7(parsed.ast, {
|
|
12335
14791
|
Function(path) {
|
|
12336
14792
|
const node = path.node;
|
|
12337
14793
|
let name = node.id?.name ?? null;
|
|
@@ -12373,7 +14829,7 @@ var configSkippedWork = {
|
|
|
12373
14829
|
if (writeMatch && BOOKKEEPING.test(after.slice(writeMatch.index, writeMatch.index + 120))) continue;
|
|
12374
14830
|
hits.push({
|
|
12375
14831
|
file: file.path,
|
|
12376
|
-
line:
|
|
14832
|
+
line: lineAt2(file.content, guard.start),
|
|
12377
14833
|
detail: `This early return answers with the same payload shape (\`{${guard.shape}}\`) as the handler's success return, so a caller cannot tell that the work was skipped. ${fnSource.length > 0 ? "" : ""}The write below it never runs, and whoever made the request is told it did.`
|
|
12378
14834
|
});
|
|
12379
14835
|
break;
|
|
@@ -12396,8 +14852,8 @@ function isConfigAbsenceTest(test, ifPath, code) {
|
|
|
12396
14852
|
}
|
|
12397
14853
|
|
|
12398
14854
|
// src/quality/rules/stale-response-wins.ts
|
|
12399
|
-
var
|
|
12400
|
-
var
|
|
14855
|
+
var import_traverse9 = __toESM(require("@babel/traverse"), 1);
|
|
14856
|
+
var traverse8 = typeof import_traverse9.default === "function" ? import_traverse9.default : import_traverse9.default.default;
|
|
12401
14857
|
var ORDERING_GUARD = /\breturn\s*\(\s*\)\s*=>|\bAbortController\b|\bsignal\b|\bcancell?ed\b|\bignore\b|\bstale\b|\bisMounted\b|\baborted\b/i;
|
|
12402
14858
|
var SETTER2 = /^set[A-Z][A-Za-z0-9_]*$/;
|
|
12403
14859
|
function calleeIdentifier2(node) {
|
|
@@ -12493,7 +14949,7 @@ var staleResponseWins = {
|
|
|
12493
14949
|
if (!isClientTarget(file)) continue;
|
|
12494
14950
|
const parsed = file.parsed;
|
|
12495
14951
|
if (!parsed) continue;
|
|
12496
|
-
|
|
14952
|
+
traverse8(parsed.ast, {
|
|
12497
14953
|
CallExpression(path) {
|
|
12498
14954
|
if (!isEffectCall3(path.node)) return;
|
|
12499
14955
|
const args = path.node.arguments;
|
|
@@ -12539,7 +14995,7 @@ var staleResponseWins = {
|
|
|
12539
14995
|
(d) => derivesFromDep(ident2, /* @__PURE__ */ new Set([d]), cb, file.code)
|
|
12540
14996
|
);
|
|
12541
14997
|
if (!driving.some((d) => userDriven(d, cb))) continue;
|
|
12542
|
-
hit = { line:
|
|
14998
|
+
hit = { line: lineAt2(file.content, nodeStart(inner.node)), ident: ident2 };
|
|
12543
14999
|
return;
|
|
12544
15000
|
}
|
|
12545
15001
|
}
|
|
@@ -12580,8 +15036,8 @@ function userDriven(dep, at) {
|
|
|
12580
15036
|
}
|
|
12581
15037
|
|
|
12582
15038
|
// src/quality/rules/lost-update-counter.ts
|
|
12583
|
-
var
|
|
12584
|
-
var
|
|
15039
|
+
var import_traverse10 = __toESM(require("@babel/traverse"), 1);
|
|
15040
|
+
var traverse9 = typeof import_traverse10.default === "function" ? import_traverse10.default : import_traverse10.default.default;
|
|
12585
15041
|
var COUNTER_COLUMN = /^(?:credits?|balance|stock|quantity|qty|tokens?|seats?|points?|inventory|remaining|available)$/i;
|
|
12586
15042
|
var WRITE_CALL = /\bUPDATE\s+\w|\.\s*update\s*\(|\.\s*set\s*\(|\bprisma\s*\.\s*\w+\s*\.\s*update\b/i;
|
|
12587
15043
|
var ATOMIC_OR_SERIALISED = /\b(?:increment|decrement)\s*:|\bsql`[^`]*\b\w+\s*[-+]\s*|\bSET\s+(\w+)\s*=\s*\1\s*[-+]|\.\s*rpc\s*\(|\btransaction\s*\(|\bBEGIN\s+IMMEDIATE\b|\bFOR\s+UPDATE\b|\block\s*\.\s*acquire\s*\(|\bmutex\b|\bredlock\b|\bWHERE[^;]{0,120}\b\w+\s*=\s*\?[^;]{0,40}\bAND\b[^;]{0,120}\bversion\b/i;
|
|
@@ -12619,7 +15075,7 @@ var lostUpdateCounter = {
|
|
|
12619
15075
|
const parsed = file.parsed;
|
|
12620
15076
|
if (!parsed) continue;
|
|
12621
15077
|
let firedInFile = false;
|
|
12622
|
-
|
|
15078
|
+
traverse9(parsed.ast, {
|
|
12623
15079
|
BinaryExpression(path) {
|
|
12624
15080
|
if (firedInFile || hits.length >= MAX_PER_SCAN2) return;
|
|
12625
15081
|
const op = path.node.operator;
|
|
@@ -12646,7 +15102,7 @@ var lostUpdateCounter = {
|
|
|
12646
15102
|
firedInFile = true;
|
|
12647
15103
|
hits.push({
|
|
12648
15104
|
file: file.path,
|
|
12649
|
-
line:
|
|
15105
|
+
line: lineAt2(file.content, nodeStart(path.node)),
|
|
12650
15106
|
detail: `\`${readLocal}.${column}\` is read, changed here, and written back, so two requests that arrive together both start from the same value and one of the two changes is lost. Let the database do the arithmetic instead.`
|
|
12651
15107
|
});
|
|
12652
15108
|
}
|
|
@@ -13178,6 +15634,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
13178
15634
|
attachInlineSuppressed,
|
|
13179
15635
|
attachScanSuppression,
|
|
13180
15636
|
authPrefixCovers,
|
|
15637
|
+
bearerProvenanceSafe,
|
|
13181
15638
|
billingWebhookUnmatchedProps,
|
|
13182
15639
|
bucketFiles,
|
|
13183
15640
|
buildMarkerIndex,
|
|
@@ -13188,6 +15645,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
13188
15645
|
calculateGrade,
|
|
13189
15646
|
callSpreads,
|
|
13190
15647
|
capWarnings,
|
|
15648
|
+
capabilityTokenHandler,
|
|
13191
15649
|
checkIntent,
|
|
13192
15650
|
clampCount,
|
|
13193
15651
|
classifyExposure,
|
|
@@ -13282,11 +15740,15 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
13282
15740
|
parseSupabaseConfig,
|
|
13283
15741
|
perCallTimeoutMs,
|
|
13284
15742
|
planCause,
|
|
15743
|
+
publicHttpsUrl,
|
|
15744
|
+
publicReadOnlyHandler,
|
|
13285
15745
|
publicSuppressedRecord,
|
|
13286
15746
|
qualityRules,
|
|
13287
15747
|
readInlineSuppressed,
|
|
13288
15748
|
readScanSuppression,
|
|
15749
|
+
refineDirectObjectFindings,
|
|
13289
15750
|
replaceBlockComments,
|
|
15751
|
+
resetStructuralState,
|
|
13290
15752
|
routeForFile,
|
|
13291
15753
|
routePathFromFile,
|
|
13292
15754
|
runCustomRules,
|
|
@@ -13297,8 +15759,10 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
13297
15759
|
scanMultiFile,
|
|
13298
15760
|
scanQuality,
|
|
13299
15761
|
scanTokenNullProps,
|
|
15762
|
+
setStructuralFaultForTest,
|
|
13300
15763
|
sqlInjection,
|
|
13301
15764
|
stripeWebhookUnprotected,
|
|
15765
|
+
structuralParseCount,
|
|
13302
15766
|
supabaseFunctionName,
|
|
13303
15767
|
supabaseNoRLS,
|
|
13304
15768
|
suppressionSummary,
|