xploitscan-shared-rules 2.4.31 → 2.4.33
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 +322 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -4
- package/dist/index.d.ts +85 -4
- package/dist/index.js +316 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -94,6 +94,7 @@ __export(index_exports, {
|
|
|
94
94
|
classifyPublicEnvVar: () => classifyPublicEnvVar,
|
|
95
95
|
classifyStatement: () => classifyStatement,
|
|
96
96
|
clientSideAuth: () => clientSideAuth,
|
|
97
|
+
collectRouteClaims: () => collectRouteClaims,
|
|
97
98
|
complianceMap: () => complianceMap,
|
|
98
99
|
consoleLogProduction: () => consoleLogProduction,
|
|
99
100
|
corsWildcard: () => corsWildcard,
|
|
@@ -109,6 +110,7 @@ __export(index_exports, {
|
|
|
109
110
|
emptyCatchBlock: () => emptyCatchBlock,
|
|
110
111
|
enclosingHandler: () => enclosingHandler,
|
|
111
112
|
envNotGitignored: () => envNotGitignored,
|
|
113
|
+
envVarNamesUsed: () => envVarNamesUsed,
|
|
112
114
|
evalUsage: () => evalUsage,
|
|
113
115
|
exposedAuthSecret: () => exposedAuthSecret,
|
|
114
116
|
exposedDebugMode: () => exposedDebugMode,
|
|
@@ -165,6 +167,8 @@ __export(index_exports, {
|
|
|
165
167
|
maskSecretValue: () => maskSecretValue,
|
|
166
168
|
maskStringLiterals: () => maskStringLiterals,
|
|
167
169
|
matchIgnore: () => matchIgnore,
|
|
170
|
+
mergeIntentStatements: () => mergeIntentStatements,
|
|
171
|
+
mergeRouteClaims: () => mergeRouteClaims,
|
|
168
172
|
missingAuthMiddleware: () => missingAuthMiddleware,
|
|
169
173
|
missingCSP: () => missingCSP,
|
|
170
174
|
missingErrorBoundary: () => missingErrorBoundary,
|
|
@@ -193,6 +197,8 @@ __export(index_exports, {
|
|
|
193
197
|
refineDirectObjectFindings: () => refineDirectObjectFindings,
|
|
194
198
|
replaceBlockComments: () => replaceBlockComments,
|
|
195
199
|
resetStructuralState: () => resetStructuralState,
|
|
200
|
+
resolveSecretGuardedRoutes: () => resolveSecretGuardedRoutes,
|
|
201
|
+
routeDelegationFacts: () => routeDelegationFacts,
|
|
196
202
|
routeForFile: () => routeForFile,
|
|
197
203
|
routePathFromFile: () => routePathFromFile,
|
|
198
204
|
runCustomRules: () => runCustomRules,
|
|
@@ -230,7 +236,7 @@ __export(index_exports, {
|
|
|
230
236
|
module.exports = __toCommonJS(index_exports);
|
|
231
237
|
|
|
232
238
|
// src/version.ts
|
|
233
|
-
var SCANNER_VERSION = "2.4.
|
|
239
|
+
var SCANNER_VERSION = "2.4.33";
|
|
234
240
|
|
|
235
241
|
// src/snippet.ts
|
|
236
242
|
var cacheContent = null;
|
|
@@ -1502,6 +1508,121 @@ function calleeIsGuarded(fn, route, files) {
|
|
|
1502
1508
|
const open = defs[0].index + defs[0][0].length - 1;
|
|
1503
1509
|
return opensWithGuard(targets[0].content.slice(open, open + 4e3));
|
|
1504
1510
|
}
|
|
1511
|
+
var DEF_HEAD_RE = /\b(?:function|const|let)\s+([A-Za-z_$][\w$]*)/g;
|
|
1512
|
+
var GENERIC_DEF_RE = new RegExp(
|
|
1513
|
+
`\\bfunction\\s+([A-Za-z_$][\\w$]*)\\s*\\([^()]{0,200}\\)[^{;]{0,80}\\{|\\b(?:const|let)\\s+([A-Za-z_$][\\w$]*)\\s*(?::[^=;\\n]{0,80})?=\\s*(?:async\\s*)?\\([^()]{0,200}\\)[^{;=]{0,80}=>\\s*\\{`,
|
|
1514
|
+
"y"
|
|
1515
|
+
);
|
|
1516
|
+
var ENV_READ = "process.env";
|
|
1517
|
+
var MAX_GUARDED_CANDIDATES = 50;
|
|
1518
|
+
function importSpec(fn, route) {
|
|
1519
|
+
for (const m of route.matchAll(/\bimport\s*\{([^{}]{0,1000})\}\s*from\s*["']([^"'\n]{1,200})["']/g)) {
|
|
1520
|
+
if (m[1].split(",").some((n) => n.trim() === fn)) return m[2];
|
|
1521
|
+
}
|
|
1522
|
+
return null;
|
|
1523
|
+
}
|
|
1524
|
+
function definesGuarded(fn, content) {
|
|
1525
|
+
const F = esc(fn);
|
|
1526
|
+
const defRe = new RegExp(
|
|
1527
|
+
`\\bfunction\\s+${F}\\s*\\([^()]{0,200}\\)[^{;]{0,80}\\{|\\b(?:const|let)\\s+${F}\\s*(?::[^=;\\n]{0,80})?=\\s*(?:async\\s*)?\\([^()]{0,200}\\)[^{;=]{0,80}=>\\s*\\{`,
|
|
1528
|
+
"g"
|
|
1529
|
+
);
|
|
1530
|
+
const defs = [...content.matchAll(defRe)];
|
|
1531
|
+
if (defs.length !== 1) return false;
|
|
1532
|
+
const open = defs[0].index + defs[0][0].length - 1;
|
|
1533
|
+
return opensWithGuard(content.slice(open, open + 4e3));
|
|
1534
|
+
}
|
|
1535
|
+
function envReads(content) {
|
|
1536
|
+
const out = [];
|
|
1537
|
+
for (let i = content.indexOf(ENV_READ); i !== -1; i = content.indexOf(ENV_READ, i + 1)) out.push(i);
|
|
1538
|
+
return out;
|
|
1539
|
+
}
|
|
1540
|
+
function anyIn(sorted, from, to) {
|
|
1541
|
+
let lo = 0;
|
|
1542
|
+
let hi = sorted.length;
|
|
1543
|
+
while (lo < hi) {
|
|
1544
|
+
const mid = lo + hi >>> 1;
|
|
1545
|
+
if (sorted[mid] < from) lo = mid + 1;
|
|
1546
|
+
else hi = mid;
|
|
1547
|
+
}
|
|
1548
|
+
return lo < sorted.length && sorted[lo] < to;
|
|
1549
|
+
}
|
|
1550
|
+
function guardedHelperNames(content) {
|
|
1551
|
+
const reads = envReads(content);
|
|
1552
|
+
if (reads.length === 0) return [];
|
|
1553
|
+
const candidates = [];
|
|
1554
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1555
|
+
DEF_HEAD_RE.lastIndex = 0;
|
|
1556
|
+
for (let m = DEF_HEAD_RE.exec(content); m !== null; m = DEF_HEAD_RE.exec(content)) {
|
|
1557
|
+
if (seen.has(m[1])) continue;
|
|
1558
|
+
GENERIC_DEF_RE.lastIndex = m.index;
|
|
1559
|
+
const def = GENERIC_DEF_RE.exec(content);
|
|
1560
|
+
if (def === null || (def[1] ?? def[2]) !== m[1]) continue;
|
|
1561
|
+
const open = m.index + def[0].length - 1;
|
|
1562
|
+
if (!anyIn(reads, open, open + 4e3)) continue;
|
|
1563
|
+
if (!opensWithGuard(content.slice(open, open + 4e3))) continue;
|
|
1564
|
+
seen.add(m[1]);
|
|
1565
|
+
candidates.push(m[1]);
|
|
1566
|
+
if (candidates.length >= MAX_GUARDED_CANDIDATES) break;
|
|
1567
|
+
}
|
|
1568
|
+
DEF_HEAD_RE.lastIndex = 0;
|
|
1569
|
+
return candidates.filter((name) => definesGuarded(name, content));
|
|
1570
|
+
}
|
|
1571
|
+
function routeDelegationFacts(files) {
|
|
1572
|
+
const routes = [];
|
|
1573
|
+
const helpers = [];
|
|
1574
|
+
for (const f of files) {
|
|
1575
|
+
if (/\.[jt]sx?$/.test(f.path)) {
|
|
1576
|
+
const names = guardedHelperNames(f.content);
|
|
1577
|
+
if (names.length > 0) helpers.push({ path: f.path, names });
|
|
1578
|
+
}
|
|
1579
|
+
if (!ROUTE_FILE_RE.test(f.path) || OTHER_EXPORT_RE.test(f.content)) continue;
|
|
1580
|
+
const exported = firstMatches(f.content, HANDLER_EXPORT_RE, 8);
|
|
1581
|
+
if (exported.length === 0 || exported.length > 7) continue;
|
|
1582
|
+
const callees = /* @__PURE__ */ new Set();
|
|
1583
|
+
let readable = true;
|
|
1584
|
+
for (const e of exported) {
|
|
1585
|
+
DELEGATING_HANDLER_RE.lastIndex = e.index;
|
|
1586
|
+
const h = DELEGATING_HANDLER_RE.exec(f.content);
|
|
1587
|
+
if (h !== null) {
|
|
1588
|
+
callees.add(h[2]);
|
|
1589
|
+
continue;
|
|
1590
|
+
}
|
|
1591
|
+
HANDLER_HEAD_RE.lastIndex = e.index;
|
|
1592
|
+
const head = HANDLER_HEAD_RE.exec(f.content);
|
|
1593
|
+
const open = head === null ? -1 : e.index + head[0].length - 1;
|
|
1594
|
+
if (open === -1 || !opensWithGuard(f.content.slice(open, open + 4e3))) {
|
|
1595
|
+
readable = false;
|
|
1596
|
+
break;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
if (!readable) continue;
|
|
1600
|
+
routes.push({ path: f.path, callees: [...callees].map((fn) => ({ fn, spec: importSpec(fn, f.content) })) });
|
|
1601
|
+
}
|
|
1602
|
+
return { routes, helpers };
|
|
1603
|
+
}
|
|
1604
|
+
function resolveSecretGuardedRoutes(routes, helpers, paths) {
|
|
1605
|
+
const all = [...new Set(paths)];
|
|
1606
|
+
const guardedBy = /* @__PURE__ */ new Map();
|
|
1607
|
+
for (const h of helpers) {
|
|
1608
|
+
const set = guardedBy.get(h.path) ?? /* @__PURE__ */ new Set();
|
|
1609
|
+
for (const name of h.names) set.add(name);
|
|
1610
|
+
guardedBy.set(h.path, set);
|
|
1611
|
+
}
|
|
1612
|
+
const out = /* @__PURE__ */ new Set();
|
|
1613
|
+
for (const route of routes) {
|
|
1614
|
+
const ok = route.callees.every(({ fn, spec }) => {
|
|
1615
|
+
if (spec === null) return false;
|
|
1616
|
+
const tail = spec.replace(/^(?:@|~)\//, "").replace(/^(?:\.\.?\/)+/, "");
|
|
1617
|
+
const tailRe = new RegExp(`(?:^|/)${esc(tail)}(?:\\.[jt]sx?|/index\\.[jt]sx?)$`);
|
|
1618
|
+
const targets = all.filter((p) => tailRe.test(p));
|
|
1619
|
+
if (targets.length !== 1) return false;
|
|
1620
|
+
return guardedBy.get(targets[0])?.has(fn) === true;
|
|
1621
|
+
});
|
|
1622
|
+
if (ok) out.add(route.path);
|
|
1623
|
+
}
|
|
1624
|
+
return out;
|
|
1625
|
+
}
|
|
1505
1626
|
|
|
1506
1627
|
// src/project-context.ts
|
|
1507
1628
|
var TOML_FN_SECTION_RE = /^\s*\[functions\.(?:"([^"]+)"|([A-Za-z0-9._-]+))\]\s*$/;
|
|
@@ -1769,12 +1890,34 @@ function normalize2(p) {
|
|
|
1769
1890
|
return p;
|
|
1770
1891
|
}
|
|
1771
1892
|
function extractRoutes(files) {
|
|
1893
|
+
const claims = collectRouteClaims(files);
|
|
1894
|
+
return assembleRoutes([...claims.manifest?.routes ?? [], ...claims.declared]);
|
|
1895
|
+
}
|
|
1896
|
+
function mergeRouteClaims(parts) {
|
|
1897
|
+
const manifest = parts.find((part) => part.manifest !== null)?.manifest ?? null;
|
|
1898
|
+
return assembleRoutes([...manifest?.routes ?? [], ...parts.flatMap((part) => part.declared)]);
|
|
1899
|
+
}
|
|
1900
|
+
function assembleRoutes(claims) {
|
|
1772
1901
|
const routes = /* @__PURE__ */ new Map();
|
|
1773
1902
|
const frameworks = /* @__PURE__ */ new Set();
|
|
1774
|
-
|
|
1903
|
+
for (const claim of claims) {
|
|
1904
|
+
if (routes.has(claim.path)) continue;
|
|
1905
|
+
routes.set(claim.path, claim);
|
|
1906
|
+
frameworks.add(claim.framework);
|
|
1907
|
+
}
|
|
1908
|
+
return {
|
|
1909
|
+
frameworks: [...frameworks],
|
|
1910
|
+
routes: [...routes.values()].sort((a, b) => a.path.localeCompare(b.path))
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1913
|
+
function collectRouteClaims(files) {
|
|
1914
|
+
const declaredPaths = /* @__PURE__ */ new Set();
|
|
1915
|
+
const declared = [];
|
|
1916
|
+
let manifest = null;
|
|
1917
|
+
const claim = (raw, framework, source, kindOverride) => {
|
|
1775
1918
|
const path = normalize2(raw);
|
|
1776
|
-
if (!path
|
|
1777
|
-
|
|
1919
|
+
if (!path) return null;
|
|
1920
|
+
return {
|
|
1778
1921
|
path,
|
|
1779
1922
|
// The URL prefix is a fallback, not the authority. A Next `route.ts` is a
|
|
1780
1923
|
// handler wherever it lives: /free-trust-page/claim/start/route.ts is an
|
|
@@ -1784,8 +1927,13 @@ function extractRoutes(files) {
|
|
|
1784
1927
|
dynamic: DYNAMIC_RE.test(path),
|
|
1785
1928
|
framework,
|
|
1786
1929
|
source
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1930
|
+
};
|
|
1931
|
+
};
|
|
1932
|
+
const add = (raw, framework, source, kindOverride) => {
|
|
1933
|
+
const route = claim(raw, framework, source, kindOverride);
|
|
1934
|
+
if (!route || declaredPaths.has(route.path)) return;
|
|
1935
|
+
declaredPaths.add(route.path);
|
|
1936
|
+
declared.push(route);
|
|
1789
1937
|
};
|
|
1790
1938
|
const isNext = hasDep(files, "next");
|
|
1791
1939
|
const isExpress = hasDep(files, "express") || hasDep(files, "hono") || hasDep(files, "koa");
|
|
@@ -1793,10 +1941,16 @@ function extractRoutes(files) {
|
|
|
1793
1941
|
if (isTanstack) {
|
|
1794
1942
|
const gen = files.find((f) => f.path.endsWith("routeTree.gen.ts"));
|
|
1795
1943
|
if (gen) {
|
|
1944
|
+
const listed = [];
|
|
1945
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1796
1946
|
for (const m of gen.content.matchAll(/'(\/[A-Za-z0-9_\-/$.]*)'/g)) {
|
|
1797
1947
|
if (m[1].split("/").some((seg) => seg.startsWith("_"))) continue;
|
|
1798
|
-
|
|
1948
|
+
const route = claim(m[1], "tanstack-router", gen.path);
|
|
1949
|
+
if (!route || seen.has(route.path)) continue;
|
|
1950
|
+
seen.add(route.path);
|
|
1951
|
+
listed.push(route);
|
|
1799
1952
|
}
|
|
1953
|
+
manifest = { source: gen.path, routes: listed };
|
|
1800
1954
|
}
|
|
1801
1955
|
}
|
|
1802
1956
|
for (const file of files) {
|
|
@@ -1844,10 +1998,7 @@ function extractRoutes(files) {
|
|
|
1844
1998
|
}
|
|
1845
1999
|
}
|
|
1846
2000
|
}
|
|
1847
|
-
return {
|
|
1848
|
-
frameworks: [...frameworks],
|
|
1849
|
-
routes: [...routes.values()].sort((a, b) => a.path.localeCompare(b.path))
|
|
1850
|
-
};
|
|
2001
|
+
return { manifest, declared };
|
|
1851
2002
|
}
|
|
1852
2003
|
function routeForFile(table, filePath) {
|
|
1853
2004
|
const norm = filePath.replace(/^\.\//, "");
|
|
@@ -2101,10 +2252,24 @@ var CHECKABLE_CLAIMS = [
|
|
|
2101
2252
|
{ id: "verified-webhooks", label: "which webhooks are verified", example: "Stripe webhooks are signature verified." },
|
|
2102
2253
|
{ id: "rate-limited", label: "what is rate limited", example: "The public API is rate limited." }
|
|
2103
2254
|
];
|
|
2104
|
-
function
|
|
2105
|
-
const
|
|
2255
|
+
function mergeIntentStatements(parts) {
|
|
2256
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
2257
|
+
const out = [];
|
|
2258
|
+
for (const part of parts) {
|
|
2259
|
+
const own = /* @__PURE__ */ new Set();
|
|
2260
|
+
for (const statement of part) {
|
|
2261
|
+
if (claimed.has(statement.source)) continue;
|
|
2262
|
+
own.add(statement.source);
|
|
2263
|
+
out.push(statement);
|
|
2264
|
+
}
|
|
2265
|
+
for (const source of own) claimed.add(source);
|
|
2266
|
+
}
|
|
2267
|
+
return out;
|
|
2268
|
+
}
|
|
2269
|
+
function checkIntent(files, findings, inputs = {}) {
|
|
2270
|
+
const statements = inputs.statements ?? harvestIntent(files);
|
|
2106
2271
|
const sources = [...new Set(statements.map((s) => s.source))];
|
|
2107
|
-
const routes = extractRoutes(files).routes;
|
|
2272
|
+
const routes = inputs.routes ?? extractRoutes(files).routes;
|
|
2108
2273
|
const mismatches = [];
|
|
2109
2274
|
const unchallenged = [];
|
|
2110
2275
|
const uncheckable = [];
|
|
@@ -10309,6 +10474,70 @@ function callWasAborted(err) {
|
|
|
10309
10474
|
const name = "name" in err ? String(err.name) : "";
|
|
10310
10475
|
return name === "AbortError" || name === "APIUserAbortError";
|
|
10311
10476
|
}
|
|
10477
|
+
var SAFE_ERROR_IDENT = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
10478
|
+
var SAFE_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,47}$/;
|
|
10479
|
+
function safeIdent(value) {
|
|
10480
|
+
return typeof value === "string" && SAFE_ERROR_IDENT.test(value) ? value : null;
|
|
10481
|
+
}
|
|
10482
|
+
function errorClassChain(err) {
|
|
10483
|
+
const names = [];
|
|
10484
|
+
let proto = Object.getPrototypeOf(err);
|
|
10485
|
+
for (let depth = 0; proto && depth < 8; depth++) {
|
|
10486
|
+
const ctor = proto.constructor;
|
|
10487
|
+
const name = safeIdent(ctor?.name);
|
|
10488
|
+
if (name && name !== "Object") names.push(name);
|
|
10489
|
+
proto = Object.getPrototypeOf(proto);
|
|
10490
|
+
}
|
|
10491
|
+
return names;
|
|
10492
|
+
}
|
|
10493
|
+
function causeLabel(err) {
|
|
10494
|
+
const cause = err.cause;
|
|
10495
|
+
if (!cause || typeof cause !== "object") return null;
|
|
10496
|
+
const chain = errorClassChain(cause);
|
|
10497
|
+
const name = chain[0] ?? safeIdent(cause.name);
|
|
10498
|
+
let code = null;
|
|
10499
|
+
let node = cause;
|
|
10500
|
+
for (let depth = 0; node && typeof node === "object" && depth < 3 && !code; depth++) {
|
|
10501
|
+
const raw = node.code;
|
|
10502
|
+
if (typeof raw === "string" && SAFE_ERROR_CODE.test(raw)) code = raw;
|
|
10503
|
+
node = node.cause;
|
|
10504
|
+
}
|
|
10505
|
+
if (!name && !code) return null;
|
|
10506
|
+
return code ? `${name ?? "unknown"}/${code}` : name;
|
|
10507
|
+
}
|
|
10508
|
+
function classifyModelError(err) {
|
|
10509
|
+
if (!err || typeof err !== "object") {
|
|
10510
|
+
return { name: "unknown", category: "unknown", status: null, cause: null };
|
|
10511
|
+
}
|
|
10512
|
+
const chain = errorClassChain(err);
|
|
10513
|
+
const ownName = safeIdent(err.name);
|
|
10514
|
+
const specific = chain.find((name2) => name2 !== "Error");
|
|
10515
|
+
const name = specific ?? (ownName && ownName !== "Error" ? ownName : chain[0] ?? ownName ?? "unknown");
|
|
10516
|
+
const status = errorHttpStatus(err);
|
|
10517
|
+
const names = new Set(chain);
|
|
10518
|
+
if (ownName) names.add(ownName);
|
|
10519
|
+
let category = "unknown";
|
|
10520
|
+
if (status === 401 || status === 403) category = "auth";
|
|
10521
|
+
else if (status === 400) category = "bad_request";
|
|
10522
|
+
else if (status === 429) category = "rate_limit";
|
|
10523
|
+
else if (status != null && status >= 500) category = "server";
|
|
10524
|
+
else if (status != null && status >= 400) category = "client";
|
|
10525
|
+
else if (names.has("APIConnectionTimeoutError") || names.has("TimeoutError")) category = "timeout";
|
|
10526
|
+
else if (names.has("APIUserAbortError") || names.has("AbortError")) category = "abort";
|
|
10527
|
+
else if (names.has("APIConnectionError")) category = "connection";
|
|
10528
|
+
const cause = causeLabel(err);
|
|
10529
|
+
if (category === "unknown" && cause && cause.includes("/")) category = "connection";
|
|
10530
|
+
return { name, category, status, cause };
|
|
10531
|
+
}
|
|
10532
|
+
function isRetryableModelError(info) {
|
|
10533
|
+
if (info.category === "timeout" || info.category === "abort") return false;
|
|
10534
|
+
if (info.status == null) return true;
|
|
10535
|
+
if (info.status === 408 || info.status === 409 || info.status === 429) return true;
|
|
10536
|
+
return info.status >= 500;
|
|
10537
|
+
}
|
|
10538
|
+
var MODEL_RETRY_DELAY_MS = 300;
|
|
10539
|
+
var HOSTED_RETRY_SURFACES = /* @__PURE__ */ new Set(["api", "web", "app"]);
|
|
10540
|
+
var MAX_MODEL_THROW_LOGS = 3;
|
|
10312
10541
|
var SEVERITY_PRIORITY = {
|
|
10313
10542
|
critical: 0,
|
|
10314
10543
|
high: 1,
|
|
@@ -10600,6 +10829,7 @@ function parseReviewResponse(text) {
|
|
|
10600
10829
|
}
|
|
10601
10830
|
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS, options) {
|
|
10602
10831
|
const surface = options?.surface ?? "cli";
|
|
10832
|
+
const retryTransient = options?.retryTransient === true && HOSTED_RETRY_SURFACES.has(surface);
|
|
10603
10833
|
const emptyMask = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
|
|
10604
10834
|
const early = (status2, reason2, extra) => ({
|
|
10605
10835
|
findings,
|
|
@@ -10675,6 +10905,14 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10675
10905
|
let fenceDropCount = 0;
|
|
10676
10906
|
let timedOutCount = 0;
|
|
10677
10907
|
let missingContentCount = 0;
|
|
10908
|
+
let modelThrowLogs = 0;
|
|
10909
|
+
const logModelThrow = (info, action) => {
|
|
10910
|
+
if (modelThrowLogs >= MAX_MODEL_THROW_LOGS) return;
|
|
10911
|
+
modelThrowLogs += 1;
|
|
10912
|
+
console.error(
|
|
10913
|
+
`[ai-fp-filter] model call threw: class ${info.name}, category ${info.category}, status ${info.status ?? "none"}, cause ${info.cause ?? "none"}, model ${MODEL_TRIAGE}; ${action}`
|
|
10914
|
+
);
|
|
10915
|
+
};
|
|
10678
10916
|
const detectionCaches = /* @__PURE__ */ new Map();
|
|
10679
10917
|
const cacheFor = (file) => {
|
|
10680
10918
|
let cache2 = detectionCaches.get(file);
|
|
@@ -10807,34 +11045,53 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10807
11045
|
);
|
|
10808
11046
|
}
|
|
10809
11047
|
const perCall = perCallTimeoutMs(budgetMs);
|
|
10810
|
-
|
|
10811
|
-
const
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
11048
|
+
let callAborted = false;
|
|
11049
|
+
const send = async (callTimeout) => {
|
|
11050
|
+
const callAbort = new AbortController();
|
|
11051
|
+
const onParentAbort = () => callAbort.abort();
|
|
11052
|
+
if (abortController.signal.aborted) callAbort.abort();
|
|
11053
|
+
else abortController.signal.addEventListener("abort", onParentAbort, { once: true });
|
|
11054
|
+
const callTimer = setTimeout(() => callAbort.abort(), callTimeout);
|
|
11055
|
+
try {
|
|
11056
|
+
return await client.messages.create(
|
|
11057
|
+
{
|
|
11058
|
+
model: MODEL_TRIAGE,
|
|
11059
|
+
max_tokens: 2048,
|
|
11060
|
+
// Haiku 5.5 rejects non-default sampling params with HTTP 400
|
|
11061
|
+
// ("temperature is deprecated for this model"). Omit temperature /
|
|
11062
|
+
// top_p / top_k entirely — do NOT send MODEL_TEMPERATURE (0).
|
|
11063
|
+
// Adaptive thinking is on by default for 5.5; disable it here: this
|
|
11064
|
+
// is binary FP classification, not open-ended analysis, and thinking
|
|
11065
|
+
// burns the shared AI budget (Isobar rescan: every call 400'd on
|
|
11066
|
+
// temperature, then timed_out with aiReviewed:false → grade D).
|
|
11067
|
+
thinking: { type: "disabled" },
|
|
11068
|
+
system: REVIEW_SYSTEM_PROMPT,
|
|
11069
|
+
messages: [{ role: "user", content: prompt }]
|
|
11070
|
+
},
|
|
11071
|
+
{ timeout: callTimeout, signal: callAbort.signal }
|
|
11072
|
+
);
|
|
11073
|
+
} finally {
|
|
11074
|
+
callAborted = callAbort.signal.aborted;
|
|
11075
|
+
clearTimeout(callTimer);
|
|
11076
|
+
abortController.signal.removeEventListener("abort", onParentAbort);
|
|
11077
|
+
}
|
|
11078
|
+
};
|
|
10816
11079
|
let response;
|
|
10817
11080
|
try {
|
|
10818
|
-
response = await
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
},
|
|
10833
|
-
{ timeout: callTimeout, signal: callAbort.signal }
|
|
10834
|
-
);
|
|
10835
|
-
} finally {
|
|
10836
|
-
clearTimeout(callTimer);
|
|
10837
|
-
abortController.signal.removeEventListener("abort", onParentAbort);
|
|
11081
|
+
response = await send(Math.min(perCall, remaining));
|
|
11082
|
+
} catch (err) {
|
|
11083
|
+
const info = classifyModelError(err);
|
|
11084
|
+
const budgetAbort = abortController.signal.aborted;
|
|
11085
|
+
const retry = retryTransient && !callAborted && !budgetAbort && !authFailed && isRetryableModelError(info) && deadlineMs - Date.now() - MODEL_RETRY_DELAY_MS >= perCall;
|
|
11086
|
+
if (!budgetAbort) logModelThrow(info, retry ? "retrying once" : "not retried");
|
|
11087
|
+
if (!retry) throw err;
|
|
11088
|
+
await new Promise((resolve) => setTimeout(resolve, MODEL_RETRY_DELAY_MS));
|
|
11089
|
+
try {
|
|
11090
|
+
response = await send(Math.min(perCall, Math.max(1, deadlineMs - Date.now())));
|
|
11091
|
+
} catch (retryErr) {
|
|
11092
|
+
if (!abortController.signal.aborted) logModelThrow(classifyModelError(retryErr), "retry failed");
|
|
11093
|
+
throw retryErr;
|
|
11094
|
+
}
|
|
10838
11095
|
}
|
|
10839
11096
|
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
10840
11097
|
const results = parseReviewResponse(text);
|
|
@@ -11805,9 +12062,24 @@ function getSnippet5(content, line) {
|
|
|
11805
12062
|
return `${prefix} ${String(lineNum).padStart(5)} | ${l}`;
|
|
11806
12063
|
}).join("\n");
|
|
11807
12064
|
}
|
|
11808
|
-
function
|
|
12065
|
+
function collectEnvNames(files, into) {
|
|
12066
|
+
for (const f of files) {
|
|
12067
|
+
if (/\.(ts|js|tsx|jsx)$/i.test(f.path)) {
|
|
12068
|
+
const matches = f.content.matchAll(/process\.env\.([A-Z_][A-Z0-9_]*)/g);
|
|
12069
|
+
for (const m of matches) {
|
|
12070
|
+
into.add(m[1]);
|
|
12071
|
+
}
|
|
12072
|
+
}
|
|
12073
|
+
}
|
|
12074
|
+
}
|
|
12075
|
+
function envVarNamesUsed(files) {
|
|
12076
|
+
const names = /* @__PURE__ */ new Set();
|
|
12077
|
+
collectEnvNames(files.filter((f) => !isSbomPath(f.path)), names);
|
|
12078
|
+
return [...names];
|
|
12079
|
+
}
|
|
12080
|
+
function scanMultiFile(files, opts = {}) {
|
|
11809
12081
|
files = files.filter((f) => !isSbomPath(f.path));
|
|
11810
|
-
const guarded = secretGuardedRoutes(files);
|
|
12082
|
+
const guarded = opts.guardedRoutes ?? secretGuardedRoutes(files);
|
|
11811
12083
|
const findings = [];
|
|
11812
12084
|
const fileMap = /* @__PURE__ */ new Map();
|
|
11813
12085
|
for (const f of files) {
|
|
@@ -11925,15 +12197,8 @@ function scanMultiFile(files) {
|
|
|
11925
12197
|
}
|
|
11926
12198
|
const envExample = files.find((f) => /\.env\.example$|\.env\.sample$|\.env\.template$/.test(f.path));
|
|
11927
12199
|
if (envExample) {
|
|
11928
|
-
const envVarsUsed =
|
|
11929
|
-
|
|
11930
|
-
if (/\.(ts|js|tsx|jsx)$/i.test(f.path)) {
|
|
11931
|
-
const matches = f.content.matchAll(/process\.env\.([A-Z_][A-Z0-9_]*)/g);
|
|
11932
|
-
for (const m of matches) {
|
|
11933
|
-
envVarsUsed.add(m[1]);
|
|
11934
|
-
}
|
|
11935
|
-
}
|
|
11936
|
-
}
|
|
12200
|
+
const envVarsUsed = new Set(opts.priorEnvNames ?? []);
|
|
12201
|
+
collectEnvNames(files, envVarsUsed);
|
|
11937
12202
|
const envVarsDocumented = /* @__PURE__ */ new Set();
|
|
11938
12203
|
const exampleMatches = envExample.content.matchAll(/^([A-Z_][A-Z0-9_]*)=/gm);
|
|
11939
12204
|
for (const m of exampleMatches) {
|
|
@@ -15737,6 +16002,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
15737
16002
|
classifyPublicEnvVar,
|
|
15738
16003
|
classifyStatement,
|
|
15739
16004
|
clientSideAuth,
|
|
16005
|
+
collectRouteClaims,
|
|
15740
16006
|
complianceMap,
|
|
15741
16007
|
consoleLogProduction,
|
|
15742
16008
|
corsWildcard,
|
|
@@ -15752,6 +16018,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
15752
16018
|
emptyCatchBlock,
|
|
15753
16019
|
enclosingHandler,
|
|
15754
16020
|
envNotGitignored,
|
|
16021
|
+
envVarNamesUsed,
|
|
15755
16022
|
evalUsage,
|
|
15756
16023
|
exposedAuthSecret,
|
|
15757
16024
|
exposedDebugMode,
|
|
@@ -15808,6 +16075,8 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
15808
16075
|
maskSecretValue,
|
|
15809
16076
|
maskStringLiterals,
|
|
15810
16077
|
matchIgnore,
|
|
16078
|
+
mergeIntentStatements,
|
|
16079
|
+
mergeRouteClaims,
|
|
15811
16080
|
missingAuthMiddleware,
|
|
15812
16081
|
missingCSP,
|
|
15813
16082
|
missingErrorBoundary,
|
|
@@ -15836,6 +16105,8 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
15836
16105
|
refineDirectObjectFindings,
|
|
15837
16106
|
replaceBlockComments,
|
|
15838
16107
|
resetStructuralState,
|
|
16108
|
+
resolveSecretGuardedRoutes,
|
|
16109
|
+
routeDelegationFacts,
|
|
15839
16110
|
routeForFile,
|
|
15840
16111
|
routePathFromFile,
|
|
15841
16112
|
runCustomRules,
|