xploitscan-shared-rules 2.4.25 → 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 +1788 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +1780 -144
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SCANNER_VERSION = "2.4.
|
|
2
|
+
var SCANNER_VERSION = "2.4.26";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -1939,6 +1939,1374 @@ function checkIntent(files, findings) {
|
|
|
1939
1939
|
return { statements, mismatches, sources, unchallenged, uncheckable };
|
|
1940
1940
|
}
|
|
1941
1941
|
|
|
1942
|
+
// src/structural-handlers.ts
|
|
1943
|
+
import _traverse from "@babel/traverse";
|
|
1944
|
+
|
|
1945
|
+
// src/ast/parse.ts
|
|
1946
|
+
import { parse } from "@babel/parser";
|
|
1947
|
+
var MAX_CACHE = 256;
|
|
1948
|
+
var cache = /* @__PURE__ */ new Map();
|
|
1949
|
+
function cacheKey(filename, digest2) {
|
|
1950
|
+
return `${filename}:${digest2}`;
|
|
1951
|
+
}
|
|
1952
|
+
function fullDigest(s) {
|
|
1953
|
+
let h1 = 5381;
|
|
1954
|
+
let h2 = 52711;
|
|
1955
|
+
for (let i = 0; i < s.length; i++) {
|
|
1956
|
+
const c = s.charCodeAt(i);
|
|
1957
|
+
h1 = Math.imul(h1, 33) + c | 0;
|
|
1958
|
+
h2 = Math.imul(h2, 31) + c | 0;
|
|
1959
|
+
}
|
|
1960
|
+
return `${s.length}:${h1}:${h2}`;
|
|
1961
|
+
}
|
|
1962
|
+
function pickLanguage(filename) {
|
|
1963
|
+
if (/\.tsx$/i.test(filename)) return "tsx";
|
|
1964
|
+
if (/\.jsx$/i.test(filename)) return "jsx";
|
|
1965
|
+
if (/\.(ts|cts|mts)$/i.test(filename)) return "ts";
|
|
1966
|
+
if (/\.(js|cjs|mjs)$/i.test(filename)) return "js";
|
|
1967
|
+
return null;
|
|
1968
|
+
}
|
|
1969
|
+
function parseFile(content, filename) {
|
|
1970
|
+
const lang = pickLanguage(filename);
|
|
1971
|
+
if (!lang) return null;
|
|
1972
|
+
if (!content || content.length === 0) return null;
|
|
1973
|
+
const key = cacheKey(filename, fullDigest(content));
|
|
1974
|
+
const hit = cache.get(key);
|
|
1975
|
+
if (hit && hit.content === content) return hit.value;
|
|
1976
|
+
const plugins = [];
|
|
1977
|
+
if (lang === "ts" || lang === "tsx") plugins.push("typescript");
|
|
1978
|
+
if (lang === "jsx" || lang === "tsx") plugins.push("jsx");
|
|
1979
|
+
plugins.push("decorators-legacy", "classProperties", "dynamicImport", "topLevelAwait");
|
|
1980
|
+
let ast = null;
|
|
1981
|
+
try {
|
|
1982
|
+
ast = parse(content, {
|
|
1983
|
+
sourceType: "unambiguous",
|
|
1984
|
+
allowImportExportEverywhere: true,
|
|
1985
|
+
allowReturnOutsideFunction: true,
|
|
1986
|
+
allowAwaitOutsideFunction: true,
|
|
1987
|
+
allowUndeclaredExports: true,
|
|
1988
|
+
errorRecovery: true,
|
|
1989
|
+
plugins
|
|
1990
|
+
});
|
|
1991
|
+
} catch {
|
|
1992
|
+
cache.set(key, { content, value: null });
|
|
1993
|
+
if (cache.size > MAX_CACHE) {
|
|
1994
|
+
const firstKey = cache.keys().next().value;
|
|
1995
|
+
if (firstKey !== void 0) cache.delete(firstKey);
|
|
1996
|
+
}
|
|
1997
|
+
return null;
|
|
1998
|
+
}
|
|
1999
|
+
const entry = { ast, language: lang };
|
|
2000
|
+
cache.set(key, { content, value: entry });
|
|
2001
|
+
if (cache.size > MAX_CACHE) {
|
|
2002
|
+
const firstKey = cache.keys().next().value;
|
|
2003
|
+
if (firstKey !== void 0) cache.delete(firstKey);
|
|
2004
|
+
}
|
|
2005
|
+
return entry;
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
// src/structural-handlers.ts
|
|
2009
|
+
var traverse = typeof _traverse === "function" ? _traverse : _traverse.default;
|
|
2010
|
+
var PARSE_BYTES = 256 * 1024;
|
|
2011
|
+
var LOOKUP_LIMIT = 200;
|
|
2012
|
+
var METHODS = /* @__PURE__ */ new Set(["get", "head", "post", "put", "patch", "delete"]);
|
|
2013
|
+
var ROLE_WORD = /^(admin|superadmin|staff|owner)$/i;
|
|
2014
|
+
var faultName = null;
|
|
2015
|
+
var parseCount = 0;
|
|
2016
|
+
var modelCache = /* @__PURE__ */ new Map();
|
|
2017
|
+
var bearerSpanCache = /* @__PURE__ */ new Map();
|
|
2018
|
+
function setStructuralFaultForTest(name) {
|
|
2019
|
+
faultName = name;
|
|
2020
|
+
}
|
|
2021
|
+
function structuralParseCount() {
|
|
2022
|
+
return parseCount;
|
|
2023
|
+
}
|
|
2024
|
+
function resetStructuralState() {
|
|
2025
|
+
parseCount = 0;
|
|
2026
|
+
modelCache.clear();
|
|
2027
|
+
bearerSpanCache.clear();
|
|
2028
|
+
faultName = null;
|
|
2029
|
+
}
|
|
2030
|
+
function fault(name) {
|
|
2031
|
+
if (faultName === name || faultName === "all") throw new Error("injected");
|
|
2032
|
+
}
|
|
2033
|
+
function digest(text) {
|
|
2034
|
+
let h1 = 5381;
|
|
2035
|
+
let h2 = 52711;
|
|
2036
|
+
for (let i = 0; i < text.length; i++) {
|
|
2037
|
+
const c = text.charCodeAt(i);
|
|
2038
|
+
h1 = Math.imul(h1, 33) + c | 0;
|
|
2039
|
+
h2 = Math.imul(h2, 31) + c | 0;
|
|
2040
|
+
}
|
|
2041
|
+
return `${text.length}:${h1}:${h2}`;
|
|
2042
|
+
}
|
|
2043
|
+
function lineAt(content, index) {
|
|
2044
|
+
let line = 1;
|
|
2045
|
+
const end = Math.min(index, content.length);
|
|
2046
|
+
for (let i = 0; i < end; i++) if (content.charCodeAt(i) === 10) line++;
|
|
2047
|
+
return line;
|
|
2048
|
+
}
|
|
2049
|
+
function unwrap(node) {
|
|
2050
|
+
let cur = node;
|
|
2051
|
+
while (cur) {
|
|
2052
|
+
if (cur.type === "AwaitExpression" || cur.type === "ParenthesizedExpression" || cur.type === "TSAsExpression" || cur.type === "TSNonNullExpression" || cur.type === "TSSatisfiesExpression" || cur.type === "TSTypeAssertion" || cur.type === "ChainExpression") {
|
|
2053
|
+
cur = cur.expression ?? cur.argument;
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
break;
|
|
2057
|
+
}
|
|
2058
|
+
return cur;
|
|
2059
|
+
}
|
|
2060
|
+
function propName(prop) {
|
|
2061
|
+
if (!prop) return "";
|
|
2062
|
+
if (prop.key?.type === "Identifier" && !prop.computed) return String(prop.key.name);
|
|
2063
|
+
if (prop.key?.type === "StringLiteral") return String(prop.key.value);
|
|
2064
|
+
return "";
|
|
2065
|
+
}
|
|
2066
|
+
function walk(node, visit) {
|
|
2067
|
+
if (!node || typeof node !== "object" || !node.type) return;
|
|
2068
|
+
visit(node);
|
|
2069
|
+
for (const key of Object.keys(node)) {
|
|
2070
|
+
if (key === "loc" || key === "start" || key === "end" || key === "range" || key === "leadingComments" || key === "trailingComments" || key === "innerComments") {
|
|
2071
|
+
continue;
|
|
2072
|
+
}
|
|
2073
|
+
const child = node[key];
|
|
2074
|
+
if (Array.isArray(child)) {
|
|
2075
|
+
for (const item of child) if (item && typeof item === "object" && item.type) walk(item, visit);
|
|
2076
|
+
} else if (child && typeof child === "object" && child.type) {
|
|
2077
|
+
walk(child, visit);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
function paramNames(fn) {
|
|
2082
|
+
const names = [];
|
|
2083
|
+
for (const param of fn.params ?? []) {
|
|
2084
|
+
if (param?.type === "Identifier") names.push(param.name);
|
|
2085
|
+
else if (param?.type === "AssignmentPattern" && param.left?.type === "Identifier") names.push(param.left.name);
|
|
2086
|
+
else if (param?.type === "ObjectPattern") {
|
|
2087
|
+
for (const prop of param.properties ?? []) {
|
|
2088
|
+
if (prop?.type === "ObjectProperty" && prop.key?.type === "Identifier") names.push(prop.key.name);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
return names;
|
|
2093
|
+
}
|
|
2094
|
+
function statementsOf(fn) {
|
|
2095
|
+
const body = fn?.body;
|
|
2096
|
+
if (!body) return [];
|
|
2097
|
+
if (body.type === "BlockStatement") return body.body ?? [];
|
|
2098
|
+
return [{ type: "ReturnStatement", argument: body, start: body.start, end: body.end }];
|
|
2099
|
+
}
|
|
2100
|
+
function usable(parsed, content) {
|
|
2101
|
+
if (!parsed?.ast) return false;
|
|
2102
|
+
const ast = parsed.ast;
|
|
2103
|
+
if (Array.isArray(ast.errors) && ast.errors.length > 0) return false;
|
|
2104
|
+
if (typeof ast.end === "number" && ast.end !== content.length) return false;
|
|
2105
|
+
return true;
|
|
2106
|
+
}
|
|
2107
|
+
function controlScope(path) {
|
|
2108
|
+
let cur = path?.parentPath;
|
|
2109
|
+
while (cur) {
|
|
2110
|
+
const t = cur.node?.type;
|
|
2111
|
+
if (t === "IfStatement" || t === "ForStatement" || t === "WhileStatement" || t === "DoWhileStatement" || t === "ForInStatement" || t === "ForOfStatement" || t === "SwitchStatement" || t === "TryStatement" || t === "CatchClause" || t === "ConditionalExpression") {
|
|
2112
|
+
return null;
|
|
2113
|
+
}
|
|
2114
|
+
if (t === "FunctionDeclaration" || t === "FunctionExpression" || t === "ArrowFunctionExpression" || t === "ObjectMethod" || t === "ClassMethod") {
|
|
2115
|
+
return cur.node.start ?? 0;
|
|
2116
|
+
}
|
|
2117
|
+
if (t === "Program") return 0;
|
|
2118
|
+
cur = cur.parentPath;
|
|
2119
|
+
}
|
|
2120
|
+
return 0;
|
|
2121
|
+
}
|
|
2122
|
+
function stringEntries(node) {
|
|
2123
|
+
const value = unwrap(node);
|
|
2124
|
+
if (!value) return null;
|
|
2125
|
+
let array = value;
|
|
2126
|
+
if (value.type === "NewExpression" && value.callee?.type === "Identifier" && value.callee.name === "Set") {
|
|
2127
|
+
if ((value.arguments ?? []).length !== 1) return null;
|
|
2128
|
+
array = value.arguments[0];
|
|
2129
|
+
}
|
|
2130
|
+
if (array?.type !== "ArrayExpression") return null;
|
|
2131
|
+
const entries = [];
|
|
2132
|
+
for (const el of array.elements ?? []) {
|
|
2133
|
+
if (!el || el.type !== "StringLiteral") return null;
|
|
2134
|
+
entries.push(String(el.value));
|
|
2135
|
+
}
|
|
2136
|
+
return entries.length > 0 ? entries : null;
|
|
2137
|
+
}
|
|
2138
|
+
function staticString(node) {
|
|
2139
|
+
const value = unwrap(node);
|
|
2140
|
+
if (!value) return null;
|
|
2141
|
+
if (value.type === "StringLiteral") return String(value.value);
|
|
2142
|
+
if (value.type === "TemplateLiteral" && (value.expressions ?? []).length === 0) {
|
|
2143
|
+
return value.quasis.map((q) => q.value?.cooked ?? "").join("");
|
|
2144
|
+
}
|
|
2145
|
+
return null;
|
|
2146
|
+
}
|
|
2147
|
+
function isProcessEnv(node) {
|
|
2148
|
+
const value = unwrap(node);
|
|
2149
|
+
if (value?.type !== "MemberExpression" || value.computed) return false;
|
|
2150
|
+
if (value.property?.type !== "Identifier") return false;
|
|
2151
|
+
const env = value.object;
|
|
2152
|
+
return env?.type === "MemberExpression" && !env.computed && env.property?.name === "env" && env.object?.type === "Identifier" && env.object.name === "process";
|
|
2153
|
+
}
|
|
2154
|
+
function isEnvRead(node) {
|
|
2155
|
+
const value = unwrap(node);
|
|
2156
|
+
if (!value) return false;
|
|
2157
|
+
if (value.type === "MemberExpression") {
|
|
2158
|
+
if (value.object?.type === "Identifier" && value.object.name === "process" && value.property?.name === "env") return true;
|
|
2159
|
+
if (isProcessEnv(value)) return true;
|
|
2160
|
+
if (value.object?.type === "Identifier" && value.object.name === "env") return true;
|
|
2161
|
+
if (value.object?.type === "MemberExpression" && value.object.property?.name === "env" && (value.object.object?.name === "Deno" || value.object.object?.name === "Bun")) {
|
|
2162
|
+
return true;
|
|
2163
|
+
}
|
|
2164
|
+
if (value.object?.type === "MetaProperty" && value.property?.name === "env") return true;
|
|
2165
|
+
}
|
|
2166
|
+
if (value.type === "CallExpression" && value.callee?.type === "MemberExpression" && value.callee.property?.name === "get" && value.callee.object?.type === "MemberExpression" && value.callee.object.property?.name === "env") {
|
|
2167
|
+
return true;
|
|
2168
|
+
}
|
|
2169
|
+
return false;
|
|
2170
|
+
}
|
|
2171
|
+
function registrationOk(content, start, method, appRouter) {
|
|
2172
|
+
const slice = content.slice(start, start + 160).replace(/^\s+/, "");
|
|
2173
|
+
if (appRouter) return new RegExp(`^export\\s+(?:async\\s+)?function\\s+${method}\\b`).test(slice);
|
|
2174
|
+
return new RegExp(`^[A-Za-z_$][\\w$]*\\s*\\.\\s*${method}\\s*\\(`, "i").test(slice);
|
|
2175
|
+
}
|
|
2176
|
+
function pushHandler(handlers, content, fn, method, path, receiver, line, regStart, routeArgs, appRouter, scope) {
|
|
2177
|
+
if (typeof fn?.start !== "number" || typeof fn?.end !== "number") return;
|
|
2178
|
+
if (!registrationOk(content, regStart, appRouter ? method.toUpperCase() : method, appRouter)) return;
|
|
2179
|
+
const params = paramNames(fn);
|
|
2180
|
+
handlers.push({
|
|
2181
|
+
method,
|
|
2182
|
+
path,
|
|
2183
|
+
receiver,
|
|
2184
|
+
line,
|
|
2185
|
+
fnStart: fn.start,
|
|
2186
|
+
fnEnd: fn.end,
|
|
2187
|
+
regStart,
|
|
2188
|
+
params,
|
|
2189
|
+
statements: statementsOf(fn),
|
|
2190
|
+
fn,
|
|
2191
|
+
appRouter,
|
|
2192
|
+
routeArgs,
|
|
2193
|
+
scope,
|
|
2194
|
+
requestName: params[0] ?? "req",
|
|
2195
|
+
replyName: params[1] ?? "res"
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
function build(parsed, content) {
|
|
2199
|
+
const ast = parsed.ast;
|
|
2200
|
+
const handlers = [];
|
|
2201
|
+
const uses = [];
|
|
2202
|
+
const functions = [];
|
|
2203
|
+
const consts = /* @__PURE__ */ new Set();
|
|
2204
|
+
const assigned = /* @__PURE__ */ new Set();
|
|
2205
|
+
traverse(ast, {
|
|
2206
|
+
FunctionExpression(path) {
|
|
2207
|
+
const node = path.node;
|
|
2208
|
+
if (typeof node.start === "number" && typeof node.end === "number") functions.push({ start: node.start, end: node.end });
|
|
2209
|
+
},
|
|
2210
|
+
ArrowFunctionExpression(path) {
|
|
2211
|
+
const node = path.node;
|
|
2212
|
+
if (typeof node.start === "number" && typeof node.end === "number") functions.push({ start: node.start, end: node.end });
|
|
2213
|
+
},
|
|
2214
|
+
VariableDeclaration(path) {
|
|
2215
|
+
if (path.node.kind !== "const") return;
|
|
2216
|
+
for (const decl of path.node.declarations ?? []) {
|
|
2217
|
+
if (decl?.id?.type === "Identifier") consts.add(decl.id.name);
|
|
2218
|
+
}
|
|
2219
|
+
},
|
|
2220
|
+
AssignmentExpression(path) {
|
|
2221
|
+
if (path.node.left?.type === "Identifier") assigned.add(path.node.left.name);
|
|
2222
|
+
},
|
|
2223
|
+
FunctionDeclaration(path) {
|
|
2224
|
+
const node = path.node;
|
|
2225
|
+
if (typeof node.start === "number" && typeof node.end === "number") functions.push({ start: node.start, end: node.end });
|
|
2226
|
+
if (path.parent?.type !== "ExportNamedDeclaration") return;
|
|
2227
|
+
const name = path.node.id?.name;
|
|
2228
|
+
if (!name || !/^(GET|HEAD|POST|PUT|PATCH|DELETE)$/.test(name)) return;
|
|
2229
|
+
const reg = path.parent;
|
|
2230
|
+
pushHandler(
|
|
2231
|
+
handlers,
|
|
2232
|
+
content,
|
|
2233
|
+
path.node,
|
|
2234
|
+
name.toLowerCase(),
|
|
2235
|
+
"",
|
|
2236
|
+
"",
|
|
2237
|
+
reg.loc?.start?.line ?? path.node.loc?.start?.line ?? 0,
|
|
2238
|
+
reg.start ?? path.node.start,
|
|
2239
|
+
[],
|
|
2240
|
+
true,
|
|
2241
|
+
0
|
|
2242
|
+
);
|
|
2243
|
+
},
|
|
2244
|
+
CallExpression(path) {
|
|
2245
|
+
const node = path.node;
|
|
2246
|
+
const callee = node.callee;
|
|
2247
|
+
const deno = callee?.type === "MemberExpression" && callee.object?.name === "Deno" && callee.property?.name === "serve" || callee?.type === "Identifier" && callee.name === "serve";
|
|
2248
|
+
if (deno) {
|
|
2249
|
+
const args2 = node.arguments ?? [];
|
|
2250
|
+
const last2 = args2[args2.length - 1];
|
|
2251
|
+
if (last2?.type === "FunctionExpression" || last2?.type === "ArrowFunctionExpression") {
|
|
2252
|
+
pushHandler(handlers, content, last2, "serve", "", "Deno", node.loc?.start?.line ?? 0, node.start ?? 0, args2.slice(0, -1), false, controlScope(path) ?? 0);
|
|
2253
|
+
}
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
if (callee?.type !== "MemberExpression" || callee.computed || callee.optional) return;
|
|
2257
|
+
if (callee.object?.type !== "Identifier" || callee.property?.type !== "Identifier") return;
|
|
2258
|
+
const method = String(callee.property.name);
|
|
2259
|
+
const receiver = String(callee.object.name);
|
|
2260
|
+
if (method === "use") {
|
|
2261
|
+
uses.push({
|
|
2262
|
+
receiver,
|
|
2263
|
+
start: node.start ?? 0,
|
|
2264
|
+
args: node.arguments ?? [],
|
|
2265
|
+
scope: controlScope(path),
|
|
2266
|
+
constReceiver: consts.has(receiver) && !assigned.has(receiver)
|
|
2267
|
+
});
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
const lower = method.toLowerCase();
|
|
2271
|
+
if (!METHODS.has(lower)) return;
|
|
2272
|
+
const args = node.arguments ?? [];
|
|
2273
|
+
const last = args[args.length - 1];
|
|
2274
|
+
if (last?.type !== "FunctionExpression" && last?.type !== "ArrowFunctionExpression") return;
|
|
2275
|
+
const pathArg = args[0];
|
|
2276
|
+
const routePath = pathArg?.type === "StringLiteral" ? String(pathArg.value) : staticString(pathArg) ?? "";
|
|
2277
|
+
pushHandler(
|
|
2278
|
+
handlers,
|
|
2279
|
+
content,
|
|
2280
|
+
last,
|
|
2281
|
+
lower,
|
|
2282
|
+
routePath,
|
|
2283
|
+
receiver,
|
|
2284
|
+
node.loc?.start?.line ?? 0,
|
|
2285
|
+
node.start ?? 0,
|
|
2286
|
+
args.slice(0, -1),
|
|
2287
|
+
false,
|
|
2288
|
+
controlScope(path) ?? 0
|
|
2289
|
+
);
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
for (const use of uses) use.constReceiver = consts.has(use.receiver) && !assigned.has(use.receiver);
|
|
2293
|
+
return {
|
|
2294
|
+
ast,
|
|
2295
|
+
handlers,
|
|
2296
|
+
uses,
|
|
2297
|
+
functions,
|
|
2298
|
+
sets: moduleSets(ast),
|
|
2299
|
+
primitives: modulePrimitives(ast),
|
|
2300
|
+
cryptoName: importedName(ast, ["crypto", "node:crypto"]),
|
|
2301
|
+
hasherNames: importedNames(ast, ["bcrypt", "bcryptjs", "argon2"]),
|
|
2302
|
+
hashFns: hashFunctions(ast, importedName(ast, ["crypto", "node:crypto"])),
|
|
2303
|
+
randomNames: randomBindings(ast, importedName(ast, ["crypto", "node:crypto"]))
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
function topLevel(ast) {
|
|
2307
|
+
const out = [];
|
|
2308
|
+
for (const stmt of ast.program?.body ?? []) {
|
|
2309
|
+
if (stmt?.type === "ExportNamedDeclaration" && stmt.declaration) out.push(stmt.declaration);
|
|
2310
|
+
else out.push(stmt);
|
|
2311
|
+
}
|
|
2312
|
+
return out;
|
|
2313
|
+
}
|
|
2314
|
+
function moduleSets(ast) {
|
|
2315
|
+
const sets = /* @__PURE__ */ new Map();
|
|
2316
|
+
for (const stmt of topLevel(ast)) {
|
|
2317
|
+
if (stmt?.type !== "VariableDeclaration" || stmt.kind !== "const") continue;
|
|
2318
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2319
|
+
if (decl?.id?.type !== "Identifier") continue;
|
|
2320
|
+
const entries = stringEntries(decl.init);
|
|
2321
|
+
if (!entries) continue;
|
|
2322
|
+
if (entries.every((entry) => publicHttpsUrl(httpsHost(entry)))) sets.set(decl.id.name, entries);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
const mutated = /* @__PURE__ */ new Set();
|
|
2326
|
+
walk(ast, (node) => {
|
|
2327
|
+
if (node.type === "AssignmentExpression" && node.left?.type === "Identifier" && sets.has(node.left.name)) mutated.add(node.left.name);
|
|
2328
|
+
if (node.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.type === "Identifier") {
|
|
2329
|
+
const name = node.callee.property?.name;
|
|
2330
|
+
if ((name === "add" || name === "delete" || name === "clear" || name === "push") && sets.has(node.callee.object.name)) {
|
|
2331
|
+
mutated.add(node.callee.object.name);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
});
|
|
2335
|
+
for (const name of mutated) sets.delete(name);
|
|
2336
|
+
return sets;
|
|
2337
|
+
}
|
|
2338
|
+
function httpsHost(host) {
|
|
2339
|
+
return host.includes("://") ? host : `https://${host}`;
|
|
2340
|
+
}
|
|
2341
|
+
function modulePrimitives(ast) {
|
|
2342
|
+
const names = /* @__PURE__ */ new Set();
|
|
2343
|
+
for (const stmt of topLevel(ast)) {
|
|
2344
|
+
if (stmt?.type !== "VariableDeclaration" || stmt.kind !== "const") continue;
|
|
2345
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2346
|
+
const init = unwrap(decl?.init);
|
|
2347
|
+
if (decl?.id?.type === "Identifier" && init && (init.type === "StringLiteral" || init.type === "NumericLiteral" || init.type === "BooleanLiteral")) {
|
|
2348
|
+
names.add(decl.id.name);
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
return names;
|
|
2353
|
+
}
|
|
2354
|
+
function importedName(ast, sources) {
|
|
2355
|
+
const names = importedNames(ast, sources);
|
|
2356
|
+
return names.values().next().value ?? null;
|
|
2357
|
+
}
|
|
2358
|
+
function importedNames(ast, sources) {
|
|
2359
|
+
const names = /* @__PURE__ */ new Set();
|
|
2360
|
+
const accept = new Set(sources);
|
|
2361
|
+
for (const stmt of ast.program?.body ?? []) {
|
|
2362
|
+
if (stmt?.type === "ImportDeclaration" && accept.has(String(stmt.source?.value))) {
|
|
2363
|
+
for (const spec of stmt.specifiers ?? []) {
|
|
2364
|
+
if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportNamespaceSpecifier") names.add(spec.local.name);
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
if (stmt?.type === "VariableDeclaration") {
|
|
2368
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2369
|
+
const init = unwrap(decl?.init);
|
|
2370
|
+
if (decl?.id?.type !== "Identifier" || init?.type !== "CallExpression") continue;
|
|
2371
|
+
if (init.callee?.type !== "Identifier" || init.callee.name !== "require") continue;
|
|
2372
|
+
const arg = init.arguments?.[0];
|
|
2373
|
+
if (arg?.type === "StringLiteral" && accept.has(String(arg.value))) names.add(decl.id.name);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
return names;
|
|
2378
|
+
}
|
|
2379
|
+
function isCreateHashChain(node, param, cryptoName) {
|
|
2380
|
+
const digest2 = unwrap(node);
|
|
2381
|
+
if (digest2?.type !== "CallExpression" || digest2.callee?.type !== "MemberExpression" || digest2.callee.property?.name !== "digest") return false;
|
|
2382
|
+
const digestArgs = digest2.arguments ?? [];
|
|
2383
|
+
if (digestArgs.length > 1) return false;
|
|
2384
|
+
if (digestArgs.length === 1 && digestArgs[0]?.type !== "StringLiteral") return false;
|
|
2385
|
+
const update = digest2.callee.object;
|
|
2386
|
+
if (update?.type !== "CallExpression" || update.callee?.type !== "MemberExpression" || update.callee.property?.name !== "update") return false;
|
|
2387
|
+
if ((update.arguments ?? []).length !== 1 || update.arguments[0]?.type !== "Identifier" || update.arguments[0].name !== param) return false;
|
|
2388
|
+
const created = update.callee.object;
|
|
2389
|
+
if (created?.type !== "CallExpression" || created.callee?.type !== "MemberExpression") return false;
|
|
2390
|
+
if (created.callee.property?.name !== "createHash" || created.callee.object?.name !== cryptoName) return false;
|
|
2391
|
+
return (created.arguments ?? []).length === 1 && created.arguments[0]?.type === "StringLiteral";
|
|
2392
|
+
}
|
|
2393
|
+
function hashFunctions(ast, cryptoName) {
|
|
2394
|
+
const names = /* @__PURE__ */ new Set();
|
|
2395
|
+
if (!cryptoName) return names;
|
|
2396
|
+
walk(ast, (node) => {
|
|
2397
|
+
if (node.type === "FunctionDeclaration" && node.id?.name && hashBody(node, cryptoName)) names.add(node.id.name);
|
|
2398
|
+
if (node.type === "VariableDeclarator" && node.id?.type === "Identifier") {
|
|
2399
|
+
const init = node.init;
|
|
2400
|
+
if ((init?.type === "ArrowFunctionExpression" || init?.type === "FunctionExpression") && hashBody(init, cryptoName)) names.add(node.id.name);
|
|
2401
|
+
}
|
|
2402
|
+
});
|
|
2403
|
+
return names;
|
|
2404
|
+
}
|
|
2405
|
+
function hashBody(fn, cryptoName) {
|
|
2406
|
+
if ((fn.params ?? []).length !== 1 || fn.params[0]?.type !== "Identifier") return false;
|
|
2407
|
+
const param = fn.params[0].name;
|
|
2408
|
+
let body = fn.body;
|
|
2409
|
+
if (body?.type === "BlockStatement") {
|
|
2410
|
+
if ((body.body ?? []).length !== 1 || body.body[0]?.type !== "ReturnStatement") return false;
|
|
2411
|
+
body = body.body[0].argument;
|
|
2412
|
+
}
|
|
2413
|
+
return isCreateHashChain(body, param, cryptoName);
|
|
2414
|
+
}
|
|
2415
|
+
function randomBindings(ast, cryptoName) {
|
|
2416
|
+
const names = /* @__PURE__ */ new Set();
|
|
2417
|
+
if (!cryptoName) return names;
|
|
2418
|
+
walk(ast, (node) => {
|
|
2419
|
+
if (node.type !== "VariableDeclarator" || node.id?.type !== "Identifier") return;
|
|
2420
|
+
if (isRandomBytes(unwrap(node.init), cryptoName)) names.add(node.id.name);
|
|
2421
|
+
});
|
|
2422
|
+
return names;
|
|
2423
|
+
}
|
|
2424
|
+
function isRandomBytes(node, cryptoName) {
|
|
2425
|
+
let call = node;
|
|
2426
|
+
if (call?.type === "CallExpression" && call.callee?.type === "MemberExpression" && call.callee.property?.name === "toString") {
|
|
2427
|
+
call = call.callee.object;
|
|
2428
|
+
}
|
|
2429
|
+
if (call?.type !== "CallExpression" || call.callee?.type !== "MemberExpression" || call.callee.property?.name !== "randomBytes") return false;
|
|
2430
|
+
if (call.callee.object?.name !== cryptoName) return false;
|
|
2431
|
+
const n = call.arguments?.[0];
|
|
2432
|
+
return n?.type === "NumericLiteral" && typeof n.value === "number" && n.value >= 16 && (call.arguments ?? []).length === 1;
|
|
2433
|
+
}
|
|
2434
|
+
function load(content, filePath) {
|
|
2435
|
+
fault("parse");
|
|
2436
|
+
if (content.length > PARSE_BYTES) return null;
|
|
2437
|
+
const key = `${filePath}\0${digest(content)}`;
|
|
2438
|
+
const hit = modelCache.get(key);
|
|
2439
|
+
if (hit && hit.content === content) return hit.model;
|
|
2440
|
+
parseCount += 1;
|
|
2441
|
+
const parsed = parseFile(content, filePath);
|
|
2442
|
+
const model = parsed && usable(parsed, content) ? build(parsed, content) : null;
|
|
2443
|
+
modelCache.set(key, { content, model });
|
|
2444
|
+
if (modelCache.size > 128) {
|
|
2445
|
+
const first = modelCache.keys().next().value;
|
|
2446
|
+
if (first !== void 0) modelCache.delete(first);
|
|
2447
|
+
}
|
|
2448
|
+
return model;
|
|
2449
|
+
}
|
|
2450
|
+
function onLine(model, content, index) {
|
|
2451
|
+
const line = lineAt(content, index);
|
|
2452
|
+
const found = model.handlers.filter((handler) => handler.line === line);
|
|
2453
|
+
return found.length === 1 ? found[0] : null;
|
|
2454
|
+
}
|
|
2455
|
+
function publicHttpsUrl(value) {
|
|
2456
|
+
try {
|
|
2457
|
+
fault("publicHttpsUrl");
|
|
2458
|
+
const url = new URL(value);
|
|
2459
|
+
if (url.protocol !== "https:") return false;
|
|
2460
|
+
if (url.username || url.password) return false;
|
|
2461
|
+
if (url.port !== "") return false;
|
|
2462
|
+
const host = url.hostname.toLowerCase().replace(/\.$/, "");
|
|
2463
|
+
if (!host || !host.includes(".")) return false;
|
|
2464
|
+
if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(host) || host.includes(":")) return false;
|
|
2465
|
+
if (host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal") || host.endsWith(".lan") || host.endsWith(".home.arpa")) {
|
|
2466
|
+
return false;
|
|
2467
|
+
}
|
|
2468
|
+
return true;
|
|
2469
|
+
} catch {
|
|
2470
|
+
return false;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
function isReq(node, requestName) {
|
|
2474
|
+
const value = unwrap(node);
|
|
2475
|
+
return value?.type === "Identifier" && (value.name === requestName || value.name === "req" || value.name === "request" || value.name === "ctx");
|
|
2476
|
+
}
|
|
2477
|
+
function isRequestInput(node, requestName) {
|
|
2478
|
+
const value = unwrap(node);
|
|
2479
|
+
if (!value || value.type !== "MemberExpression" || value.computed) return false;
|
|
2480
|
+
const prop = value.property?.name;
|
|
2481
|
+
if (["query", "params", "body", "searchParams"].includes(prop) && isReq(value.object, requestName)) return true;
|
|
2482
|
+
return isRequestInput(value.object, requestName);
|
|
2483
|
+
}
|
|
2484
|
+
function hasIdentity(fn, requestName) {
|
|
2485
|
+
let bad = false;
|
|
2486
|
+
walk(fn, (node) => {
|
|
2487
|
+
if (node.type === "CallExpression") {
|
|
2488
|
+
if (node.callee?.type === "Identifier" && (node.callee.name === "cookies" || node.callee.name === "headers")) bad = true;
|
|
2489
|
+
if (node.callee?.type === "MemberExpression" && node.callee.property?.name === "get") {
|
|
2490
|
+
const arg = node.arguments?.[0];
|
|
2491
|
+
if (arg?.type === "StringLiteral" && /^(authorization|cookie|x-api-key)$/i.test(String(arg.value))) bad = true;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
if ((node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && !node.computed) {
|
|
2495
|
+
const prop = node.property?.name;
|
|
2496
|
+
if (["user", "session", "cookies", "auth", "signedCookies"].includes(prop) && isReq(node.object, requestName)) bad = true;
|
|
2497
|
+
if (prop === "user" && node.object?.type === "MemberExpression" && node.object.property?.name === "state") bad = true;
|
|
2498
|
+
}
|
|
2499
|
+
});
|
|
2500
|
+
return bad;
|
|
2501
|
+
}
|
|
2502
|
+
function evalExpr(node, env, depth = 0) {
|
|
2503
|
+
if (!node || depth > 40) return "no";
|
|
2504
|
+
const value = unwrap(node);
|
|
2505
|
+
if (!value) return "no";
|
|
2506
|
+
if (value.type === "StringLiteral" || value.type === "NumericLiteral" || value.type === "BooleanLiteral" || value.type === "NullLiteral") return "value";
|
|
2507
|
+
if (value.type === "TemplateLiteral" && (value.expressions ?? []).length === 0) return "value";
|
|
2508
|
+
if (isEnvRead(value)) {
|
|
2509
|
+
env.bad = true;
|
|
2510
|
+
return "no";
|
|
2511
|
+
}
|
|
2512
|
+
if (value.type === "Identifier") {
|
|
2513
|
+
const known = env.allowed.get(value.name);
|
|
2514
|
+
if (known) return known;
|
|
2515
|
+
if (env.primitives.has(value.name)) return "value";
|
|
2516
|
+
return "no";
|
|
2517
|
+
}
|
|
2518
|
+
if (value.type === "MemberExpression" || value.type === "OptionalMemberExpression") {
|
|
2519
|
+
if (value.optional || value.type === "OptionalMemberExpression") return "no";
|
|
2520
|
+
if (value.computed) {
|
|
2521
|
+
if (isReq(value.property, env.requestName) || isRequestInput(value.property, env.requestName)) env.bad = true;
|
|
2522
|
+
return "no";
|
|
2523
|
+
}
|
|
2524
|
+
if (isRequestInput(value, env.requestName)) return "value";
|
|
2525
|
+
const obj = value.object;
|
|
2526
|
+
if (obj?.type === "Identifier" && env.allowed.get(obj.name) === "url" && (value.property?.name === "hostname" || value.property?.name === "href")) return "value";
|
|
2527
|
+
const inner = evalExpr(obj, env, depth + 1);
|
|
2528
|
+
if (inner === "value") return "value";
|
|
2529
|
+
return "no";
|
|
2530
|
+
}
|
|
2531
|
+
if (value.type === "NewExpression" && value.callee?.type === "Identifier" && value.callee.name === "URL") {
|
|
2532
|
+
if ((value.arguments ?? []).length < 1 || evalExpr(value.arguments[0], env, depth + 1) === "no") return "no";
|
|
2533
|
+
return "url";
|
|
2534
|
+
}
|
|
2535
|
+
if (value.type === "ObjectExpression") {
|
|
2536
|
+
for (const prop of value.properties ?? []) {
|
|
2537
|
+
if (prop?.type !== "ObjectProperty" || prop.computed) return "no";
|
|
2538
|
+
if (evalExpr(prop.value, env, depth + 1) === "no") return "no";
|
|
2539
|
+
}
|
|
2540
|
+
return "value";
|
|
2541
|
+
}
|
|
2542
|
+
if (value.type === "ArrayExpression") {
|
|
2543
|
+
for (const el of value.elements ?? []) if (!el || evalExpr(el, env, depth + 1) === "no") return "no";
|
|
2544
|
+
return "value";
|
|
2545
|
+
}
|
|
2546
|
+
if (value.type === "CallExpression" || value.type === "OptionalCallExpression") {
|
|
2547
|
+
if (value.optional || value.type === "OptionalCallExpression") return "no";
|
|
2548
|
+
return evalCall(value, env, depth);
|
|
2549
|
+
}
|
|
2550
|
+
return "no";
|
|
2551
|
+
}
|
|
2552
|
+
function argsAllowed(node, env, depth) {
|
|
2553
|
+
return (node.arguments ?? []).every((arg) => arg && evalExpr(arg, env, depth + 1) !== "no");
|
|
2554
|
+
}
|
|
2555
|
+
function callbackOk(fn, env) {
|
|
2556
|
+
if (!fn || fn.type !== "ArrowFunctionExpression" && fn.type !== "FunctionExpression") return false;
|
|
2557
|
+
const saved = new Map(env.allowed);
|
|
2558
|
+
const responded = env.responded;
|
|
2559
|
+
const bad = env.bad;
|
|
2560
|
+
for (const name of paramNames(fn)) env.allowed.set(name, "value");
|
|
2561
|
+
let ok = false;
|
|
2562
|
+
if (fn.body?.type === "BlockStatement") ok = (fn.body.body ?? []).every((stmt) => execStmt(stmt, env));
|
|
2563
|
+
else ok = evalExpr(fn.body, env) !== "no";
|
|
2564
|
+
env.allowed = saved;
|
|
2565
|
+
env.responded = responded;
|
|
2566
|
+
env.bad = bad;
|
|
2567
|
+
return ok;
|
|
2568
|
+
}
|
|
2569
|
+
function isReply(node, env) {
|
|
2570
|
+
const value = unwrap(node);
|
|
2571
|
+
return value?.type === "Identifier" && (value.name === "res" || value.name === "reply" || value.name === env.replyName);
|
|
2572
|
+
}
|
|
2573
|
+
function responseCall(node, env, depth) {
|
|
2574
|
+
if (node?.type === "NewExpression" && node.callee?.name === "Response") return argsAllowed(node, env, depth);
|
|
2575
|
+
if (node?.type !== "CallExpression") return false;
|
|
2576
|
+
const callee = node.callee;
|
|
2577
|
+
if (callee?.type === "MemberExpression" && callee.object?.type === "Identifier" && (callee.object.name === "NextResponse" || callee.object.name === "Response") && callee.property?.name === "json") {
|
|
2578
|
+
return argsAllowed(node, env, depth);
|
|
2579
|
+
}
|
|
2580
|
+
if (callee?.type !== "MemberExpression") return false;
|
|
2581
|
+
const prop = callee.property?.name;
|
|
2582
|
+
if (prop === "render") {
|
|
2583
|
+
if (!isReply(callee.object, env)) return false;
|
|
2584
|
+
if (node.arguments?.[0]?.type !== "StringLiteral") return false;
|
|
2585
|
+
return node.arguments.length < 2 || evalExpr(node.arguments[1], env, depth + 1) !== "no";
|
|
2586
|
+
}
|
|
2587
|
+
if (prop !== "json" && prop !== "send" && prop !== "end") return false;
|
|
2588
|
+
const target = callee.object;
|
|
2589
|
+
if (isReply(target, env)) return argsAllowed(node, env, depth);
|
|
2590
|
+
if (target?.type === "CallExpression" && target.callee?.type === "MemberExpression") {
|
|
2591
|
+
const inner = target.callee.property?.name;
|
|
2592
|
+
if ((inner === "status" || inner === "code") && isReply(target.callee.object, env) && target.arguments?.[0]?.type === "NumericLiteral") {
|
|
2593
|
+
return argsAllowed(node, env, depth);
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
return false;
|
|
2597
|
+
}
|
|
2598
|
+
function urlBinding(node, env) {
|
|
2599
|
+
const value = unwrap(node);
|
|
2600
|
+
if (value?.type === "Identifier" && env.allowed.get(value.name) === "url") return value.name;
|
|
2601
|
+
if (value?.type === "MemberExpression" && !value.computed && value.property?.name === "href" && value.object?.type === "Identifier" && env.allowed.get(value.object.name) === "url") {
|
|
2602
|
+
return value.object.name;
|
|
2603
|
+
}
|
|
2604
|
+
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") {
|
|
2605
|
+
return value.callee.object.name;
|
|
2606
|
+
}
|
|
2607
|
+
return null;
|
|
2608
|
+
}
|
|
2609
|
+
var MODEL_PATH = /^\/(?:v\d+(?:beta\d*)?\/)?models\/?$/;
|
|
2610
|
+
function optionState(node) {
|
|
2611
|
+
if (!node) return "absent";
|
|
2612
|
+
if (node.type !== "ObjectExpression") return "bad";
|
|
2613
|
+
let secret = false;
|
|
2614
|
+
for (const prop of node.properties ?? []) {
|
|
2615
|
+
if (prop?.type !== "ObjectProperty" || prop.computed) return "bad";
|
|
2616
|
+
const key = propName(prop);
|
|
2617
|
+
if (key !== "headers" && key !== "cache" && key !== "next" && key !== "method") return "bad";
|
|
2618
|
+
if (key === "method") {
|
|
2619
|
+
const text = staticString(prop.value);
|
|
2620
|
+
if (text !== "GET" && text !== "HEAD" && text !== "get" && text !== "head") return "bad";
|
|
2621
|
+
continue;
|
|
2622
|
+
}
|
|
2623
|
+
if (key === "headers") {
|
|
2624
|
+
if (prop.value?.type !== "ObjectExpression") return "bad";
|
|
2625
|
+
for (const header of prop.value.properties ?? []) {
|
|
2626
|
+
if (header?.type !== "ObjectProperty" || header.computed || !literalValue(header.value)) secret = true;
|
|
2627
|
+
}
|
|
2628
|
+
continue;
|
|
2629
|
+
}
|
|
2630
|
+
if (staticString(prop.value) === null && prop.value?.type !== "NumericLiteral" && prop.value?.type !== "BooleanLiteral") secret = true;
|
|
2631
|
+
}
|
|
2632
|
+
return secret ? "secret" : "ok";
|
|
2633
|
+
}
|
|
2634
|
+
function literalValue(node) {
|
|
2635
|
+
const value = unwrap(node);
|
|
2636
|
+
if (!value) return false;
|
|
2637
|
+
if (value.type === "StringLiteral" || value.type === "NumericLiteral" || value.type === "BooleanLiteral" || value.type === "NullLiteral") return true;
|
|
2638
|
+
if (value.type === "TemplateLiteral") return (value.expressions ?? []).length === 0;
|
|
2639
|
+
if (value.type === "ObjectExpression") {
|
|
2640
|
+
return (value.properties ?? []).every((prop) => prop?.type === "ObjectProperty" && !prop.computed && literalValue(prop.value));
|
|
2641
|
+
}
|
|
2642
|
+
if (value.type === "ArrayExpression") return (value.elements ?? []).every((el) => Boolean(el) && literalValue(el));
|
|
2643
|
+
return false;
|
|
2644
|
+
}
|
|
2645
|
+
function evalCall(node, env, depth) {
|
|
2646
|
+
if (responseCall(node, env, depth)) {
|
|
2647
|
+
env.responded = true;
|
|
2648
|
+
return "value";
|
|
2649
|
+
}
|
|
2650
|
+
const callee = node.callee;
|
|
2651
|
+
if (callee?.type === "Identifier" && callee.name === "fetch") {
|
|
2652
|
+
const state = optionState(node.arguments?.[1]);
|
|
2653
|
+
if (state === "bad" || (node.arguments ?? []).length > 2) return "no";
|
|
2654
|
+
const secret = state === "secret";
|
|
2655
|
+
const literal = staticString(node.arguments?.[0]);
|
|
2656
|
+
if (literal !== null) {
|
|
2657
|
+
if (!publicHttpsUrl(literal)) return "no";
|
|
2658
|
+
if (secret) {
|
|
2659
|
+
const url = new URL(literal);
|
|
2660
|
+
if (url.search || url.hash || !MODEL_PATH.test(url.pathname)) return "no";
|
|
2661
|
+
}
|
|
2662
|
+
env.fetchSeen = true;
|
|
2663
|
+
return "fetch";
|
|
2664
|
+
}
|
|
2665
|
+
const binding = urlBinding(node.arguments?.[0], env);
|
|
2666
|
+
if (!binding || !env.rejected.has(binding) || secret) return "no";
|
|
2667
|
+
env.fetchSeen = true;
|
|
2668
|
+
return "fetch";
|
|
2669
|
+
}
|
|
2670
|
+
if (callee?.type === "Identifier" && (callee.name === "String" || callee.name === "Number" || callee.name === "Boolean")) {
|
|
2671
|
+
return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2672
|
+
}
|
|
2673
|
+
if (callee?.type === "MemberExpression" && !callee.computed) {
|
|
2674
|
+
const obj = callee.object;
|
|
2675
|
+
const prop = callee.property?.name;
|
|
2676
|
+
if (obj?.type === "Identifier" && obj.name === "JSON" && (prop === "parse" || prop === "stringify")) return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2677
|
+
if (obj?.type === "Identifier" && obj.name === "Object" && (prop === "keys" || prop === "values" || prop === "entries")) return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2678
|
+
if (obj?.type === "Identifier" && obj.name === "Array" && prop === "isArray") return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2679
|
+
if ((prop === "json" || prop === "text") && obj?.type === "Identifier" && env.allowed.get(obj.name) === "fetch") return "value";
|
|
2680
|
+
if ((prop === "has" || prop === "includes") && obj?.type === "Identifier" && env.sets.has(obj.name)) return "value";
|
|
2681
|
+
if ((prop === "map" || prop === "filter") && evalExpr(obj, env, depth + 1) === "value") return callbackOk(node.arguments?.[0], env) ? "value" : "no";
|
|
2682
|
+
if ((prop === "slice" || prop === "join" || prop === "toString") && evalExpr(obj, env, depth + 1) !== "no") return argsAllowed(node, env, depth) ? "value" : "no";
|
|
2683
|
+
}
|
|
2684
|
+
return "no";
|
|
2685
|
+
}
|
|
2686
|
+
function has4xx(node) {
|
|
2687
|
+
let number = false;
|
|
2688
|
+
let call = false;
|
|
2689
|
+
walk(node, (current) => {
|
|
2690
|
+
if (current.type === "NumericLiteral" && current.value >= 400 && current.value < 500) number = true;
|
|
2691
|
+
if (current.type === "CallExpression" && ["status", "code", "json", "send"].includes(current.callee?.property?.name)) call = true;
|
|
2692
|
+
});
|
|
2693
|
+
return number && call;
|
|
2694
|
+
}
|
|
2695
|
+
function rejectConsequent(node) {
|
|
2696
|
+
if (!node) return false;
|
|
2697
|
+
if (node.type === "BlockStatement") return (node.body ?? []).length === 1 && rejectConsequent(node.body[0]);
|
|
2698
|
+
if (node.type === "ThrowStatement") return true;
|
|
2699
|
+
if (node.type === "ReturnStatement" || node.type === "ExpressionStatement") {
|
|
2700
|
+
const value = node.argument ?? node.expression;
|
|
2701
|
+
return has4xx(value);
|
|
2702
|
+
}
|
|
2703
|
+
return false;
|
|
2704
|
+
}
|
|
2705
|
+
function allowlistIf(stmt, env) {
|
|
2706
|
+
if (stmt?.type !== "IfStatement" || stmt.alternate || env.fetchSeen) return false;
|
|
2707
|
+
const test = unwrap(stmt.test);
|
|
2708
|
+
if (test?.type !== "UnaryExpression" || test.operator !== "!") return false;
|
|
2709
|
+
const call = unwrap(test.argument);
|
|
2710
|
+
if (call?.type !== "CallExpression" || call.callee?.type !== "MemberExpression") return false;
|
|
2711
|
+
const setName = call.callee.object?.type === "Identifier" ? call.callee.object.name : "";
|
|
2712
|
+
if (!env.sets.has(setName) || call.callee.property?.name !== "has" && call.callee.property?.name !== "includes") return false;
|
|
2713
|
+
const arg = call.arguments?.[0];
|
|
2714
|
+
if (arg?.type !== "MemberExpression" || arg.computed || arg.property?.name !== "hostname" || arg.object?.type !== "Identifier") return false;
|
|
2715
|
+
if (env.allowed.get(arg.object.name) !== "url") return false;
|
|
2716
|
+
if (!rejectConsequent(stmt.consequent)) return false;
|
|
2717
|
+
env.rejected.add(arg.object.name);
|
|
2718
|
+
return true;
|
|
2719
|
+
}
|
|
2720
|
+
function bind(id, kind, env) {
|
|
2721
|
+
if (!id) return false;
|
|
2722
|
+
if (id.type === "Identifier") {
|
|
2723
|
+
env.allowed.set(id.name, kind);
|
|
2724
|
+
return true;
|
|
2725
|
+
}
|
|
2726
|
+
if (id.type === "ObjectPattern") {
|
|
2727
|
+
return (id.properties ?? []).every((prop) => prop?.type === "ObjectProperty" && bind(prop.value, kind, env));
|
|
2728
|
+
}
|
|
2729
|
+
return false;
|
|
2730
|
+
}
|
|
2731
|
+
function execStmt(stmt, env) {
|
|
2732
|
+
if (!stmt || stmt.type === "EmptyStatement") return true;
|
|
2733
|
+
if (allowlistIf(stmt, env)) return true;
|
|
2734
|
+
if (stmt.type === "VariableDeclaration") {
|
|
2735
|
+
if (stmt.kind === "var") return false;
|
|
2736
|
+
if (stmt.kind !== "const") {
|
|
2737
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2738
|
+
const init = unwrap(decl?.init);
|
|
2739
|
+
if (init?.type === "NewExpression" && init.callee?.type === "Identifier" && init.callee.name === "URL") return false;
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
for (const decl of stmt.declarations ?? []) {
|
|
2743
|
+
const kind = evalExpr(decl.init, env);
|
|
2744
|
+
if (kind === "no" || !bind(decl.id, kind, env)) return false;
|
|
2745
|
+
}
|
|
2746
|
+
return true;
|
|
2747
|
+
}
|
|
2748
|
+
if (stmt.type === "ReturnStatement") {
|
|
2749
|
+
if (stmt.argument && evalExpr(stmt.argument, env) === "no") return false;
|
|
2750
|
+
env.responded = true;
|
|
2751
|
+
return true;
|
|
2752
|
+
}
|
|
2753
|
+
if (stmt.type === "ExpressionStatement") {
|
|
2754
|
+
const kind = evalExpr(stmt.expression, env);
|
|
2755
|
+
return kind !== "no";
|
|
2756
|
+
}
|
|
2757
|
+
return false;
|
|
2758
|
+
}
|
|
2759
|
+
function readOnlyBody(content, model, handler) {
|
|
2760
|
+
if (handler.method !== "get" && handler.method !== "head") return false;
|
|
2761
|
+
if (hasIdentity(handler.fn, handler.requestName)) return false;
|
|
2762
|
+
const env = {
|
|
2763
|
+
allowed: /* @__PURE__ */ new Map(),
|
|
2764
|
+
sets: model.sets,
|
|
2765
|
+
primitives: model.primitives,
|
|
2766
|
+
requestName: handler.requestName,
|
|
2767
|
+
replyName: handler.replyName,
|
|
2768
|
+
rejected: /* @__PURE__ */ new Set(),
|
|
2769
|
+
fetchSeen: false,
|
|
2770
|
+
responded: false,
|
|
2771
|
+
bad: false
|
|
2772
|
+
};
|
|
2773
|
+
for (const stmt of handler.statements) {
|
|
2774
|
+
if (!execStmt(stmt, env) || env.bad) return false;
|
|
2775
|
+
}
|
|
2776
|
+
return env.responded && !env.bad && content.length >= 0;
|
|
2777
|
+
}
|
|
2778
|
+
function sourceGuarded(content, handler) {
|
|
2779
|
+
const slice = content.slice(handler.fnStart, handler.fnEnd);
|
|
2780
|
+
return /requireUser|requireAuth|withAuth|getServerSession|\bauth\s*\(|passport|isAuthenticated|verifyAdmin|requireAdmin|verifyToken/.test(slice);
|
|
2781
|
+
}
|
|
2782
|
+
function publicReadOnlyHandler(content, filePath, index, strictApp = false) {
|
|
2783
|
+
try {
|
|
2784
|
+
fault("readOnly");
|
|
2785
|
+
const model = load(content, filePath);
|
|
2786
|
+
if (!model) return false;
|
|
2787
|
+
const handler = onLine(model, content, index);
|
|
2788
|
+
if (!handler || !readOnlyBody(content, model, handler)) return false;
|
|
2789
|
+
if (strictApp && handler.appRouter) {
|
|
2790
|
+
for (const other of model.handlers) {
|
|
2791
|
+
if (!other.appRouter || other === handler) continue;
|
|
2792
|
+
const ok = (other.method === "get" || other.method === "head") && readOnlyBody(content, model, other) || capabilityBody(model, other) || sourceGuarded(content, other);
|
|
2793
|
+
if (!ok) return false;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
return true;
|
|
2797
|
+
} catch {
|
|
2798
|
+
return false;
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
function roleLiteral(node) {
|
|
2802
|
+
if (node?.type === "StringLiteral") return ROLE_WORD.test(String(node.value));
|
|
2803
|
+
if (node?.type === "ArrayExpression") {
|
|
2804
|
+
const elements = node.elements ?? [];
|
|
2805
|
+
return elements.length > 0 && elements.every((el) => el?.type === "StringLiteral" && ROLE_WORD.test(String(el.value)));
|
|
2806
|
+
}
|
|
2807
|
+
return false;
|
|
2808
|
+
}
|
|
2809
|
+
function argIsRole(node) {
|
|
2810
|
+
if (!node) return false;
|
|
2811
|
+
if (node.type === "Identifier") return node.name === "requireAdmin" || node.name === "verifyAdmin";
|
|
2812
|
+
if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "requireRole") {
|
|
2813
|
+
const args = node.arguments ?? [];
|
|
2814
|
+
return args.length > 0 && args.every((arg) => roleLiteral(arg));
|
|
2815
|
+
}
|
|
2816
|
+
if (node.type === "ArrayExpression") return (node.elements ?? []).some((el) => argIsRole(el));
|
|
2817
|
+
return false;
|
|
2818
|
+
}
|
|
2819
|
+
function lookupHasTwoParams(content, lookup, params) {
|
|
2820
|
+
const query = querySlice(content, lookup);
|
|
2821
|
+
if (!query) return false;
|
|
2822
|
+
const used = /* @__PURE__ */ new Set();
|
|
2823
|
+
const re = /req\.params\.([A-Za-z_$][\w$]*)/g;
|
|
2824
|
+
let match;
|
|
2825
|
+
while (match = re.exec(query)) used.add(match[1]);
|
|
2826
|
+
return [...used].filter((name) => params.includes(name)).length >= 2;
|
|
2827
|
+
}
|
|
2828
|
+
function memberScoped(content, handler, lookups) {
|
|
2829
|
+
const params = [...handler.path.matchAll(/:([A-Za-z_$][\w$]*)/g)].map((match) => match[1]);
|
|
2830
|
+
if (params.length < 2) return false;
|
|
2831
|
+
const inside = lookups.filter((index) => index >= handler.fnStart && index < handler.fnEnd);
|
|
2832
|
+
if (inside.length === 0) return false;
|
|
2833
|
+
return inside.every((lookup) => lookupHasTwoParams(content, lookup, params));
|
|
2834
|
+
}
|
|
2835
|
+
function narrowedGuard(content, model, handler, lookups) {
|
|
2836
|
+
const member = (args) => args.some((arg) => arg?.type === "Identifier" && arg.name === "requireMember") && memberScoped(content, handler, lookups);
|
|
2837
|
+
if (handler.routeArgs.some((arg) => argIsRole(arg)) || member(handler.routeArgs)) return true;
|
|
2838
|
+
for (const use of model.uses) {
|
|
2839
|
+
if (use.receiver !== handler.receiver || !handler.receiver) continue;
|
|
2840
|
+
if (use.start >= handler.regStart || use.scope === null || use.scope !== handler.scope || !use.constReceiver) continue;
|
|
2841
|
+
if (use.args.some((arg) => argIsRole(arg)) || member(use.args)) return true;
|
|
2842
|
+
}
|
|
2843
|
+
return false;
|
|
2844
|
+
}
|
|
2845
|
+
function paramAccess(node) {
|
|
2846
|
+
const value = unwrap(node);
|
|
2847
|
+
if (value?.type !== "MemberExpression" || value.computed || value.property?.type !== "Identifier") return null;
|
|
2848
|
+
const prop = String(value.property.name);
|
|
2849
|
+
const obj = value.object;
|
|
2850
|
+
if (obj?.type === "Identifier" && obj.name === "params") return prop;
|
|
2851
|
+
if (obj?.type === "MemberExpression" && !obj.computed && obj.property?.name === "params") return prop;
|
|
2852
|
+
return null;
|
|
2853
|
+
}
|
|
2854
|
+
function isNow(node) {
|
|
2855
|
+
const value = unwrap(node);
|
|
2856
|
+
if (value?.type === "CallExpression" && value.callee?.object?.name === "Date" && value.callee?.property?.name === "now" && (value.arguments ?? []).length === 0) return true;
|
|
2857
|
+
return value?.type === "NewExpression" && value.callee?.name === "Date" && (value.arguments ?? []).length === 0;
|
|
2858
|
+
}
|
|
2859
|
+
function filterOf(obj, hashFns, cryptoName) {
|
|
2860
|
+
let target = obj;
|
|
2861
|
+
if ((obj?.properties ?? []).length === 1 && propName(obj.properties[0]) === "where" && obj.properties[0].value?.type === "ObjectExpression") {
|
|
2862
|
+
target = obj.properties[0].value;
|
|
2863
|
+
}
|
|
2864
|
+
const props = target?.properties ?? [];
|
|
2865
|
+
if (props.length !== 2 || props.some((prop) => prop?.type !== "ObjectProperty")) return null;
|
|
2866
|
+
let field = "";
|
|
2867
|
+
let param = "";
|
|
2868
|
+
let expiry = "";
|
|
2869
|
+
for (const prop of props) {
|
|
2870
|
+
const key = propName(prop);
|
|
2871
|
+
const value = unwrap(prop.value);
|
|
2872
|
+
if (value?.type === "CallExpression" && value.callee?.type === "Identifier" && hashFns.has(value.callee.name)) {
|
|
2873
|
+
if ((value.arguments ?? []).length !== 1) return null;
|
|
2874
|
+
const accessed = paramAccess(value.arguments[0]);
|
|
2875
|
+
if (!accessed) return null;
|
|
2876
|
+
field = key;
|
|
2877
|
+
param = accessed;
|
|
2878
|
+
} else if (value?.type === "CallExpression") {
|
|
2879
|
+
const accessed = paramAccess(inlineUpdateArg(value, cryptoName));
|
|
2880
|
+
if (!accessed) return null;
|
|
2881
|
+
field = key;
|
|
2882
|
+
param = accessed;
|
|
2883
|
+
} else if (value?.type === "ObjectExpression" && (value.properties ?? []).length === 1) {
|
|
2884
|
+
const inner = value.properties[0];
|
|
2885
|
+
const name = propName(inner);
|
|
2886
|
+
if (name !== "$gt" && name !== "gt" || !isNow(inner.value)) return null;
|
|
2887
|
+
expiry = key;
|
|
2888
|
+
} else return null;
|
|
2889
|
+
}
|
|
2890
|
+
if (!field || !param || !expiry) return null;
|
|
2891
|
+
return { field, param, expiry };
|
|
2892
|
+
}
|
|
2893
|
+
function assignedFromRandom(ast, field, hashFns, randomNames, cryptoName) {
|
|
2894
|
+
let found = false;
|
|
2895
|
+
walk(ast, (node) => {
|
|
2896
|
+
if (node.type !== "AssignmentExpression" || node.left?.type !== "MemberExpression") return;
|
|
2897
|
+
if (propName(node.left) !== field && node.left.property?.name !== field) return;
|
|
2898
|
+
const right = unwrap(node.right);
|
|
2899
|
+
if (right?.type !== "CallExpression") return;
|
|
2900
|
+
if (right.callee?.type === "Identifier" && hashFns.has(right.callee.name)) {
|
|
2901
|
+
const arg2 = right.arguments?.[0];
|
|
2902
|
+
if (arg2?.type === "Identifier" && randomNames.has(arg2.name)) found = true;
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
const arg = inlineUpdateArg(right, cryptoName);
|
|
2906
|
+
if (arg?.type === "Identifier" && randomNames.has(arg.name)) found = true;
|
|
2907
|
+
});
|
|
2908
|
+
return found;
|
|
2909
|
+
}
|
|
2910
|
+
function inlineUpdateArg(node, cryptoName) {
|
|
2911
|
+
const digest2 = unwrap(node);
|
|
2912
|
+
if (!cryptoName || digest2?.type !== "CallExpression" || digest2.callee?.type !== "MemberExpression" || digest2.callee.property?.name !== "digest") return null;
|
|
2913
|
+
const update = digest2.callee.object;
|
|
2914
|
+
if (update?.type !== "CallExpression" || update.callee?.type !== "MemberExpression" || update.callee.property?.name !== "update") return null;
|
|
2915
|
+
if ((update.arguments ?? []).length !== 1) return null;
|
|
2916
|
+
const created = update.callee.object;
|
|
2917
|
+
if (created?.type !== "CallExpression" || created.callee?.type !== "MemberExpression") return null;
|
|
2918
|
+
if (created.callee.property?.name !== "createHash" || created.callee.object?.name !== cryptoName) return null;
|
|
2919
|
+
if ((created.arguments ?? []).length !== 1 || created.arguments[0]?.type !== "StringLiteral") return null;
|
|
2920
|
+
return update.arguments[0];
|
|
2921
|
+
}
|
|
2922
|
+
function isPasswordAssign(stmt, user, hashers) {
|
|
2923
|
+
if (stmt?.type !== "ExpressionStatement" || stmt.expression?.type !== "AssignmentExpression") return false;
|
|
2924
|
+
const left = stmt.expression.left;
|
|
2925
|
+
if (left?.type !== "MemberExpression" || left.object?.name !== user) return false;
|
|
2926
|
+
const right = unwrap(stmt.expression.right);
|
|
2927
|
+
if (right?.type !== "CallExpression" || right.callee?.type !== "MemberExpression" || right.callee.property?.name !== "hash") return false;
|
|
2928
|
+
if (right.callee.object?.type !== "Identifier" || !hashers.has(right.callee.object.name)) return false;
|
|
2929
|
+
let cur = right.arguments?.[0];
|
|
2930
|
+
let body = false;
|
|
2931
|
+
while (cur?.type === "MemberExpression") {
|
|
2932
|
+
if (cur.property?.name === "body") body = true;
|
|
2933
|
+
cur = cur.object;
|
|
2934
|
+
}
|
|
2935
|
+
return body && right.arguments?.[1]?.type === "NumericLiteral";
|
|
2936
|
+
}
|
|
2937
|
+
function isClear(stmt, user, field) {
|
|
2938
|
+
if (stmt?.type !== "ExpressionStatement" || stmt.expression?.type !== "AssignmentExpression") return false;
|
|
2939
|
+
const left = stmt.expression.left;
|
|
2940
|
+
if (left?.type !== "MemberExpression" || left.object?.name !== user || left.property?.name !== field) return false;
|
|
2941
|
+
const right = unwrap(stmt.expression.right);
|
|
2942
|
+
return right?.type === "Identifier" && right.name === "undefined" || right?.type === "NullLiteral";
|
|
2943
|
+
}
|
|
2944
|
+
function isSave(stmt, user) {
|
|
2945
|
+
if (stmt?.type !== "ExpressionStatement") return false;
|
|
2946
|
+
const call = unwrap(stmt.expression);
|
|
2947
|
+
return call?.type === "CallExpression" && call.callee?.type === "MemberExpression" && call.callee.property?.name === "save" && call.callee.object?.name === user && (call.arguments ?? []).length === 0;
|
|
2948
|
+
}
|
|
2949
|
+
function isSuccess(stmt, _user, _param) {
|
|
2950
|
+
const value = stmt?.type === "ReturnStatement" ? stmt.argument : stmt?.type === "ExpressionStatement" ? stmt.expression : null;
|
|
2951
|
+
const call = unwrap(value);
|
|
2952
|
+
if (call?.type !== "CallExpression") return false;
|
|
2953
|
+
const callee = call.callee;
|
|
2954
|
+
const name = callee?.property?.name;
|
|
2955
|
+
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");
|
|
2956
|
+
if (!ok || (call.arguments ?? []).length < 1) return false;
|
|
2957
|
+
return literalValue(call.arguments[0]);
|
|
2958
|
+
}
|
|
2959
|
+
function capabilityBody(model, handler) {
|
|
2960
|
+
if (handler.method !== "post" && handler.method !== "put" && handler.method !== "patch") return false;
|
|
2961
|
+
const stmts = handler.statements.filter((stmt) => stmt?.type !== "EmptyStatement");
|
|
2962
|
+
if (stmts.length < 2 || stmts[0]?.type !== "VariableDeclaration" || (stmts[0].declarations ?? []).length !== 1) return false;
|
|
2963
|
+
const decl = stmts[0].declarations[0];
|
|
2964
|
+
if (decl?.id?.type !== "Identifier") return false;
|
|
2965
|
+
const lookup = unwrap(decl.init);
|
|
2966
|
+
if (lookup?.type !== "CallExpression" || lookup.callee?.type !== "MemberExpression") return false;
|
|
2967
|
+
if (!["findOne", "findUnique", "findFirst"].includes(lookup.callee.property?.name)) return false;
|
|
2968
|
+
const filter = filterOf(lookup.arguments?.[0], model.hashFns, model.cryptoName);
|
|
2969
|
+
if (!filter) return false;
|
|
2970
|
+
if (!handler.appRouter && !handler.path.includes(`:${filter.param}`)) return false;
|
|
2971
|
+
if (!assignedFromRandom(model.ast, filter.field, model.hashFns, model.randomNames, model.cryptoName)) return false;
|
|
2972
|
+
const guard = stmts[1];
|
|
2973
|
+
if (guard?.type !== "IfStatement" || guard.alternate) return false;
|
|
2974
|
+
const test = unwrap(guard.test);
|
|
2975
|
+
if (test?.type !== "UnaryExpression" || test.operator !== "!" || test.argument?.type !== "Identifier" || test.argument.name !== decl.id.name) return false;
|
|
2976
|
+
if (!rejectConsequent(guard.consequent)) return false;
|
|
2977
|
+
let clearF = false;
|
|
2978
|
+
let clearE = false;
|
|
2979
|
+
let password = false;
|
|
2980
|
+
let saved = false;
|
|
2981
|
+
let done = false;
|
|
2982
|
+
for (const stmt of stmts.slice(2)) {
|
|
2983
|
+
if (done) return false;
|
|
2984
|
+
if (isPasswordAssign(stmt, decl.id.name, model.hasherNames)) {
|
|
2985
|
+
if (password || saved) return false;
|
|
2986
|
+
password = true;
|
|
2987
|
+
continue;
|
|
2988
|
+
}
|
|
2989
|
+
if (isClear(stmt, decl.id.name, filter.field)) {
|
|
2990
|
+
if (saved) return false;
|
|
2991
|
+
clearF = true;
|
|
2992
|
+
continue;
|
|
2993
|
+
}
|
|
2994
|
+
if (isClear(stmt, decl.id.name, filter.expiry)) {
|
|
2995
|
+
if (saved) return false;
|
|
2996
|
+
clearE = true;
|
|
2997
|
+
continue;
|
|
2998
|
+
}
|
|
2999
|
+
if (isSave(stmt, decl.id.name)) {
|
|
3000
|
+
if (!clearF || !clearE || !password || saved) return false;
|
|
3001
|
+
saved = true;
|
|
3002
|
+
continue;
|
|
3003
|
+
}
|
|
3004
|
+
if (isSuccess(stmt, decl.id.name, filter.param)) {
|
|
3005
|
+
if (!saved) return false;
|
|
3006
|
+
done = true;
|
|
3007
|
+
continue;
|
|
3008
|
+
}
|
|
3009
|
+
return false;
|
|
3010
|
+
}
|
|
3011
|
+
return done && clearF && clearE && password && saved;
|
|
3012
|
+
}
|
|
3013
|
+
function capabilityTokenHandler(content, filePath, index) {
|
|
3014
|
+
try {
|
|
3015
|
+
fault("capability");
|
|
3016
|
+
const model = load(content, filePath);
|
|
3017
|
+
if (!model) return false;
|
|
3018
|
+
const handler = onLine(model, content, index);
|
|
3019
|
+
return handler ? capabilityBody(model, handler) : false;
|
|
3020
|
+
} catch {
|
|
3021
|
+
return false;
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
function bearerExpr(node) {
|
|
3025
|
+
const value = unwrap(node);
|
|
3026
|
+
if (value?.type !== "TemplateLiteral" || (value.expressions ?? []).length !== 1) return null;
|
|
3027
|
+
const lead = value.quasis?.[0]?.value?.cooked ?? "";
|
|
3028
|
+
const tail = value.quasis?.[1]?.value?.cooked ?? "";
|
|
3029
|
+
if (!/^Bearer $/i.test(lead) || tail !== "") return null;
|
|
3030
|
+
return value.expressions[0];
|
|
3031
|
+
}
|
|
3032
|
+
function bindPattern(id, init, map) {
|
|
3033
|
+
if (!id) return;
|
|
3034
|
+
if (id.type === "Identifier") map.set(id.name, init);
|
|
3035
|
+
if (id.type === "ObjectPattern") {
|
|
3036
|
+
for (const prop of id.properties ?? []) {
|
|
3037
|
+
if (prop?.type === "ObjectProperty") bindPattern(prop.value, { type: "Destructure", object: init, key: propName(prop) }, map);
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
function declaredNames(id, into) {
|
|
3042
|
+
if (!id) return;
|
|
3043
|
+
if (id.type === "Identifier") into.push(id.name);
|
|
3044
|
+
if (id.type === "ObjectPattern" || id.type === "ArrayPattern") {
|
|
3045
|
+
const parts = id.properties ?? id.elements ?? [];
|
|
3046
|
+
for (const part of parts) {
|
|
3047
|
+
if (part?.type === "ObjectProperty" || part?.type === "RestElement") declaredNames(part.value ?? part.argument, into);
|
|
3048
|
+
else declaredNames(part, into);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
if (id.type === "AssignmentPattern") declaredNames(id.left, into);
|
|
3052
|
+
}
|
|
3053
|
+
function bindingMap(fn) {
|
|
3054
|
+
const map = /* @__PURE__ */ new Map();
|
|
3055
|
+
const body = fn?.body?.type === "BlockStatement" ? fn.body.body ?? [] : [];
|
|
3056
|
+
for (const stmt of body) {
|
|
3057
|
+
if (stmt?.type !== "VariableDeclaration" || stmt.kind !== "const") continue;
|
|
3058
|
+
for (const decl of stmt.declarations ?? []) {
|
|
3059
|
+
if (decl?.init) bindPattern(decl.id, unwrap(decl.init), map);
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3063
|
+
const assigned = /* @__PURE__ */ new Set();
|
|
3064
|
+
walk(fn, (node) => {
|
|
3065
|
+
if (node.type === "VariableDeclarator") {
|
|
3066
|
+
const names = [];
|
|
3067
|
+
declaredNames(node.id, names);
|
|
3068
|
+
for (const name of names) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
3069
|
+
}
|
|
3070
|
+
if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") {
|
|
3071
|
+
const names = [];
|
|
3072
|
+
declaredNames(node.left ?? node.argument, names);
|
|
3073
|
+
for (const name of names) assigned.add(name);
|
|
3074
|
+
}
|
|
3075
|
+
});
|
|
3076
|
+
for (const [name, count] of counts) if (count > 1) map.delete(name);
|
|
3077
|
+
for (const name of assigned) map.delete(name);
|
|
3078
|
+
return map;
|
|
3079
|
+
}
|
|
3080
|
+
function isCookieValue(node, map) {
|
|
3081
|
+
const member = unwrap(node);
|
|
3082
|
+
if (!member || member.type !== "MemberExpression" && member.type !== "OptionalMemberExpression" || member.property?.name !== "value") return false;
|
|
3083
|
+
const call = unwrap(member.object);
|
|
3084
|
+
if (call?.type !== "CallExpression" || call.callee?.type !== "MemberExpression" || call.callee.property?.name !== "get") return false;
|
|
3085
|
+
if (call.arguments?.[0]?.type !== "StringLiteral") return false;
|
|
3086
|
+
const obj = unwrap(call.callee.object);
|
|
3087
|
+
if (obj?.type === "CallExpression" && obj.callee?.name === "cookies") return true;
|
|
3088
|
+
if (obj?.type === "Identifier") {
|
|
3089
|
+
const bound = unwrap(map.get(obj.name));
|
|
3090
|
+
if (bound?.type === "CallExpression" && bound.callee?.name === "cookies") return true;
|
|
3091
|
+
}
|
|
3092
|
+
return false;
|
|
3093
|
+
}
|
|
3094
|
+
function isSessionToken(node, map) {
|
|
3095
|
+
const member = unwrap(node);
|
|
3096
|
+
if (!member || member.type !== "MemberExpression" && member.type !== "OptionalMemberExpression" || member.property?.name !== "access_token") return false;
|
|
3097
|
+
if (member.object?.type !== "Identifier") return false;
|
|
3098
|
+
let current = map.get(member.object.name);
|
|
3099
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3100
|
+
while (current && current.type === "Destructure" && !seen.has(current)) {
|
|
3101
|
+
seen.add(current);
|
|
3102
|
+
current = current.object;
|
|
3103
|
+
}
|
|
3104
|
+
const call = unwrap(current);
|
|
3105
|
+
if (call?.type !== "CallExpression" || call.callee?.property?.name !== "getSession" || call.callee?.object?.property?.name !== "auth") return false;
|
|
3106
|
+
const clientName = call.callee.object.object?.name;
|
|
3107
|
+
const client = unwrap(map.get(clientName));
|
|
3108
|
+
return client?.type === "CallExpression" && (client.callee?.name === "createClient" || client.callee?.property?.name === "createClient");
|
|
3109
|
+
}
|
|
3110
|
+
function fetchLiteral(node) {
|
|
3111
|
+
const call = unwrap(node);
|
|
3112
|
+
if (call?.type !== "CallExpression" || call.callee?.name !== "fetch") return null;
|
|
3113
|
+
return staticString(call.arguments?.[0]);
|
|
3114
|
+
}
|
|
3115
|
+
function isOAuthToken(node, map, here) {
|
|
3116
|
+
if (node?.type !== "Identifier") return false;
|
|
3117
|
+
let current = map.get(node.name);
|
|
3118
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3119
|
+
while (current && current.type === "Destructure" && !seen.has(current)) {
|
|
3120
|
+
seen.add(current);
|
|
3121
|
+
current = current.object;
|
|
3122
|
+
}
|
|
3123
|
+
const json = unwrap(current);
|
|
3124
|
+
if (json?.type !== "CallExpression" || json.callee?.property?.name !== "json" || json.callee?.object?.type !== "Identifier") return false;
|
|
3125
|
+
const tokenUrl = fetchLiteral(map.get(json.callee.object.name));
|
|
3126
|
+
if (!tokenUrl || !here) return false;
|
|
3127
|
+
if (!publicHttpsUrl(tokenUrl) || !publicHttpsUrl(here)) return false;
|
|
3128
|
+
const tokenHost = new URL(tokenUrl).hostname.toLowerCase();
|
|
3129
|
+
const hereHost = new URL(here).hostname.toLowerCase();
|
|
3130
|
+
return tokenHost === hereHost || hereHost.endsWith(`.${tokenHost}`);
|
|
3131
|
+
}
|
|
3132
|
+
function envUrl(node) {
|
|
3133
|
+
const value = unwrap(node);
|
|
3134
|
+
if (value?.type !== "TemplateLiteral" || (value.expressions ?? []).length !== 1) return false;
|
|
3135
|
+
if (!isProcessEnv(value.expressions[0]) || value.expressions[0]?.type === "LogicalExpression") return false;
|
|
3136
|
+
const lead = value.quasis?.[0]?.value?.cooked ?? "";
|
|
3137
|
+
const rest = value.quasis?.[1]?.value?.cooked ?? "";
|
|
3138
|
+
return lead === "" && rest.startsWith("/") && !rest.includes("?");
|
|
3139
|
+
}
|
|
3140
|
+
function headerQualifies(model, propPath) {
|
|
3141
|
+
const index = propPath.node.start;
|
|
3142
|
+
const options = propPath.parent;
|
|
3143
|
+
const call = propPath.parentPath?.parentPath?.node;
|
|
3144
|
+
if (options?.type !== "ObjectExpression" || call?.type !== "CallExpression") return false;
|
|
3145
|
+
if (call.arguments?.[1] !== options || call.callee?.name !== "fetch") return false;
|
|
3146
|
+
const headers = propPath.node.value;
|
|
3147
|
+
if (headers?.type !== "ObjectExpression") return false;
|
|
3148
|
+
const auth = (headers.properties ?? []).find((prop) => prop?.type === "ObjectProperty" && propName(prop).toLowerCase() === "authorization");
|
|
3149
|
+
const expr = bearerExpr(auth?.value);
|
|
3150
|
+
if (!expr) return false;
|
|
3151
|
+
const inner = model.functions.filter((fn) => fn.start <= index && index < fn.end).sort((a, b) => a.end - a.start - (b.end - b.start))[0];
|
|
3152
|
+
const handler = model.handlers.find((item) => item.fnStart === inner?.start && item.fnEnd === inner?.end);
|
|
3153
|
+
if (!handler || handler.method !== "serve" && !METHODS.has(handler.method)) return false;
|
|
3154
|
+
const map = bindingMap(handler.fn);
|
|
3155
|
+
const urlNode = call.arguments?.[0];
|
|
3156
|
+
const direct = unwrap(expr);
|
|
3157
|
+
const resolved = direct?.type === "Identifier" ? unwrap(map.get(direct.name)) ?? direct : direct;
|
|
3158
|
+
if (isCookieValue(direct, map) || isCookieValue(resolved, map) || isSessionToken(direct, map) || isSessionToken(resolved, map)) return envUrl(urlNode);
|
|
3159
|
+
const here = staticString(urlNode);
|
|
3160
|
+
return here !== null && isOAuthToken(unwrap(expr), map, here);
|
|
3161
|
+
}
|
|
3162
|
+
function bearerSpans(content, filePath, model) {
|
|
3163
|
+
const key = `${filePath}\0${digest(content)}`;
|
|
3164
|
+
const hit = bearerSpanCache.get(key);
|
|
3165
|
+
if (hit && hit.content === content) return hit.spans;
|
|
3166
|
+
const spans = [];
|
|
3167
|
+
traverse(model.ast, {
|
|
3168
|
+
ObjectProperty(path) {
|
|
3169
|
+
const node = path.node;
|
|
3170
|
+
if (typeof node.start !== "number" || typeof node.end !== "number") return;
|
|
3171
|
+
if (propName(node).toLowerCase() !== "headers") return;
|
|
3172
|
+
spans.push({ start: node.start, end: node.end, ok: headerQualifies(model, path) });
|
|
3173
|
+
}
|
|
3174
|
+
});
|
|
3175
|
+
bearerSpanCache.set(key, { content, spans });
|
|
3176
|
+
if (bearerSpanCache.size > 128) {
|
|
3177
|
+
const first = bearerSpanCache.keys().next().value;
|
|
3178
|
+
if (first !== void 0) bearerSpanCache.delete(first);
|
|
3179
|
+
}
|
|
3180
|
+
return spans;
|
|
3181
|
+
}
|
|
3182
|
+
function bearerProvenanceSafe(content, filePath, index) {
|
|
3183
|
+
try {
|
|
3184
|
+
fault("bearer");
|
|
3185
|
+
if (!content.includes("fetch")) return false;
|
|
3186
|
+
const model = load(content, filePath);
|
|
3187
|
+
if (!model) return false;
|
|
3188
|
+
let count = 0;
|
|
3189
|
+
let ok = false;
|
|
3190
|
+
for (const span of bearerSpans(content, filePath, model)) {
|
|
3191
|
+
if (index < span.start || index >= span.end) continue;
|
|
3192
|
+
count += 1;
|
|
3193
|
+
ok = span.ok;
|
|
3194
|
+
}
|
|
3195
|
+
return count === 1 && ok;
|
|
3196
|
+
} catch {
|
|
3197
|
+
return false;
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
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;
|
|
3201
|
+
var REF_RE = /params\.id|params\.(?:slug|uuid)|req\.params\.\w+|req\.params\b|req\.(?:body|query)\.\w*id/gi;
|
|
3202
|
+
var OWNER_RE = /userId|ownerId|createdBy|user_id|owner_id|AND.*user|where.*user|authorize|canAccess|checkPermission|isOwner|belongsTo/i;
|
|
3203
|
+
var AUTH_RE = /requireUser|requireUserForApi|requireAuth|withAuth|getServerSession|auth\(\)|passport|isAuthenticated/i;
|
|
3204
|
+
function maskLocal(content) {
|
|
3205
|
+
let open = content.indexOf("/*");
|
|
3206
|
+
let blocked2 = content;
|
|
3207
|
+
if (open !== -1) {
|
|
3208
|
+
const parts = [];
|
|
3209
|
+
let copied = 0;
|
|
3210
|
+
while (open !== -1) {
|
|
3211
|
+
const close = content.indexOf("*/", open + 2);
|
|
3212
|
+
if (close === -1) break;
|
|
3213
|
+
parts.push(content.slice(copied, open), content.slice(open, close + 2).replace(/[^\n]/g, " "));
|
|
3214
|
+
copied = close + 2;
|
|
3215
|
+
open = content.indexOf("/*", copied);
|
|
3216
|
+
}
|
|
3217
|
+
parts.push(content.slice(copied));
|
|
3218
|
+
blocked2 = parts.join("");
|
|
3219
|
+
}
|
|
3220
|
+
return blocked2.replace(/(^|[^:])\/\/[^\n]*/gm, (match, lead) => lead + " ".repeat(match.length - lead.length));
|
|
3221
|
+
}
|
|
3222
|
+
function matchIndexes(text, re) {
|
|
3223
|
+
const copy = new RegExp(re.source, re.flags);
|
|
3224
|
+
const out = [];
|
|
3225
|
+
let match;
|
|
3226
|
+
while (match = copy.exec(text)) {
|
|
3227
|
+
out.push(match.index);
|
|
3228
|
+
if (match[0].length === 0) copy.lastIndex += 1;
|
|
3229
|
+
if (out.length > LOOKUP_LIMIT) break;
|
|
3230
|
+
}
|
|
3231
|
+
return out;
|
|
3232
|
+
}
|
|
3233
|
+
function balancedCall(content, open) {
|
|
3234
|
+
let depth = 0;
|
|
3235
|
+
for (let i = open; i < content.length; i++) {
|
|
3236
|
+
const c = content[i];
|
|
3237
|
+
if (c === "(") depth += 1;
|
|
3238
|
+
else if (c === ")") {
|
|
3239
|
+
depth -= 1;
|
|
3240
|
+
if (depth === 0) return content.slice(open, i + 1);
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
return null;
|
|
3244
|
+
}
|
|
3245
|
+
function querySlice(content, index) {
|
|
3246
|
+
if (/^where\b/i.test(content.slice(index, index + 5))) {
|
|
3247
|
+
let depth = 0;
|
|
3248
|
+
for (let i = index; i >= 0; i--) {
|
|
3249
|
+
const c = content[i];
|
|
3250
|
+
if (c === ")") depth += 1;
|
|
3251
|
+
else if (c === "(") {
|
|
3252
|
+
if (depth === 0) return balancedCall(content, i);
|
|
3253
|
+
depth -= 1;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
const open = content.indexOf("(", index);
|
|
3258
|
+
if (open === -1 || open - index > 80) return null;
|
|
3259
|
+
return balancedCall(content, open);
|
|
3260
|
+
}
|
|
3261
|
+
function handlerAt(model, index) {
|
|
3262
|
+
const found = model.handlers.filter((handler) => handler.fnStart <= index && index < handler.fnEnd);
|
|
3263
|
+
found.sort((a, b) => a.fnEnd - a.fnStart - (b.fnEnd - b.fnStart));
|
|
3264
|
+
return found[0] ?? null;
|
|
3265
|
+
}
|
|
3266
|
+
function handlerQualifies(content, filePath, handler, lookups) {
|
|
3267
|
+
const slice = content.slice(handler.fnStart, handler.fnEnd);
|
|
3268
|
+
const registered = content.slice(handler.regStart, handler.fnEnd);
|
|
3269
|
+
if (AUTH_RE.test(registered)) return false;
|
|
3270
|
+
const lookup = lookups.find((index) => index >= handler.fnStart && index < handler.fnEnd);
|
|
3271
|
+
if (lookup === void 0) return false;
|
|
3272
|
+
const query = querySlice(content, lookup) ?? slice;
|
|
3273
|
+
if (OWNER_RE.test(query)) return false;
|
|
3274
|
+
const reads = /req\.params\b|req\.(?:body|query)\.\w*id\b|params\.id|params\.(?:slug|uuid)/i.test(slice);
|
|
3275
|
+
if (!reads) return false;
|
|
3276
|
+
if (handler.appRouter) return /\/api\//i.test(filePath) && /^(get|put|patch|delete)$/.test(handler.method);
|
|
3277
|
+
return METHODS.has(handler.method);
|
|
3278
|
+
}
|
|
3279
|
+
function refineDirectObjectFindings(content, filePath, legacyLines) {
|
|
3280
|
+
try {
|
|
3281
|
+
fault("refine");
|
|
3282
|
+
if (content.length > PARSE_BYTES) return null;
|
|
3283
|
+
const masked = maskLocal(content);
|
|
3284
|
+
const lookups = matchIndexes(masked, LOOKUP_RE);
|
|
3285
|
+
if (lookups.length > LOOKUP_LIMIT) return null;
|
|
3286
|
+
const model = load(content, filePath);
|
|
3287
|
+
if (!model || model.handlers.length === 0) return null;
|
|
3288
|
+
const refs = matchIndexes(masked, REF_RE);
|
|
3289
|
+
if (refs.length === 0) return null;
|
|
3290
|
+
const cleared = (handler) => narrowedGuard(content, model, handler, lookups) || capabilityTokenHandler(content, filePath, handler.regStart);
|
|
3291
|
+
let every = true;
|
|
3292
|
+
for (const ref of refs) {
|
|
3293
|
+
const handler = handlerAt(model, ref);
|
|
3294
|
+
if (!handler || !cleared(handler)) every = false;
|
|
3295
|
+
}
|
|
3296
|
+
const lines = /* @__PURE__ */ new Set();
|
|
3297
|
+
if (!every) for (const line of legacyLines) lines.add(line);
|
|
3298
|
+
for (const handler of model.handlers) {
|
|
3299
|
+
if (cleared(handler) || !handlerQualifies(content, filePath, handler, lookups)) continue;
|
|
3300
|
+
const ref = refs.find((index) => index >= handler.fnStart && index < handler.fnEnd);
|
|
3301
|
+
if (ref === void 0) continue;
|
|
3302
|
+
lines.add(lineAt(content, ref));
|
|
3303
|
+
}
|
|
3304
|
+
return [...lines].sort((a, b) => a - b);
|
|
3305
|
+
} catch {
|
|
3306
|
+
return null;
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
|
|
1942
3310
|
// src/auth-scope.ts
|
|
1943
3311
|
var GUARD_NAMES = ["requireAdmin", "requireMember", "requireRole", "requireUser", "verifyToken", "verifyAdmin"];
|
|
1944
3312
|
var PUBLIC_LAST = /^(?:login|logout|signup|register|forgot(?:-password)?|reset(?:-password)?|callback)$/i;
|
|
@@ -2413,10 +3781,10 @@ function useCoversRoute(content, index) {
|
|
|
2413
3781
|
if (routeKey === "exhausted") return false;
|
|
2414
3782
|
for (const site of usesInScope(content, routeKey)) {
|
|
2415
3783
|
if (site.receiver !== receiver || site.index >= lineStart) continue;
|
|
2416
|
-
const
|
|
3784
|
+
const stringPrefix2 = /^\s*["'`]([^"'`]*)["'`]/.exec(site.first)?.[1];
|
|
2417
3785
|
const firstIsGuard = /^[A-Za-z_$][\w$]*$/.test(site.first) && GUARD_NAMES.includes(site.first) && guardNameCounts(content, site.first);
|
|
2418
|
-
if (
|
|
2419
|
-
const prefix =
|
|
3786
|
+
if (stringPrefix2 === void 0 && !firstIsGuard) continue;
|
|
3787
|
+
const prefix = stringPrefix2 ?? "";
|
|
2420
3788
|
if (prefix && !authPrefixCovers(prefix, path)) continue;
|
|
2421
3789
|
if (!guardMentioned(content, site.args) && !firstIsGuard) continue;
|
|
2422
3790
|
return true;
|
|
@@ -2617,10 +3985,13 @@ function widenedAuthSuppressesBody(content, filePath, index, handler) {
|
|
|
2617
3985
|
if (cronSecretGates(maskedHandler)) return true;
|
|
2618
3986
|
return false;
|
|
2619
3987
|
}
|
|
2620
|
-
function widenedAuthSuppresses(content, filePath, index, handler) {
|
|
3988
|
+
function widenedAuthSuppresses(content, filePath, index, handler, rawContent, capability = false, strictApp = false) {
|
|
2621
3989
|
try {
|
|
2622
3990
|
if (authFaultForTest) throw new Error("injected");
|
|
2623
|
-
|
|
3991
|
+
if (widenedAuthSuppressesBody(content, filePath, index, handler)) return true;
|
|
3992
|
+
if (!rawContent) return false;
|
|
3993
|
+
if (publicReadOnlyHandler(rawContent, filePath, index, strictApp)) return true;
|
|
3994
|
+
return capability && capabilityTokenHandler(rawContent, filePath, index);
|
|
2624
3995
|
} catch {
|
|
2625
3996
|
return false;
|
|
2626
3997
|
}
|
|
@@ -2661,29 +4032,345 @@ function wordIn(tokens, word) {
|
|
|
2661
4032
|
function hasPf(text) {
|
|
2662
4033
|
return nameTokens(text).some(isPf);
|
|
2663
4034
|
}
|
|
4035
|
+
var TOKEN_PARTS = /* @__PURE__ */ new Set(["token", "code", "otp", "nonce"]);
|
|
4036
|
+
var METHOD_NAMES = /* @__PURE__ */ new Set(["encode", "hexdigest", "toString"]);
|
|
4037
|
+
var RUN_TOGETHER = /^(?:reset|forgot|recover|change)?(?:password|passwd|passphrase|pwd)(?:reset|forgot|recover|change)?(?:token|code|otp|nonce)$/;
|
|
4038
|
+
function languageOf(filePath) {
|
|
4039
|
+
if (filePath.endsWith(".py")) return "py";
|
|
4040
|
+
if (filePath.endsWith(".rb")) return "rb";
|
|
4041
|
+
return "js";
|
|
4042
|
+
}
|
|
4043
|
+
function namesIn(text) {
|
|
4044
|
+
const names = [];
|
|
4045
|
+
const re = /[A-Za-z_$][\w$]*/g;
|
|
4046
|
+
let match;
|
|
4047
|
+
while (match = re.exec(text)) {
|
|
4048
|
+
if (!METHOD_NAMES.has(match[0])) names.push(match[0]);
|
|
4049
|
+
}
|
|
4050
|
+
return names;
|
|
4051
|
+
}
|
|
4052
|
+
function nameHasPassword(name) {
|
|
4053
|
+
return nameTokens(name).some(isPf);
|
|
4054
|
+
}
|
|
4055
|
+
function nameHasToken(name) {
|
|
4056
|
+
const parts = nameTokens(name);
|
|
4057
|
+
if (parts.some((part) => TOKEN_PARTS.has(part))) return true;
|
|
4058
|
+
return name === name.toLowerCase() && RUN_TOGETHER.test(name);
|
|
4059
|
+
}
|
|
4060
|
+
function argumentHasPasswordOnly(expr) {
|
|
4061
|
+
return namesIn(expr).some((name) => nameHasPassword(name) && !nameHasToken(name));
|
|
4062
|
+
}
|
|
4063
|
+
function argumentGivesTokenCredit(expr) {
|
|
4064
|
+
const names = namesIn(expr);
|
|
4065
|
+
if (names.some((name) => nameHasPassword(name) && !nameHasToken(name))) return false;
|
|
4066
|
+
return names.some((name) => nameHasToken(name));
|
|
4067
|
+
}
|
|
2664
4068
|
function isTokenValue(expr) {
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
return
|
|
4069
|
+
return argumentGivesTokenCredit(expr);
|
|
4070
|
+
}
|
|
4071
|
+
function containsPasswordWord(text) {
|
|
4072
|
+
const lower = text.toLowerCase().replace(/passwordless/g, "");
|
|
4073
|
+
return PF_RE.test(lower);
|
|
4074
|
+
}
|
|
4075
|
+
function isBracketKey(raw, start, end) {
|
|
4076
|
+
let j = start - 1;
|
|
4077
|
+
while (j >= 0 && /\s/.test(raw[j])) j--;
|
|
4078
|
+
if (j < 0 || raw[j] !== "[") return false;
|
|
4079
|
+
const prev = raw[j - 1] ?? "";
|
|
4080
|
+
const prev2 = raw[j - 2] ?? "";
|
|
4081
|
+
const member = /[A-Za-z0-9_$)\]]/.test(prev) || prev === "." && prev2 === "?";
|
|
4082
|
+
if (!member) return false;
|
|
4083
|
+
let a = end + 1;
|
|
4084
|
+
while (a < raw.length && /\s/.test(raw[a])) a++;
|
|
4085
|
+
return raw[a] === "]";
|
|
4086
|
+
}
|
|
4087
|
+
function isLookupCallArg(raw, start, end) {
|
|
4088
|
+
if (!/(?:\.(?:get|getItem|getAttribute|param)\s*\(\s*)$/.test(raw.slice(0, start))) return false;
|
|
4089
|
+
let a = end + 1;
|
|
4090
|
+
while (a < raw.length && /\s/.test(raw[a])) a++;
|
|
4091
|
+
return raw[a] === ")";
|
|
4092
|
+
}
|
|
4093
|
+
function applyString(chars, raw, open, close, content, lookup) {
|
|
4094
|
+
const ident = /^[A-Za-z_$][\w$]*$/.test(content);
|
|
4095
|
+
if (lookup && ident) {
|
|
4096
|
+
chars[open] = " ";
|
|
4097
|
+
chars[close] = " ";
|
|
4098
|
+
return;
|
|
4099
|
+
}
|
|
4100
|
+
if (lookup && containsPasswordWord(content)) {
|
|
4101
|
+
const marker = "pwd";
|
|
4102
|
+
for (let k = open; k <= close; k++) if (chars[k] !== "\n") chars[k] = " ";
|
|
4103
|
+
for (let k = 0; k < marker.length && open + 1 + k < close; k++) chars[open + 1 + k] = marker[k];
|
|
4104
|
+
return;
|
|
4105
|
+
}
|
|
4106
|
+
for (let k = open; k <= close; k++) if (chars[k] !== "\n") chars[k] = " ";
|
|
4107
|
+
}
|
|
4108
|
+
function stringPrefix(chars, quoteAt) {
|
|
4109
|
+
for (let len = 2; len >= 1; len--) {
|
|
4110
|
+
if (quoteAt - len < 0) continue;
|
|
4111
|
+
let ok = true;
|
|
4112
|
+
for (let j = 1; j <= len; j++) {
|
|
4113
|
+
if (!/[rRbBuUfF]/.test(chars[quoteAt - j] ?? "")) ok = false;
|
|
4114
|
+
}
|
|
4115
|
+
const before = chars[quoteAt - len - 1] ?? "";
|
|
4116
|
+
if (before && /[A-Za-z0-9_]/.test(before)) ok = false;
|
|
4117
|
+
if (ok) return len;
|
|
4118
|
+
}
|
|
4119
|
+
return 0;
|
|
4120
|
+
}
|
|
4121
|
+
function maskArgument(raw, lang) {
|
|
4122
|
+
const chars = raw.split("");
|
|
4123
|
+
const n = chars.length;
|
|
4124
|
+
let i = 0;
|
|
4125
|
+
const blank = (from, to) => {
|
|
4126
|
+
for (let k = from; k < to && k < n; k++) if (chars[k] !== "\n") chars[k] = " ";
|
|
4127
|
+
};
|
|
4128
|
+
while (i < n) {
|
|
4129
|
+
if (lang === "js" && chars[i] === "/" && chars[i + 1] === "/") {
|
|
4130
|
+
const start = i;
|
|
4131
|
+
while (i < n && chars[i] !== "\n") i++;
|
|
4132
|
+
blank(start, i);
|
|
4133
|
+
continue;
|
|
4134
|
+
}
|
|
4135
|
+
if (lang === "js" && chars[i] === "/" && chars[i + 1] === "*") {
|
|
4136
|
+
const start = i;
|
|
4137
|
+
i += 2;
|
|
4138
|
+
while (i < n && !(chars[i] === "*" && chars[i + 1] === "/")) i++;
|
|
4139
|
+
if (i < n) i += 2;
|
|
4140
|
+
blank(start, i);
|
|
4141
|
+
continue;
|
|
4142
|
+
}
|
|
4143
|
+
if ((lang === "py" || lang === "rb") && chars[i] === "#") {
|
|
4144
|
+
const start = i;
|
|
4145
|
+
while (i < n && chars[i] !== "\n") i++;
|
|
4146
|
+
blank(start, i);
|
|
4147
|
+
continue;
|
|
4148
|
+
}
|
|
4149
|
+
const quote = chars[i];
|
|
4150
|
+
const prefix = quote === "'" || quote === '"' ? stringPrefix(chars, i) : 0;
|
|
4151
|
+
const fstring = prefix > 0 && /[fF]/.test(chars.slice(i - prefix, i).join(""));
|
|
4152
|
+
if ((quote === "'" || quote === '"') && i + 2 < n && chars[i + 1] === quote && chars[i + 2] === quote) {
|
|
4153
|
+
const start = i - prefix;
|
|
4154
|
+
i += 3;
|
|
4155
|
+
const keptTriple = [];
|
|
4156
|
+
while (i + 2 < n && !(chars[i] === quote && chars[i + 1] === quote && chars[i + 2] === quote)) {
|
|
4157
|
+
if (fstring && chars[i] === "{") {
|
|
4158
|
+
const from = i;
|
|
4159
|
+
let depth = 1;
|
|
4160
|
+
i++;
|
|
4161
|
+
while (i < n && depth > 0) {
|
|
4162
|
+
if (chars[i] === "{") depth++;
|
|
4163
|
+
else if (chars[i] === "}") depth--;
|
|
4164
|
+
i++;
|
|
4165
|
+
}
|
|
4166
|
+
keptTriple.push([from, i]);
|
|
4167
|
+
continue;
|
|
4168
|
+
}
|
|
4169
|
+
if (lang === "rb" && quote === '"' && chars[i] === "#" && chars[i + 1] === "{") {
|
|
4170
|
+
i += 2;
|
|
4171
|
+
let depth = 1;
|
|
4172
|
+
while (i < n && depth > 0) {
|
|
4173
|
+
if (chars[i] === "{") depth++;
|
|
4174
|
+
else if (chars[i] === "}") depth--;
|
|
4175
|
+
i++;
|
|
4176
|
+
}
|
|
4177
|
+
continue;
|
|
4178
|
+
}
|
|
4179
|
+
i++;
|
|
4180
|
+
}
|
|
4181
|
+
const end = Math.min(n, i + 3);
|
|
4182
|
+
blank(start, end);
|
|
4183
|
+
for (const [from, to] of keptTriple) {
|
|
4184
|
+
for (let k = from; k < to && k < n; k++) chars[k] = raw[k];
|
|
4185
|
+
}
|
|
4186
|
+
i = end;
|
|
4187
|
+
continue;
|
|
4188
|
+
}
|
|
4189
|
+
if (quote === "'" || quote === '"') {
|
|
4190
|
+
const start = i - prefix;
|
|
4191
|
+
i++;
|
|
4192
|
+
const kept = [];
|
|
4193
|
+
while (i < n) {
|
|
4194
|
+
if (chars[i] === "\\") {
|
|
4195
|
+
i += 2;
|
|
4196
|
+
continue;
|
|
4197
|
+
}
|
|
4198
|
+
if (chars[i] === "\n") break;
|
|
4199
|
+
if (fstring && chars[i] === "{") {
|
|
4200
|
+
const from = i;
|
|
4201
|
+
let depth = 1;
|
|
4202
|
+
i++;
|
|
4203
|
+
while (i < n && depth > 0) {
|
|
4204
|
+
if (chars[i] === "{") depth++;
|
|
4205
|
+
else if (chars[i] === "}") depth--;
|
|
4206
|
+
i++;
|
|
4207
|
+
}
|
|
4208
|
+
kept.push([from, i]);
|
|
4209
|
+
continue;
|
|
4210
|
+
}
|
|
4211
|
+
if (lang === "rb" && quote === '"' && chars[i] === "#" && chars[i + 1] === "{") {
|
|
4212
|
+
const from = i;
|
|
4213
|
+
i += 2;
|
|
4214
|
+
let depth = 1;
|
|
4215
|
+
while (i < n && depth > 0) {
|
|
4216
|
+
if (chars[i] === "{") depth++;
|
|
4217
|
+
else if (chars[i] === "}") depth--;
|
|
4218
|
+
i++;
|
|
4219
|
+
}
|
|
4220
|
+
kept.push([from, i]);
|
|
4221
|
+
continue;
|
|
4222
|
+
}
|
|
4223
|
+
if (chars[i] === quote) break;
|
|
4224
|
+
i++;
|
|
4225
|
+
}
|
|
4226
|
+
const end = i < n && chars[i] === quote ? i : i;
|
|
4227
|
+
if (kept.length === 0 && end < n && chars[end] === quote) {
|
|
4228
|
+
const content = raw.slice(start + prefix + 1, end);
|
|
4229
|
+
const lookup = isBracketKey(raw, start + prefix, end) || isLookupCallArg(raw, start + prefix, end);
|
|
4230
|
+
applyString(chars, raw, start, end, content, lookup);
|
|
4231
|
+
} else {
|
|
4232
|
+
blank(start, end + (end < n && chars[end] === quote ? 1 : 0));
|
|
4233
|
+
for (const [from, to] of kept) {
|
|
4234
|
+
for (let k = from; k < to; k++) chars[k] = raw[k];
|
|
4235
|
+
}
|
|
4236
|
+
}
|
|
4237
|
+
i = end < n && chars[end] === quote ? end + 1 : end;
|
|
4238
|
+
continue;
|
|
4239
|
+
}
|
|
4240
|
+
if (quote === "`") {
|
|
4241
|
+
const start = i;
|
|
4242
|
+
i++;
|
|
4243
|
+
const kept = [];
|
|
4244
|
+
while (i < n) {
|
|
4245
|
+
if (chars[i] === "\\") {
|
|
4246
|
+
i += 2;
|
|
4247
|
+
continue;
|
|
4248
|
+
}
|
|
4249
|
+
if (chars[i] === "`") break;
|
|
4250
|
+
if (chars[i] === "$" && chars[i + 1] === "{") {
|
|
4251
|
+
const from = i;
|
|
4252
|
+
i += 2;
|
|
4253
|
+
let depth = 1;
|
|
4254
|
+
while (i < n && depth > 0) {
|
|
4255
|
+
if (chars[i] === "{") depth++;
|
|
4256
|
+
else if (chars[i] === "}") depth--;
|
|
4257
|
+
i++;
|
|
4258
|
+
}
|
|
4259
|
+
kept.push([from, i]);
|
|
4260
|
+
continue;
|
|
4261
|
+
}
|
|
4262
|
+
i++;
|
|
4263
|
+
}
|
|
4264
|
+
const end = i < n && chars[i] === "`" ? i : i;
|
|
4265
|
+
blank(start, end + (end < n && chars[end] === "`" ? 1 : 0));
|
|
4266
|
+
for (const [from, to] of kept) {
|
|
4267
|
+
for (let k = from; k < to; k++) chars[k] = raw[k];
|
|
4268
|
+
}
|
|
4269
|
+
i = end < n && chars[end] === "`" ? end + 1 : end;
|
|
4270
|
+
continue;
|
|
4271
|
+
}
|
|
4272
|
+
i++;
|
|
4273
|
+
}
|
|
4274
|
+
return chars.join("");
|
|
4275
|
+
}
|
|
4276
|
+
function digestLhsNames(content, digestAt) {
|
|
4277
|
+
const lineStart = content.lastIndexOf("\n", Math.max(0, digestAt - 1)) + 1;
|
|
4278
|
+
const line = content.slice(lineStart, digestAt);
|
|
4279
|
+
const assigned = /([A-Za-z_@][\w.]*)\s*=\s*$/.exec(line);
|
|
4280
|
+
if (!assigned) return [];
|
|
4281
|
+
return assigned[1].split(".").map((part) => part.replace(/^@/, "")).filter(Boolean);
|
|
4282
|
+
}
|
|
4283
|
+
function pushCall(content, open, items, veto, emptySkips) {
|
|
4284
|
+
const close = matchingCloser(content, open, "(", ")", ARG_CAP2);
|
|
4285
|
+
if (close < 0) {
|
|
4286
|
+
items.push({ kind: "fail", text: "", veto });
|
|
4287
|
+
return;
|
|
4288
|
+
}
|
|
4289
|
+
const raw = content.slice(open + 1, close);
|
|
4290
|
+
if (raw.trim() === "") {
|
|
4291
|
+
items.push({ kind: emptySkips ? "skip" : "fail", text: "", veto });
|
|
4292
|
+
return;
|
|
4293
|
+
}
|
|
4294
|
+
items.push({ kind: "arg", text: raw, veto });
|
|
4295
|
+
}
|
|
4296
|
+
function scopeSlice(slice, lang, hitIndent) {
|
|
4297
|
+
if (lang !== "js") {
|
|
4298
|
+
const re = /\n([ \t]*)(?:async[ \t]+)?(?:def|class)[ \t]/g;
|
|
4299
|
+
let m;
|
|
4300
|
+
while (m = re.exec(slice)) {
|
|
4301
|
+
const head = slice.slice(0, m.index);
|
|
4302
|
+
if ((head.split('"""').length - 1) % 2 === 1 || (head.split("'''").length - 1) % 2 === 1) continue;
|
|
4303
|
+
if (m[1].length < hitIndent) return slice.slice(0, m.index);
|
|
4304
|
+
}
|
|
4305
|
+
return slice;
|
|
4306
|
+
}
|
|
4307
|
+
let depth = 0, paren = 0, q = "";
|
|
4308
|
+
for (let i = 0; i < slice.length; i++) {
|
|
4309
|
+
const c = slice[i];
|
|
4310
|
+
if (q) {
|
|
4311
|
+
if (c === "\\") i++;
|
|
4312
|
+
else if (c === q) q = "";
|
|
4313
|
+
continue;
|
|
4314
|
+
}
|
|
4315
|
+
if (c === "'" || c === '"' || c === "`") q = c;
|
|
4316
|
+
else if (c === "(") paren++;
|
|
4317
|
+
else if (c === ")") paren--;
|
|
4318
|
+
else if (paren <= 0 && c === "{") depth++;
|
|
4319
|
+
else if (paren <= 0 && c === "}" && --depth < 0) return slice.slice(0, i);
|
|
4320
|
+
}
|
|
4321
|
+
return slice;
|
|
4322
|
+
}
|
|
4323
|
+
function collectArguments(content, lineStart, filePath) {
|
|
4324
|
+
const scanEnd = Math.min(content.length, lineStart + ARG_CAP2 + 40);
|
|
4325
|
+
const hitIndent = (/^[ \t]*/.exec(content.slice(lineStart)) ?? [""])[0].length;
|
|
4326
|
+
const slice = scopeSlice(content.slice(lineStart, scanEnd), languageOf(filePath), hitIndent);
|
|
4327
|
+
const items = [];
|
|
4328
|
+
const updateRe = /\.update\s*\(/g;
|
|
4329
|
+
let match;
|
|
4330
|
+
while (match = updateRe.exec(slice)) {
|
|
4331
|
+
if (match.index >= ARG_CAP2) break;
|
|
4332
|
+
const open = lineStart + match.index + match[0].lastIndexOf("(");
|
|
4333
|
+
pushCall(content, open, items, [], false);
|
|
4334
|
+
}
|
|
4335
|
+
const ctorRe = /hashlib\s*\.\s*[A-Za-z_]\w*\s*\(|Digest::[A-Za-z0-9_]+\s*\.\s*hexdigest\s*\(/g;
|
|
4336
|
+
while (match = ctorRe.exec(slice)) {
|
|
4337
|
+
if (match.index >= ARG_CAP2) break;
|
|
4338
|
+
const at = lineStart + match.index;
|
|
4339
|
+
const open = at + match[0].lastIndexOf("(");
|
|
4340
|
+
const veto = match[0].includes("Digest") ? digestLhsNames(content, at) : [];
|
|
4341
|
+
pushCall(content, open, items, veto, true);
|
|
4342
|
+
}
|
|
4343
|
+
const lang = languageOf(filePath);
|
|
4344
|
+
return items.map((item) => item.kind === "arg" ? { ...item, text: maskArgument(item.text, lang) } : item);
|
|
4345
|
+
}
|
|
4346
|
+
function gatherTokenDecision(content, lineStart, filePath) {
|
|
4347
|
+
const items = collectArguments(content, lineStart, filePath);
|
|
4348
|
+
const veto = items.flatMap((item) => item.veto);
|
|
4349
|
+
if (veto.some((name) => nameHasPassword(name) && !nameHasToken(name))) return false;
|
|
4350
|
+
const kept = items.filter((item) => item.kind !== "skip");
|
|
4351
|
+
if (kept.length === 0) return false;
|
|
4352
|
+
if (kept.some((item) => item.kind === "fail")) return false;
|
|
4353
|
+
if (kept.some((item) => argumentHasPasswordOnly(item.text))) return false;
|
|
4354
|
+
return kept.every((item) => argumentGivesTokenCredit(item.text));
|
|
2670
4355
|
}
|
|
2671
4356
|
function blocked(text, words) {
|
|
2672
4357
|
const tokens = nameTokens(text);
|
|
2673
4358
|
return words.some((word) => wordIn(tokens, word));
|
|
2674
4359
|
}
|
|
2675
|
-
function namedHasher(name, expr) {
|
|
4360
|
+
function namedHasher(name, expr, tokenIs) {
|
|
2676
4361
|
if (!hasPf(name)) return false;
|
|
2677
|
-
|
|
4362
|
+
const token = tokenIs === void 0 ? isTokenValue(expr) : tokenIs;
|
|
4363
|
+
if (blocked(name, RESET_WORDS) && token) return false;
|
|
2678
4364
|
return true;
|
|
2679
4365
|
}
|
|
2680
4366
|
function hasHashVerb(name) {
|
|
2681
4367
|
const tokens = nameTokens(name);
|
|
2682
4368
|
return HASH_VERBS.some((word) => wordIn(tokens, word));
|
|
2683
4369
|
}
|
|
2684
|
-
function perCallKeeps(name, expr) {
|
|
2685
|
-
|
|
2686
|
-
|
|
4370
|
+
function perCallKeeps(name, expr, tokenIs) {
|
|
4371
|
+
const token = tokenIs === void 0 ? isTokenValue(expr) : tokenIs;
|
|
4372
|
+
if (token) return namedHasher(name, expr, token) && hasHashVerb(name);
|
|
4373
|
+
return hasPf(expr) || namedHasher(name, expr, token);
|
|
2687
4374
|
}
|
|
2688
4375
|
function hashedExprAt(content, index) {
|
|
2689
4376
|
const slice = content.slice(index, index + ARG_CAP2);
|
|
@@ -3162,69 +4849,9 @@ function dotenvValue(raw) {
|
|
|
3162
4849
|
return (hash === -1 ? v : v.slice(0, hash)).trim();
|
|
3163
4850
|
}
|
|
3164
4851
|
|
|
3165
|
-
// src/ast/parse.ts
|
|
3166
|
-
import { parse } from "@babel/parser";
|
|
3167
|
-
var MAX_CACHE = 256;
|
|
3168
|
-
var cache = /* @__PURE__ */ new Map();
|
|
3169
|
-
function cacheKey(filename, contentHash) {
|
|
3170
|
-
return `${filename}:${contentHash}`;
|
|
3171
|
-
}
|
|
3172
|
-
function quickHash(s) {
|
|
3173
|
-
let h = 5381;
|
|
3174
|
-
const step = Math.max(1, Math.floor(s.length / 32));
|
|
3175
|
-
for (let i = 0; i < s.length; i += step) {
|
|
3176
|
-
h = (h << 5) + h + s.charCodeAt(i) | 0;
|
|
3177
|
-
}
|
|
3178
|
-
return h * 31 + s.length | 0;
|
|
3179
|
-
}
|
|
3180
|
-
function pickLanguage(filename) {
|
|
3181
|
-
if (/\.tsx$/i.test(filename)) return "tsx";
|
|
3182
|
-
if (/\.jsx$/i.test(filename)) return "jsx";
|
|
3183
|
-
if (/\.(ts|cts|mts)$/i.test(filename)) return "ts";
|
|
3184
|
-
if (/\.(js|cjs|mjs)$/i.test(filename)) return "js";
|
|
3185
|
-
return null;
|
|
3186
|
-
}
|
|
3187
|
-
function parseFile(content, filename) {
|
|
3188
|
-
const lang = pickLanguage(filename);
|
|
3189
|
-
if (!lang) return null;
|
|
3190
|
-
if (!content || content.length === 0) return null;
|
|
3191
|
-
const key = cacheKey(filename, quickHash(content));
|
|
3192
|
-
if (cache.has(key)) return cache.get(key) ?? null;
|
|
3193
|
-
const plugins = [];
|
|
3194
|
-
if (lang === "ts" || lang === "tsx") plugins.push("typescript");
|
|
3195
|
-
if (lang === "jsx" || lang === "tsx") plugins.push("jsx");
|
|
3196
|
-
plugins.push("decorators-legacy", "classProperties", "dynamicImport", "topLevelAwait");
|
|
3197
|
-
let ast = null;
|
|
3198
|
-
try {
|
|
3199
|
-
ast = parse(content, {
|
|
3200
|
-
sourceType: "unambiguous",
|
|
3201
|
-
allowImportExportEverywhere: true,
|
|
3202
|
-
allowReturnOutsideFunction: true,
|
|
3203
|
-
allowAwaitOutsideFunction: true,
|
|
3204
|
-
allowUndeclaredExports: true,
|
|
3205
|
-
errorRecovery: true,
|
|
3206
|
-
plugins
|
|
3207
|
-
});
|
|
3208
|
-
} catch {
|
|
3209
|
-
cache.set(key, null);
|
|
3210
|
-
if (cache.size > MAX_CACHE) {
|
|
3211
|
-
const firstKey = cache.keys().next().value;
|
|
3212
|
-
if (firstKey !== void 0) cache.delete(firstKey);
|
|
3213
|
-
}
|
|
3214
|
-
return null;
|
|
3215
|
-
}
|
|
3216
|
-
const entry = { ast, language: lang };
|
|
3217
|
-
cache.set(key, entry);
|
|
3218
|
-
if (cache.size > MAX_CACHE) {
|
|
3219
|
-
const firstKey = cache.keys().next().value;
|
|
3220
|
-
if (firstKey !== void 0) cache.delete(firstKey);
|
|
3221
|
-
}
|
|
3222
|
-
return entry;
|
|
3223
|
-
}
|
|
3224
|
-
|
|
3225
4852
|
// src/ast/taint.ts
|
|
3226
|
-
import
|
|
3227
|
-
var
|
|
4853
|
+
import _traverse2 from "@babel/traverse";
|
|
4854
|
+
var traverse2 = typeof _traverse2 === "function" ? _traverse2 : _traverse2.default;
|
|
3228
4855
|
var TAINTED_PROP_SUFFIXES = /* @__PURE__ */ new Set([
|
|
3229
4856
|
"body",
|
|
3230
4857
|
"query",
|
|
@@ -3395,8 +5022,8 @@ function buildTaintMap(parsed) {
|
|
|
3395
5022
|
if (!node) return false;
|
|
3396
5023
|
if (node.type === "MemberExpression") {
|
|
3397
5024
|
const prop = node.property;
|
|
3398
|
-
const
|
|
3399
|
-
if (TAINTED_PROP_SUFFIXES.has(
|
|
5025
|
+
const propName2 = prop.type === "Identifier" ? prop.name : prop.type === "StringLiteral" ? prop.value : "";
|
|
5026
|
+
if (TAINTED_PROP_SUFFIXES.has(propName2)) {
|
|
3400
5027
|
const obj = node.object;
|
|
3401
5028
|
if (obj.type === "Identifier" && TAINTED_REQUEST_OBJECTS.has(obj.name)) {
|
|
3402
5029
|
return true;
|
|
@@ -3489,7 +5116,7 @@ function buildTaintMap(parsed) {
|
|
|
3489
5116
|
const pt = computePassthrough(fn);
|
|
3490
5117
|
if (pt.size > 0) fnPassthrough.set(name, pt);
|
|
3491
5118
|
};
|
|
3492
|
-
|
|
5119
|
+
traverse2(parsed.ast, {
|
|
3493
5120
|
FunctionDeclaration(path) {
|
|
3494
5121
|
const n = path.node;
|
|
3495
5122
|
if (n.type === "FunctionDeclaration" && n.id && n.id.type === "Identifier") {
|
|
@@ -3512,7 +5139,7 @@ function buildTaintMap(parsed) {
|
|
|
3512
5139
|
(a, i) => pt.has(i) && a.type !== "SpreadElement" && rec(a)
|
|
3513
5140
|
);
|
|
3514
5141
|
}
|
|
3515
|
-
|
|
5142
|
+
traverse2(parsed.ast, {
|
|
3516
5143
|
VariableDeclarator(path) {
|
|
3517
5144
|
const node = path.node;
|
|
3518
5145
|
if (node.type !== "VariableDeclarator") return;
|
|
@@ -3634,10 +5261,10 @@ function buildTaintMap(parsed) {
|
|
|
3634
5261
|
}
|
|
3635
5262
|
|
|
3636
5263
|
// src/ast/traverse.ts
|
|
3637
|
-
import
|
|
3638
|
-
var
|
|
5264
|
+
import _traverse3 from "@babel/traverse";
|
|
5265
|
+
var traverse3 = typeof _traverse3 === "function" ? _traverse3 : _traverse3.default;
|
|
3639
5266
|
function visitBinary(parsed, visit) {
|
|
3640
|
-
|
|
5267
|
+
traverse3(parsed.ast, {
|
|
3641
5268
|
BinaryExpression(path) {
|
|
3642
5269
|
const line = path.node.loc?.start.line ?? 1;
|
|
3643
5270
|
visit(path.node, line);
|
|
@@ -3645,7 +5272,7 @@ function visitBinary(parsed, visit) {
|
|
|
3645
5272
|
});
|
|
3646
5273
|
}
|
|
3647
5274
|
function visitCalls(parsed, matchCallee, visit) {
|
|
3648
|
-
|
|
5275
|
+
traverse3(parsed.ast, {
|
|
3649
5276
|
CallExpression(path) {
|
|
3650
5277
|
const node = path.node;
|
|
3651
5278
|
if (!matchCallee(node.callee)) return;
|
|
@@ -4765,9 +6392,9 @@ function maskOutboundAuthNoise(code) {
|
|
|
4765
6392
|
/\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,
|
|
4766
6393
|
blankKeepLines
|
|
4767
6394
|
);
|
|
4768
|
-
let
|
|
6395
|
+
let bindingMap2 = null;
|
|
4769
6396
|
const bindingSource = out;
|
|
4770
|
-
const bindings = () =>
|
|
6397
|
+
const bindings = () => bindingMap2 ??= collectBindings(bindingSource);
|
|
4771
6398
|
out = out.replace(
|
|
4772
6399
|
/\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,
|
|
4773
6400
|
(call, value, at) => credentialValueReadsCaller(value, at, bindings) ? call : blankKeepLines(call)
|
|
@@ -5160,7 +6787,7 @@ var missingAuthMiddleware = {
|
|
|
5160
6787
|
const unauthenticated = matches.filter((m) => {
|
|
5161
6788
|
const index = indexOfLine(m.line);
|
|
5162
6789
|
if (isPublicRootGet(index) || handlerHasAuth(index)) return false;
|
|
5163
|
-
if (widenedAuthSuppresses(maskedForScope, filePath, index, scopeAt(index))) return false;
|
|
6790
|
+
if (widenedAuthSuppresses(maskedForScope, filePath, index, scopeAt(index), content, true, true)) return false;
|
|
5164
6791
|
const namedExport = NAMED_ROUTE_EXPORT_RE.exec(lineText(index));
|
|
5165
6792
|
if (namedExport && secretGuarded && /^[A-Z]+$/.test(namedExport[1])) return false;
|
|
5166
6793
|
if (useServerPatterns.length > 0 && (!routeLines.has(m.line) || namedExport !== null && !/^[A-Z]+$/.test(namedExport[1]))) {
|
|
@@ -6548,8 +8175,9 @@ var weakHashing = {
|
|
|
6548
8175
|
if (matches.some((existing) => existing.line === m.line)) continue;
|
|
6549
8176
|
const lineStart = indexOfLineNo(m.line);
|
|
6550
8177
|
const expr = hashedExprAt(content, lineStart);
|
|
8178
|
+
const token = gatherTokenDecision(content, lineStart, filePath);
|
|
6551
8179
|
const name = braceEnclosingName(lineStart);
|
|
6552
|
-
if (!perCallKeeps(name, expr)) continue;
|
|
8180
|
+
if (!perCallKeeps(name, expr, token)) continue;
|
|
6553
8181
|
matches.push(m);
|
|
6554
8182
|
}
|
|
6555
8183
|
}
|
|
@@ -10267,7 +11895,7 @@ function isClientTarget(file) {
|
|
|
10267
11895
|
function isServerTarget(file) {
|
|
10268
11896
|
return !file.excluded && file.isServer;
|
|
10269
11897
|
}
|
|
10270
|
-
function
|
|
11898
|
+
function lineAt2(content, index) {
|
|
10271
11899
|
let line = 1;
|
|
10272
11900
|
for (let i = 0; i < index && i < content.length; i++) {
|
|
10273
11901
|
if (content[i] === "\n") line++;
|
|
@@ -10370,7 +11998,7 @@ var silentFailedRead = {
|
|
|
10370
11998
|
if (!allValuesEmpty(payload)) continue;
|
|
10371
11999
|
if (HAS_MARKER.test(payload)) continue;
|
|
10372
12000
|
if (/\bstatus\s*:\s*[45]\d\d/.test(body)) continue;
|
|
10373
|
-
hits.push({ file: file.path, line:
|
|
12001
|
+
hits.push({ file: file.path, line: lineAt2(file.content, index) });
|
|
10374
12002
|
break;
|
|
10375
12003
|
}
|
|
10376
12004
|
}
|
|
@@ -10380,8 +12008,8 @@ var silentFailedRead = {
|
|
|
10380
12008
|
};
|
|
10381
12009
|
|
|
10382
12010
|
// src/quality/rules/silent-failed-write.ts
|
|
10383
|
-
import
|
|
10384
|
-
var
|
|
12011
|
+
import _traverse4 from "@babel/traverse";
|
|
12012
|
+
var traverse4 = typeof _traverse4 === "function" ? _traverse4 : _traverse4.default;
|
|
10385
12013
|
var EXTRA_EXCLUDED_PATHS = [
|
|
10386
12014
|
/(?:^|\/)generated\//i,
|
|
10387
12015
|
/(?:^|\/)__generated__\//i,
|
|
@@ -10515,7 +12143,7 @@ function collectFunctions(file) {
|
|
|
10515
12143
|
const byNode = /* @__PURE__ */ new Map();
|
|
10516
12144
|
if (!parsed) return { reachable: /* @__PURE__ */ new Map() };
|
|
10517
12145
|
const handlerRefNames = /* @__PURE__ */ new Set();
|
|
10518
|
-
|
|
12146
|
+
traverse4(parsed.ast, {
|
|
10519
12147
|
JSXAttribute(path) {
|
|
10520
12148
|
const name = path.node.name;
|
|
10521
12149
|
if (name.type !== "JSXIdentifier" || !HANDLER_ATTRIBUTE.test(name.name)) return;
|
|
@@ -10525,7 +12153,7 @@ function collectFunctions(file) {
|
|
|
10525
12153
|
if (expr.type === "Identifier") handlerRefNames.add(expr.name);
|
|
10526
12154
|
}
|
|
10527
12155
|
});
|
|
10528
|
-
|
|
12156
|
+
traverse4(parsed.ast, {
|
|
10529
12157
|
Function(path) {
|
|
10530
12158
|
const info = {
|
|
10531
12159
|
path,
|
|
@@ -10542,7 +12170,7 @@ function collectFunctions(file) {
|
|
|
10542
12170
|
byNode.set(path.node, info);
|
|
10543
12171
|
}
|
|
10544
12172
|
});
|
|
10545
|
-
|
|
12173
|
+
traverse4(parsed.ast, {
|
|
10546
12174
|
CallExpression(path) {
|
|
10547
12175
|
const name = calleeName(path.node.callee);
|
|
10548
12176
|
if (!name) return;
|
|
@@ -10730,7 +12358,7 @@ var silentFailedWrite = {
|
|
|
10730
12358
|
const reachableByNode = /* @__PURE__ */ new Map();
|
|
10731
12359
|
for (const info of reachable.keys()) reachableByNode.set(info.path.node, info);
|
|
10732
12360
|
const reportedUnits = /* @__PURE__ */ new Set();
|
|
10733
|
-
|
|
12361
|
+
traverse4(parsed.ast, {
|
|
10734
12362
|
CallExpression(path) {
|
|
10735
12363
|
if (!isFetchCallee(path.node.callee)) return;
|
|
10736
12364
|
if (inAmbientContext(path)) return;
|
|
@@ -10778,7 +12406,7 @@ var silentFailedWrite = {
|
|
|
10778
12406
|
reportedUnits.add(unit.start);
|
|
10779
12407
|
hits.push({
|
|
10780
12408
|
file: file.path,
|
|
10781
|
-
line:
|
|
12409
|
+
line: lineAt2(file.content, nodeStart(call)),
|
|
10782
12410
|
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
|
|
10783
12411
|
});
|
|
10784
12412
|
}
|
|
@@ -11306,8 +12934,8 @@ var stateBeforeEffect = {
|
|
|
11306
12934
|
const columnLabel = `${transition.table.replace(/["'`]/g, "")}.${transition.column.replace(/["'`]/g, "")}`;
|
|
11307
12935
|
hits.push({
|
|
11308
12936
|
file: file.path,
|
|
11309
|
-
line:
|
|
11310
|
-
detail: `\`${columnLabel}\` is moved out of \`${normValue(consumed.value)}\` on line ${
|
|
12937
|
+
line: lineAt2(file.content, effect.index),
|
|
12938
|
+
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.`
|
|
11311
12939
|
});
|
|
11312
12940
|
}
|
|
11313
12941
|
}
|
|
@@ -11325,22 +12953,22 @@ var SKIP_KEYS = /* @__PURE__ */ new Set([
|
|
|
11325
12953
|
"trailingComments",
|
|
11326
12954
|
"innerComments"
|
|
11327
12955
|
]);
|
|
11328
|
-
function
|
|
12956
|
+
function walk2(node, visit) {
|
|
11329
12957
|
if (!node || typeof node !== "object") return;
|
|
11330
12958
|
if (Array.isArray(node)) {
|
|
11331
|
-
for (const child of node)
|
|
12959
|
+
for (const child of node) walk2(child, visit);
|
|
11332
12960
|
return;
|
|
11333
12961
|
}
|
|
11334
12962
|
const record = node;
|
|
11335
12963
|
if (typeof record.type === "string") visit(node);
|
|
11336
12964
|
for (const key of Object.keys(record)) {
|
|
11337
12965
|
if (SKIP_KEYS.has(key)) continue;
|
|
11338
|
-
|
|
12966
|
+
walk2(record[key], visit);
|
|
11339
12967
|
}
|
|
11340
12968
|
}
|
|
11341
12969
|
function containsType(root, types) {
|
|
11342
12970
|
let found = false;
|
|
11343
|
-
|
|
12971
|
+
walk2(root, (n) => {
|
|
11344
12972
|
if (types.includes(n.type)) found = true;
|
|
11345
12973
|
});
|
|
11346
12974
|
return found;
|
|
@@ -11454,7 +13082,7 @@ function hasEnvSchemaFor(code, name) {
|
|
|
11454
13082
|
}
|
|
11455
13083
|
function readsRequestHeader(node, facts) {
|
|
11456
13084
|
let found = false;
|
|
11457
|
-
|
|
13085
|
+
walk2(node, (n) => {
|
|
11458
13086
|
if (found) return;
|
|
11459
13087
|
if (n.type === "Identifier" && n.name === "headers") found = true;
|
|
11460
13088
|
if (n.type === "CallExpression" || n.type === "OptionalCallExpression") {
|
|
@@ -11474,7 +13102,7 @@ function collectFacts(file) {
|
|
|
11474
13102
|
};
|
|
11475
13103
|
const ast = file.parsed?.ast;
|
|
11476
13104
|
if (!ast) return facts;
|
|
11477
|
-
|
|
13105
|
+
walk2(ast, (n) => {
|
|
11478
13106
|
if (n.type !== "VariableDeclarator" || !n.init) return;
|
|
11479
13107
|
const init = n.init;
|
|
11480
13108
|
let source = init;
|
|
@@ -11520,13 +13148,13 @@ function collectFacts(file) {
|
|
|
11520
13148
|
}
|
|
11521
13149
|
});
|
|
11522
13150
|
const names = /* @__PURE__ */ new Set([...facts.envAlias.values()]);
|
|
11523
|
-
|
|
13151
|
+
walk2(ast, (n) => {
|
|
11524
13152
|
if (n.type === "MemberExpression" || n.type === "CallExpression") {
|
|
11525
13153
|
const direct = envVarName(n);
|
|
11526
13154
|
if (direct) names.add(direct);
|
|
11527
13155
|
}
|
|
11528
13156
|
});
|
|
11529
|
-
|
|
13157
|
+
walk2(ast, (n) => {
|
|
11530
13158
|
if (n.type === "IfStatement") {
|
|
11531
13159
|
for (const name of names) {
|
|
11532
13160
|
if (facts.guarded.has(name)) continue;
|
|
@@ -11847,7 +13475,7 @@ var mouseOnlyControl = {
|
|
|
11847
13475
|
if (isAsChildTrigger(jsxParent)) return;
|
|
11848
13476
|
const dressed = attributeSource(findAttribute(opening, "className"), file.code) + " " + attributeSource(findAttribute(opening, "class"), file.code) + " " + attributeSource(findAttribute(opening, "style"), file.code);
|
|
11849
13477
|
if (!AFFORDANCE.test(dressed)) return;
|
|
11850
|
-
const line = opening.loc?.start.line ??
|
|
13478
|
+
const line = opening.loc?.start.line ?? lineAt2(file.content, opening.start ?? 0);
|
|
11851
13479
|
hits.push({ file: file.path, line });
|
|
11852
13480
|
});
|
|
11853
13481
|
}
|
|
@@ -12095,7 +13723,7 @@ var undeclaredModal = {
|
|
|
12095
13723
|
if (!hasFocusableDescendant(element)) continue;
|
|
12096
13724
|
if (declaresSemantics(element)) continue;
|
|
12097
13725
|
if (!isOpenGated(element, parents, baseName2)) continue;
|
|
12098
|
-
const line = opening.loc?.start.line ??
|
|
13726
|
+
const line = opening.loc?.start.line ?? lineAt2(file.content, opening.start ?? 0);
|
|
12099
13727
|
hits.push({ file: file.path, line });
|
|
12100
13728
|
break;
|
|
12101
13729
|
}
|
|
@@ -12315,7 +13943,7 @@ var unboundedList = {
|
|
|
12315
13943
|
if (REDUCING_MEMBER.test(afterQuery)) return;
|
|
12316
13944
|
const binding = resultBinding(statement);
|
|
12317
13945
|
if (binding && nextUseReduces(file.code, binding, end)) return;
|
|
12318
|
-
const line = node.loc?.start.line ??
|
|
13946
|
+
const line = node.loc?.start.line ?? lineAt2(file.content, node.start ?? 0);
|
|
12319
13947
|
hits.push({ file: file.path, line });
|
|
12320
13948
|
reported = true;
|
|
12321
13949
|
});
|
|
@@ -12471,7 +14099,7 @@ var unassociatedLabel = {
|
|
|
12471
14099
|
const field = fieldAfter(element.end, openings);
|
|
12472
14100
|
if (!field) continue;
|
|
12473
14101
|
if (fieldIsNamed(field)) continue;
|
|
12474
|
-
const line = opening.loc?.start.line ??
|
|
14102
|
+
const line = opening.loc?.start.line ?? lineAt2(file.content, opening.start ?? 0);
|
|
12475
14103
|
hits.push({ file: file.path, line });
|
|
12476
14104
|
}
|
|
12477
14105
|
}
|
|
@@ -12480,11 +14108,11 @@ var unassociatedLabel = {
|
|
|
12480
14108
|
};
|
|
12481
14109
|
|
|
12482
14110
|
// src/quality/rules/failed-read-empty-state.ts
|
|
12483
|
-
import
|
|
14111
|
+
import _traverse5 from "@babel/traverse";
|
|
12484
14112
|
import { getBindingIdentifiers } from "@babel/types";
|
|
12485
14113
|
|
|
12486
14114
|
// src/quality/rules/scope.ts
|
|
12487
|
-
function
|
|
14115
|
+
function unwrap2(node) {
|
|
12488
14116
|
let cur = node;
|
|
12489
14117
|
while (cur.type === "TSAsExpression" || cur.type === "TSNonNullExpression" || cur.type === "TSTypeAssertion" || cur.type === "TSSatisfiesExpression") {
|
|
12490
14118
|
cur = cur.expression;
|
|
@@ -12530,7 +14158,7 @@ function isEmptyInitial(node) {
|
|
|
12530
14158
|
}
|
|
12531
14159
|
|
|
12532
14160
|
// src/quality/rules/failed-read-empty-state.ts
|
|
12533
|
-
var
|
|
14161
|
+
var traverse5 = typeof _traverse5 === "function" ? _traverse5 : _traverse5.default;
|
|
12534
14162
|
var READ_ERROR_PATH_SIGNALS = ERROR_PATH_SIGNALS.filter(
|
|
12535
14163
|
(re) => re.source !== /\.catch\s*\(/.source
|
|
12536
14164
|
);
|
|
@@ -12551,10 +14179,10 @@ function mentionsJsonParse(node, code) {
|
|
|
12551
14179
|
return /\.json\s*\(/.test(code.slice(nodeStart(node), nodeEnd(node)));
|
|
12552
14180
|
}
|
|
12553
14181
|
function chainParsesBody(node, code) {
|
|
12554
|
-
let cur =
|
|
14182
|
+
let cur = unwrap2(node);
|
|
12555
14183
|
for (; ; ) {
|
|
12556
14184
|
if (cur.type === "CallExpression" || cur.type === "OptionalCallExpression") {
|
|
12557
|
-
const callee =
|
|
14185
|
+
const callee = unwrap2(cur.callee);
|
|
12558
14186
|
if ((callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") && callee.property.type === "Identifier") {
|
|
12559
14187
|
const method = callee.property.name;
|
|
12560
14188
|
if (method === "json") return true;
|
|
@@ -12564,14 +14192,14 @@ function chainParsesBody(node, code) {
|
|
|
12564
14192
|
return true;
|
|
12565
14193
|
}
|
|
12566
14194
|
}
|
|
12567
|
-
cur =
|
|
14195
|
+
cur = unwrap2(callee.object);
|
|
12568
14196
|
continue;
|
|
12569
14197
|
}
|
|
12570
14198
|
cur = callee;
|
|
12571
14199
|
continue;
|
|
12572
14200
|
}
|
|
12573
14201
|
if (cur.type === "MemberExpression" || cur.type === "OptionalMemberExpression") {
|
|
12574
|
-
cur =
|
|
14202
|
+
cur = unwrap2(cur.object);
|
|
12575
14203
|
continue;
|
|
12576
14204
|
}
|
|
12577
14205
|
return false;
|
|
@@ -12585,7 +14213,7 @@ function parsedBodyBindings(unit, code) {
|
|
|
12585
14213
|
const names = /* @__PURE__ */ new Set();
|
|
12586
14214
|
const record = (id, init) => {
|
|
12587
14215
|
if (!id || !init) return;
|
|
12588
|
-
const awaited =
|
|
14216
|
+
const awaited = unwrap2(init);
|
|
12589
14217
|
if (awaited.type !== "AwaitExpression") return;
|
|
12590
14218
|
if (!chainParsesBody(awaited.argument, code)) return;
|
|
12591
14219
|
boundNames(id, names);
|
|
@@ -12621,12 +14249,12 @@ function parsedBodyBindings(unit, code) {
|
|
|
12621
14249
|
return names;
|
|
12622
14250
|
}
|
|
12623
14251
|
function derivesFromParsedBody(node, bodies, code) {
|
|
12624
|
-
let cur =
|
|
14252
|
+
let cur = unwrap2(node);
|
|
12625
14253
|
while (cur && (cur.type === "MemberExpression" || cur.type === "OptionalMemberExpression")) {
|
|
12626
|
-
cur =
|
|
14254
|
+
cur = unwrap2(cur.object);
|
|
12627
14255
|
}
|
|
12628
14256
|
if (cur.type === "Identifier") return bodies.has(cur.name);
|
|
12629
|
-
if (cur.type === "AwaitExpression") cur =
|
|
14257
|
+
if (cur.type === "AwaitExpression") cur = unwrap2(cur.argument);
|
|
12630
14258
|
return chainParsesBody(cur, code);
|
|
12631
14259
|
}
|
|
12632
14260
|
function emptyFallbackArgument(node) {
|
|
@@ -12681,7 +14309,7 @@ var failedReadEmptyState = {
|
|
|
12681
14309
|
const parsed = file.parsed;
|
|
12682
14310
|
if (!parsed) continue;
|
|
12683
14311
|
const examined = /* @__PURE__ */ new Set();
|
|
12684
|
-
|
|
14312
|
+
traverse5(parsed.ast, {
|
|
12685
14313
|
CallExpression(path) {
|
|
12686
14314
|
if (!isFetchCallee(path.node.callee)) return;
|
|
12687
14315
|
const unit = unitFor(path);
|
|
@@ -12703,7 +14331,7 @@ var failedReadEmptyState = {
|
|
|
12703
14331
|
const fallback = emptyFallbackArgument(arg);
|
|
12704
14332
|
if (!fallback) return;
|
|
12705
14333
|
if (!derivesFromParsedBody(fallback.left, bodies, file.code)) return;
|
|
12706
|
-
hit = { line:
|
|
14334
|
+
hit = { line: lineAt2(file.content, nodeStart(fallback)), setter: name };
|
|
12707
14335
|
}
|
|
12708
14336
|
});
|
|
12709
14337
|
if (!hit) return;
|
|
@@ -12721,8 +14349,8 @@ var failedReadEmptyState = {
|
|
|
12721
14349
|
};
|
|
12722
14350
|
|
|
12723
14351
|
// src/quality/rules/autosave-armed-by-failed-load.ts
|
|
12724
|
-
import
|
|
12725
|
-
var
|
|
14352
|
+
import _traverse6 from "@babel/traverse";
|
|
14353
|
+
var traverse6 = typeof _traverse6 === "function" ? _traverse6 : _traverse6.default;
|
|
12726
14354
|
function writerTouchesEmptyState(writers) {
|
|
12727
14355
|
for (const writer of writers) {
|
|
12728
14356
|
let found = false;
|
|
@@ -12802,7 +14430,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12802
14430
|
if (!parsed) continue;
|
|
12803
14431
|
if (!EMPTY_INITIAL.test(file.code)) continue;
|
|
12804
14432
|
const armedInFinally = /* @__PURE__ */ new Map();
|
|
12805
|
-
|
|
14433
|
+
traverse6(parsed.ast, {
|
|
12806
14434
|
TryStatement(path) {
|
|
12807
14435
|
const finalizer = path.get("finalizer");
|
|
12808
14436
|
if (!finalizer || Array.isArray(finalizer) || !finalizer.node) return;
|
|
@@ -12820,7 +14448,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12820
14448
|
});
|
|
12821
14449
|
if (armedInFinally.size === 0) continue;
|
|
12822
14450
|
const writingFunctions = /* @__PURE__ */ new Map();
|
|
12823
|
-
|
|
14451
|
+
traverse6(parsed.ast, {
|
|
12824
14452
|
Function(path) {
|
|
12825
14453
|
const src = file.code.slice(nodeStart(path.node), nodeEnd(path.node));
|
|
12826
14454
|
if (!PERSISTENT_WRITE.test(src)) return;
|
|
@@ -12841,7 +14469,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12841
14469
|
}
|
|
12842
14470
|
});
|
|
12843
14471
|
const reported = /* @__PURE__ */ new Set();
|
|
12844
|
-
|
|
14472
|
+
traverse6(parsed.ast, {
|
|
12845
14473
|
CallExpression(path) {
|
|
12846
14474
|
if (!isEffectCall2(path.node)) return;
|
|
12847
14475
|
const cb = path.get("arguments.0");
|
|
@@ -12865,7 +14493,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12865
14493
|
reported.add(state);
|
|
12866
14494
|
hits.push({
|
|
12867
14495
|
file: file.path,
|
|
12868
|
-
line:
|
|
14496
|
+
line: lineAt2(file.content, armLine),
|
|
12869
14497
|
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.`
|
|
12870
14498
|
});
|
|
12871
14499
|
}
|
|
@@ -12877,8 +14505,8 @@ var autosaveArmedByFailedLoad = {
|
|
|
12877
14505
|
};
|
|
12878
14506
|
|
|
12879
14507
|
// src/quality/rules/config-skipped-work.ts
|
|
12880
|
-
import
|
|
12881
|
-
var
|
|
14508
|
+
import _traverse7 from "@babel/traverse";
|
|
14509
|
+
var traverse7 = typeof _traverse7 === "function" ? _traverse7 : _traverse7.default;
|
|
12882
14510
|
var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
12883
14511
|
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;
|
|
12884
14512
|
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;
|
|
@@ -12931,7 +14559,7 @@ var configSkippedWork = {
|
|
|
12931
14559
|
if (BOOKKEEPING.test(file.path)) continue;
|
|
12932
14560
|
const parsed = file.parsed;
|
|
12933
14561
|
if (!parsed) continue;
|
|
12934
|
-
|
|
14562
|
+
traverse7(parsed.ast, {
|
|
12935
14563
|
Function(path) {
|
|
12936
14564
|
const node = path.node;
|
|
12937
14565
|
let name = node.id?.name ?? null;
|
|
@@ -12973,7 +14601,7 @@ var configSkippedWork = {
|
|
|
12973
14601
|
if (writeMatch && BOOKKEEPING.test(after.slice(writeMatch.index, writeMatch.index + 120))) continue;
|
|
12974
14602
|
hits.push({
|
|
12975
14603
|
file: file.path,
|
|
12976
|
-
line:
|
|
14604
|
+
line: lineAt2(file.content, guard.start),
|
|
12977
14605
|
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.`
|
|
12978
14606
|
});
|
|
12979
14607
|
break;
|
|
@@ -12996,8 +14624,8 @@ function isConfigAbsenceTest(test, ifPath, code) {
|
|
|
12996
14624
|
}
|
|
12997
14625
|
|
|
12998
14626
|
// src/quality/rules/stale-response-wins.ts
|
|
12999
|
-
import
|
|
13000
|
-
var
|
|
14627
|
+
import _traverse8 from "@babel/traverse";
|
|
14628
|
+
var traverse8 = typeof _traverse8 === "function" ? _traverse8 : _traverse8.default;
|
|
13001
14629
|
var ORDERING_GUARD = /\breturn\s*\(\s*\)\s*=>|\bAbortController\b|\bsignal\b|\bcancell?ed\b|\bignore\b|\bstale\b|\bisMounted\b|\baborted\b/i;
|
|
13002
14630
|
var SETTER2 = /^set[A-Z][A-Za-z0-9_]*$/;
|
|
13003
14631
|
function calleeIdentifier2(node) {
|
|
@@ -13093,7 +14721,7 @@ var staleResponseWins = {
|
|
|
13093
14721
|
if (!isClientTarget(file)) continue;
|
|
13094
14722
|
const parsed = file.parsed;
|
|
13095
14723
|
if (!parsed) continue;
|
|
13096
|
-
|
|
14724
|
+
traverse8(parsed.ast, {
|
|
13097
14725
|
CallExpression(path) {
|
|
13098
14726
|
if (!isEffectCall3(path.node)) return;
|
|
13099
14727
|
const args = path.node.arguments;
|
|
@@ -13139,7 +14767,7 @@ var staleResponseWins = {
|
|
|
13139
14767
|
(d) => derivesFromDep(ident2, /* @__PURE__ */ new Set([d]), cb, file.code)
|
|
13140
14768
|
);
|
|
13141
14769
|
if (!driving.some((d) => userDriven(d, cb))) continue;
|
|
13142
|
-
hit = { line:
|
|
14770
|
+
hit = { line: lineAt2(file.content, nodeStart(inner.node)), ident: ident2 };
|
|
13143
14771
|
return;
|
|
13144
14772
|
}
|
|
13145
14773
|
}
|
|
@@ -13180,8 +14808,8 @@ function userDriven(dep, at) {
|
|
|
13180
14808
|
}
|
|
13181
14809
|
|
|
13182
14810
|
// src/quality/rules/lost-update-counter.ts
|
|
13183
|
-
import
|
|
13184
|
-
var
|
|
14811
|
+
import _traverse9 from "@babel/traverse";
|
|
14812
|
+
var traverse9 = typeof _traverse9 === "function" ? _traverse9 : _traverse9.default;
|
|
13185
14813
|
var COUNTER_COLUMN = /^(?:credits?|balance|stock|quantity|qty|tokens?|seats?|points?|inventory|remaining|available)$/i;
|
|
13186
14814
|
var WRITE_CALL = /\bUPDATE\s+\w|\.\s*update\s*\(|\.\s*set\s*\(|\bprisma\s*\.\s*\w+\s*\.\s*update\b/i;
|
|
13187
14815
|
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;
|
|
@@ -13219,7 +14847,7 @@ var lostUpdateCounter = {
|
|
|
13219
14847
|
const parsed = file.parsed;
|
|
13220
14848
|
if (!parsed) continue;
|
|
13221
14849
|
let firedInFile = false;
|
|
13222
|
-
|
|
14850
|
+
traverse9(parsed.ast, {
|
|
13223
14851
|
BinaryExpression(path) {
|
|
13224
14852
|
if (firedInFile || hits.length >= MAX_PER_SCAN2) return;
|
|
13225
14853
|
const op = path.node.operator;
|
|
@@ -13246,7 +14874,7 @@ var lostUpdateCounter = {
|
|
|
13246
14874
|
firedInFile = true;
|
|
13247
14875
|
hits.push({
|
|
13248
14876
|
file: file.path,
|
|
13249
|
-
line:
|
|
14877
|
+
line: lineAt2(file.content, nodeStart(path.node)),
|
|
13250
14878
|
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.`
|
|
13251
14879
|
});
|
|
13252
14880
|
}
|
|
@@ -13777,6 +15405,7 @@ export {
|
|
|
13777
15405
|
attachInlineSuppressed,
|
|
13778
15406
|
attachScanSuppression,
|
|
13779
15407
|
authPrefixCovers,
|
|
15408
|
+
bearerProvenanceSafe,
|
|
13780
15409
|
billingWebhookUnmatchedProps,
|
|
13781
15410
|
bucketFiles,
|
|
13782
15411
|
buildMarkerIndex,
|
|
@@ -13787,6 +15416,7 @@ export {
|
|
|
13787
15416
|
calculateGrade,
|
|
13788
15417
|
callSpreads,
|
|
13789
15418
|
capWarnings,
|
|
15419
|
+
capabilityTokenHandler,
|
|
13790
15420
|
checkIntent,
|
|
13791
15421
|
clampCount,
|
|
13792
15422
|
classifyExposure,
|
|
@@ -13881,11 +15511,15 @@ export {
|
|
|
13881
15511
|
parseSupabaseConfig,
|
|
13882
15512
|
perCallTimeoutMs,
|
|
13883
15513
|
planCause,
|
|
15514
|
+
publicHttpsUrl,
|
|
15515
|
+
publicReadOnlyHandler,
|
|
13884
15516
|
publicSuppressedRecord,
|
|
13885
15517
|
qualityRules,
|
|
13886
15518
|
readInlineSuppressed,
|
|
13887
15519
|
readScanSuppression,
|
|
15520
|
+
refineDirectObjectFindings,
|
|
13888
15521
|
replaceBlockComments,
|
|
15522
|
+
resetStructuralState,
|
|
13889
15523
|
routeForFile,
|
|
13890
15524
|
routePathFromFile,
|
|
13891
15525
|
runCustomRules,
|
|
@@ -13896,8 +15530,10 @@ export {
|
|
|
13896
15530
|
scanMultiFile,
|
|
13897
15531
|
scanQuality,
|
|
13898
15532
|
scanTokenNullProps,
|
|
15533
|
+
setStructuralFaultForTest,
|
|
13899
15534
|
sqlInjection,
|
|
13900
15535
|
stripeWebhookUnprotected,
|
|
15536
|
+
structuralParseCount,
|
|
13901
15537
|
supabaseFunctionName,
|
|
13902
15538
|
supabaseNoRLS,
|
|
13903
15539
|
suppressionSummary,
|