xploitscan-shared-rules 2.4.19 → 2.4.21
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/ai-status-constants.cjs +99 -0
- package/dist/ai-status-constants.cjs.map +1 -0
- package/dist/ai-status-constants.d.cts +12 -0
- package/dist/ai-status-constants.d.ts +12 -0
- package/dist/ai-status-constants.js +69 -0
- package/dist/ai-status-constants.js.map +1 -0
- package/dist/index.cjs +821 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -3
- package/dist/index.d.ts +97 -3
- package/dist/index.js +801 -82
- package/dist/index.js.map +1 -1
- package/package.json +6 -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.21";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -707,6 +707,10 @@ function isUngradedFinding(finding, options = {}) {
|
|
|
707
707
|
if (options.gradeVendored) return false;
|
|
708
708
|
return isVendoredFinding(finding);
|
|
709
709
|
}
|
|
710
|
+
function vc001TestFixtureSeverity(rule, testFile, severity) {
|
|
711
|
+
if (rule === "VC001" && testFile === true) return "low";
|
|
712
|
+
return severity;
|
|
713
|
+
}
|
|
710
714
|
|
|
711
715
|
// src/routes.ts
|
|
712
716
|
var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
|
|
@@ -2066,6 +2070,308 @@ function noteHardcodedSecret(secret) {
|
|
|
2066
2070
|
const sink = hardcodedSecretValueSink[hardcodedSecretValueSink.length - 1];
|
|
2067
2071
|
if (sink && secret) sink.push(secret);
|
|
2068
2072
|
}
|
|
2073
|
+
var LOCKED_PLACEHOLDER_TOKENS = /* @__PURE__ */ new Set([
|
|
2074
|
+
"your_api_key_here",
|
|
2075
|
+
"your-key-here",
|
|
2076
|
+
"your_key",
|
|
2077
|
+
"<your_key>",
|
|
2078
|
+
"changeme"
|
|
2079
|
+
]);
|
|
2080
|
+
function isEntireXBody(value) {
|
|
2081
|
+
if (!value) return false;
|
|
2082
|
+
for (let i = 0; i < value.length; i++) {
|
|
2083
|
+
const code = value.charCodeAt(i);
|
|
2084
|
+
if (code !== 120 && code !== 88) return false;
|
|
2085
|
+
}
|
|
2086
|
+
return true;
|
|
2087
|
+
}
|
|
2088
|
+
function bodyAfterKnownPrefix(token) {
|
|
2089
|
+
const lower = token.toLowerCase();
|
|
2090
|
+
const prefixes = ["sk_live_", "pk_live_", "sk_test_", "pk_test_", "rk_live_", "rk_test_"];
|
|
2091
|
+
for (const prefix of prefixes) {
|
|
2092
|
+
if (lower.startsWith(prefix)) return token.slice(prefix.length);
|
|
2093
|
+
}
|
|
2094
|
+
return null;
|
|
2095
|
+
}
|
|
2096
|
+
function isLockedVc001Placeholder(token) {
|
|
2097
|
+
if (!token) return false;
|
|
2098
|
+
const trimmed = token.trim();
|
|
2099
|
+
if (!trimmed) return false;
|
|
2100
|
+
const lower = trimmed.toLowerCase();
|
|
2101
|
+
if (LOCKED_PLACEHOLDER_TOKENS.has(lower) || isEntireXBody(trimmed)) return true;
|
|
2102
|
+
const body = bodyAfterKnownPrefix(trimmed);
|
|
2103
|
+
if (body === null || body.length === 0) return false;
|
|
2104
|
+
return LOCKED_PLACEHOLDER_TOKENS.has(body.toLowerCase()) || isEntireXBody(body);
|
|
2105
|
+
}
|
|
2106
|
+
function collapseIdenticalRuns(token) {
|
|
2107
|
+
let out = "";
|
|
2108
|
+
let i = 0;
|
|
2109
|
+
while (i < token.length) {
|
|
2110
|
+
let j = i + 1;
|
|
2111
|
+
while (j < token.length && token[j] === token[i]) j += 1;
|
|
2112
|
+
const keep = j - i >= 8 ? 7 : j - i;
|
|
2113
|
+
out += token[i].repeat(keep);
|
|
2114
|
+
i = j;
|
|
2115
|
+
}
|
|
2116
|
+
return out;
|
|
2117
|
+
}
|
|
2118
|
+
function liveDespiteIdenticalRun(text) {
|
|
2119
|
+
if (!text || textHasLiveCredential(text)) return false;
|
|
2120
|
+
const re = /(?:sk_live_|rk_live_)[A-Za-z0-9]{20,}/g;
|
|
2121
|
+
let found;
|
|
2122
|
+
while ((found = re.exec(text)) !== null) {
|
|
2123
|
+
const token = found[0];
|
|
2124
|
+
if (isLockedVc001Placeholder(token)) continue;
|
|
2125
|
+
const collapsed = collapseIdenticalRuns(token);
|
|
2126
|
+
if (collapsed === token) continue;
|
|
2127
|
+
if (!isPlaceholderToken(collapsed)) return true;
|
|
2128
|
+
}
|
|
2129
|
+
return false;
|
|
2130
|
+
}
|
|
2131
|
+
function stripeReportedSeverity(text) {
|
|
2132
|
+
if (/pk_live_[A-Za-z0-9]{20,}/.test(text)) return "low";
|
|
2133
|
+
if (/sk_test_[A-Za-z0-9]{20,}/.test(text)) return "medium";
|
|
2134
|
+
return void 0;
|
|
2135
|
+
}
|
|
2136
|
+
function decodeBase64UrlJson(segment) {
|
|
2137
|
+
try {
|
|
2138
|
+
if (!segment || segment.length > 8192) return null;
|
|
2139
|
+
const pad = segment.length % 4 === 0 ? "" : "=".repeat(4 - segment.length % 4);
|
|
2140
|
+
const b64 = segment.replace(/-/g, "+").replace(/_/g, "/") + pad;
|
|
2141
|
+
const binary = atob(b64);
|
|
2142
|
+
const bytes = new Uint8Array(binary.length);
|
|
2143
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i) & 255;
|
|
2144
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
2145
|
+
} catch {
|
|
2146
|
+
return null;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
function decodeSupabaseJwt(token) {
|
|
2150
|
+
const parts = token.split(".");
|
|
2151
|
+
if (parts.length !== 3) return null;
|
|
2152
|
+
if (parts.some((part) => !/^[A-Za-z0-9_-]{8,}$/.test(part))) return null;
|
|
2153
|
+
const payload = decodeBase64UrlJson(parts[1]);
|
|
2154
|
+
if (!payload || typeof payload !== "object") return null;
|
|
2155
|
+
const rec = payload;
|
|
2156
|
+
return {
|
|
2157
|
+
role: typeof rec.role === "string" ? rec.role : void 0,
|
|
2158
|
+
iss: typeof rec.iss === "string" ? rec.iss : void 0,
|
|
2159
|
+
payloadText: JSON.stringify(payload)
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
var STRING_CONST_VALUE_MAX = 4096;
|
|
2163
|
+
var CREATE_CLIENT_CALL_CAP = 200;
|
|
2164
|
+
function collectStringConsts(content) {
|
|
2165
|
+
const map = /* @__PURE__ */ new Map();
|
|
2166
|
+
const head = /(?:const|let|var)\s+([A-Za-z_$][\w$]{0,64})\s*=\s*(['"`])/g;
|
|
2167
|
+
let match;
|
|
2168
|
+
while ((match = head.exec(content)) !== null) {
|
|
2169
|
+
const name = match[1];
|
|
2170
|
+
const quote = match[2];
|
|
2171
|
+
const valueStart = match.index + match[0].length;
|
|
2172
|
+
const limit = Math.min(content.length, valueStart + STRING_CONST_VALUE_MAX);
|
|
2173
|
+
let end = valueStart;
|
|
2174
|
+
while (end < limit && content[end] !== quote) end += 1;
|
|
2175
|
+
if (end >= limit || content[end] !== quote) continue;
|
|
2176
|
+
if (!map.has(name)) map.set(name, { value: content.slice(valueStart, end), index: valueStart });
|
|
2177
|
+
head.lastIndex = end + 1;
|
|
2178
|
+
}
|
|
2179
|
+
return map;
|
|
2180
|
+
}
|
|
2181
|
+
function stringConstValue(consts, name) {
|
|
2182
|
+
if (!/^[A-Za-z_$][\w$]{0,64}$/.test(name)) return null;
|
|
2183
|
+
const found = consts.get(name);
|
|
2184
|
+
return found ? found.value : null;
|
|
2185
|
+
}
|
|
2186
|
+
function isLoopbackClientUrl(raw) {
|
|
2187
|
+
const match = /^[a-z][a-z0-9+.-]*:\/\/([^/?#\s]+)/i.exec(raw.trim());
|
|
2188
|
+
if (!match) return false;
|
|
2189
|
+
let host = match[1];
|
|
2190
|
+
if (host.startsWith("[")) {
|
|
2191
|
+
const end = host.indexOf("]");
|
|
2192
|
+
if (end < 0) return false;
|
|
2193
|
+
host = host.slice(1, end);
|
|
2194
|
+
} else {
|
|
2195
|
+
host = host.replace(/:\d+$/, "");
|
|
2196
|
+
}
|
|
2197
|
+
host = host.toLowerCase();
|
|
2198
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
2199
|
+
}
|
|
2200
|
+
function quotedValue(text) {
|
|
2201
|
+
const trimmed = text.trim();
|
|
2202
|
+
if (!trimmed) return null;
|
|
2203
|
+
const lead = text.indexOf(trimmed);
|
|
2204
|
+
if (/^(?:process\.env|import\.meta\.env)\.[A-Za-z0-9_]+!?$/.test(trimmed)) return null;
|
|
2205
|
+
const fallback = /(?:process\.env|import\.meta\.env)\.[A-Za-z0-9_]+!?\s*(?:\?\?|\|\|)\s*(['"`])([\s\S]*?)\1/.exec(trimmed);
|
|
2206
|
+
if (fallback?.[2]) {
|
|
2207
|
+
const rel = text.indexOf(fallback[2]);
|
|
2208
|
+
return { token: fallback[2], rel: rel < 0 ? lead : rel };
|
|
2209
|
+
}
|
|
2210
|
+
const literal = /^(['"`])([\s\S]*)\1$/.exec(trimmed);
|
|
2211
|
+
if (literal) {
|
|
2212
|
+
const rel = text.indexOf(literal[2]);
|
|
2213
|
+
return { token: literal[2], rel: rel < 0 ? lead + 1 : rel };
|
|
2214
|
+
}
|
|
2215
|
+
return null;
|
|
2216
|
+
}
|
|
2217
|
+
function splitCallArgs(content, openParen, cap) {
|
|
2218
|
+
const endLimit = Math.min(content.length, openParen + cap);
|
|
2219
|
+
const args = [];
|
|
2220
|
+
let start = openParen + 1;
|
|
2221
|
+
let depth = 1;
|
|
2222
|
+
let quote = null;
|
|
2223
|
+
let i = openParen + 1;
|
|
2224
|
+
while (i < endLimit && depth > 0) {
|
|
2225
|
+
const ch = content[i];
|
|
2226
|
+
if (quote) {
|
|
2227
|
+
if (ch === "\\") {
|
|
2228
|
+
i += 2;
|
|
2229
|
+
continue;
|
|
2230
|
+
}
|
|
2231
|
+
if (ch === quote) quote = null;
|
|
2232
|
+
i++;
|
|
2233
|
+
continue;
|
|
2234
|
+
}
|
|
2235
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
2236
|
+
quote = ch;
|
|
2237
|
+
i++;
|
|
2238
|
+
continue;
|
|
2239
|
+
}
|
|
2240
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
2241
|
+
depth++;
|
|
2242
|
+
i++;
|
|
2243
|
+
continue;
|
|
2244
|
+
}
|
|
2245
|
+
if (ch === ")" || ch === "]" || ch === "}") {
|
|
2246
|
+
depth--;
|
|
2247
|
+
if (depth === 0) {
|
|
2248
|
+
args.push({ text: content.slice(start, i), start });
|
|
2249
|
+
return { args, end: i + 1 };
|
|
2250
|
+
}
|
|
2251
|
+
i++;
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
if (ch === "," && depth === 1) {
|
|
2255
|
+
args.push({ text: content.slice(start, i), start });
|
|
2256
|
+
start = i + 1;
|
|
2257
|
+
if (args.length >= 4) {
|
|
2258
|
+
return { args, end: i + 1 };
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
i++;
|
|
2262
|
+
}
|
|
2263
|
+
return { args, end: i };
|
|
2264
|
+
}
|
|
2265
|
+
function objectKeyToken(arg, consts) {
|
|
2266
|
+
const named = /\b(?:supabaseKey|serviceRoleKey|service_role_key|apiKey|key)\s*:\s*(?:(['"`])([\s\S]*?)\1|([A-Za-z_$][\w$]{0,64}))/.exec(arg.text);
|
|
2267
|
+
if (!named) return null;
|
|
2268
|
+
if (named[2]) {
|
|
2269
|
+
const rel2 = arg.text.indexOf(named[2]);
|
|
2270
|
+
return { token: named[2], index: arg.start + (rel2 < 0 ? 0 : rel2) };
|
|
2271
|
+
}
|
|
2272
|
+
const ident = named[3];
|
|
2273
|
+
if (!ident) return null;
|
|
2274
|
+
const resolved = stringConstValue(consts, ident);
|
|
2275
|
+
if (resolved === null) return null;
|
|
2276
|
+
const rel = arg.text.indexOf(ident);
|
|
2277
|
+
return { token: resolved, index: arg.start + (rel < 0 ? 0 : rel) };
|
|
2278
|
+
}
|
|
2279
|
+
function valueToken(arg, consts) {
|
|
2280
|
+
const quoted = quotedValue(arg.text);
|
|
2281
|
+
if (quoted) return { token: quoted.token, index: arg.start + quoted.rel };
|
|
2282
|
+
const trimmed = arg.text.trim();
|
|
2283
|
+
if (/^[A-Za-z_$][\w$]{0,64}$/.test(trimmed)) {
|
|
2284
|
+
const resolved = stringConstValue(consts, trimmed);
|
|
2285
|
+
if (resolved === null) return null;
|
|
2286
|
+
const rel = arg.text.indexOf(trimmed);
|
|
2287
|
+
return { token: resolved, index: arg.start + (rel < 0 ? 0 : rel) };
|
|
2288
|
+
}
|
|
2289
|
+
if (trimmed.startsWith("{")) return objectKeyToken(arg, consts);
|
|
2290
|
+
return null;
|
|
2291
|
+
}
|
|
2292
|
+
function clientUrl(args) {
|
|
2293
|
+
if (args.length === 0) return "";
|
|
2294
|
+
const first = args[0].text.trim();
|
|
2295
|
+
const literal = /^(['"`])([\s\S]*)\1$/.exec(first);
|
|
2296
|
+
if (literal) return literal[2];
|
|
2297
|
+
if (first.startsWith("{")) {
|
|
2298
|
+
const url = /\b(?:supabaseUrl|url)\s*:\s*(['"`])([\s\S]*?)\1/.exec(first);
|
|
2299
|
+
return url?.[2] ?? "";
|
|
2300
|
+
}
|
|
2301
|
+
return "";
|
|
2302
|
+
}
|
|
2303
|
+
function nextCreateClient(content, from, cursor) {
|
|
2304
|
+
if (cursor.camel >= 0 && cursor.camel < from) {
|
|
2305
|
+
cursor.camel = content.indexOf("createClient", from);
|
|
2306
|
+
}
|
|
2307
|
+
if (cursor.snake >= 0 && cursor.snake < from) {
|
|
2308
|
+
cursor.snake = content.indexOf("create_client", from);
|
|
2309
|
+
}
|
|
2310
|
+
if (cursor.camel < 0) return cursor.snake;
|
|
2311
|
+
if (cursor.snake < 0) return cursor.camel;
|
|
2312
|
+
return cursor.camel < cursor.snake ? cursor.camel : cursor.snake;
|
|
2313
|
+
}
|
|
2314
|
+
function collectSupabaseCreateClientKeys(content, filePath, matches, rule, fix) {
|
|
2315
|
+
if (!content.includes("createClient") && !content.includes("create_client")) return;
|
|
2316
|
+
const consts = content.includes("createClient") ? collectStringConsts(content) : /* @__PURE__ */ new Map();
|
|
2317
|
+
const cap = 2e4;
|
|
2318
|
+
let from = 0;
|
|
2319
|
+
let calls = 0;
|
|
2320
|
+
const cursor = {
|
|
2321
|
+
camel: content.indexOf("createClient"),
|
|
2322
|
+
snake: content.indexOf("create_client")
|
|
2323
|
+
};
|
|
2324
|
+
while (from < content.length) {
|
|
2325
|
+
const at = nextCreateClient(content, from, cursor);
|
|
2326
|
+
if (at < 0) break;
|
|
2327
|
+
const nameLen = content.startsWith("create_client", at) ? "create_client".length : "createClient".length;
|
|
2328
|
+
const before = at === 0 ? "" : content[at - 1];
|
|
2329
|
+
const afterName = at + nameLen;
|
|
2330
|
+
if (before && /[A-Za-z0-9_$]/.test(before) || /[A-Za-z0-9_$]/.test(content[afterName] ?? "")) {
|
|
2331
|
+
from = afterName;
|
|
2332
|
+
continue;
|
|
2333
|
+
}
|
|
2334
|
+
let i = afterName;
|
|
2335
|
+
while (i < content.length && (content[i] === " " || content[i] === " " || content[i] === "\n" || content[i] === "\r")) i++;
|
|
2336
|
+
if (content[i] !== "(") {
|
|
2337
|
+
from = afterName;
|
|
2338
|
+
continue;
|
|
2339
|
+
}
|
|
2340
|
+
calls += 1;
|
|
2341
|
+
if (calls > CREATE_CLIENT_CALL_CAP) break;
|
|
2342
|
+
const parsed = splitCallArgs(content, i, cap);
|
|
2343
|
+
from = parsed?.end ?? Math.min(content.length, i + cap);
|
|
2344
|
+
if (!parsed || parsed.args.length === 0) continue;
|
|
2345
|
+
if (isCommentLine(content, at) || isInsideFixMessage(content, at)) continue;
|
|
2346
|
+
const first = parsed.args[0].text.trim();
|
|
2347
|
+
const keyArg = first.startsWith("{") ? parsed.args[0] : parsed.args[1];
|
|
2348
|
+
if (!keyArg) continue;
|
|
2349
|
+
const extracted = first.startsWith("{") ? objectKeyToken(keyArg, consts) : valueToken(keyArg, consts);
|
|
2350
|
+
if (!extracted || !extracted.token) continue;
|
|
2351
|
+
const token = extracted.token.trim();
|
|
2352
|
+
if (isPlaceholderToken(token) || isLockedVc001Placeholder(token)) continue;
|
|
2353
|
+
const decoded = decodeSupabaseJwt(token);
|
|
2354
|
+
if (!decoded || decoded.role !== "service_role") continue;
|
|
2355
|
+
const url = clientUrl(parsed.args);
|
|
2356
|
+
const downgrade = isTestPath(filePath) && (decoded.iss === "supabase-demo" || isLoopbackClientUrl(url));
|
|
2357
|
+
const line = lineNumberAt(content, extracted.index);
|
|
2358
|
+
const lineStart = content.lastIndexOf("\n", Math.max(0, extracted.index - 1)) + 1;
|
|
2359
|
+
const column = extracted.index - lineStart + 1;
|
|
2360
|
+
matches.push({
|
|
2361
|
+
rule: rule.id,
|
|
2362
|
+
title: rule.title,
|
|
2363
|
+
severity: downgrade ? "low" : "critical",
|
|
2364
|
+
category: rule.category,
|
|
2365
|
+
file: filePath,
|
|
2366
|
+
line,
|
|
2367
|
+
column,
|
|
2368
|
+
snippet: getSnippet(content, line),
|
|
2369
|
+
fix,
|
|
2370
|
+
...downgrade ? {} : { live: true }
|
|
2371
|
+
});
|
|
2372
|
+
noteHardcodedSecret(token);
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2069
2375
|
var hardcodedSecrets = {
|
|
2070
2376
|
id: "VC001",
|
|
2071
2377
|
title: "Hardcoded API Key or Secret",
|
|
@@ -2167,10 +2473,9 @@ var hardcodedSecrets = {
|
|
|
2167
2473
|
50,
|
|
2168
2474
|
// [3] Supabase JWT
|
|
2169
2475
|
// [4] OpenAI and [11]–[14] fixed-prefix tokens: the regex already
|
|
2170
|
-
// fixes the length
|
|
2171
|
-
//
|
|
2172
|
-
//
|
|
2173
|
-
// made redundant everywhere except that misread.)
|
|
2476
|
+
// fixes the length, so the floor is 0. Every other floor measures this
|
|
2477
|
+
// match's own value. A live credential skips the floor. A placeholder
|
|
2478
|
+
// is dropped first, so a template key is never reported.
|
|
2174
2479
|
0,
|
|
2175
2480
|
20,
|
|
2176
2481
|
// [5] generic tokens with {20,} in the regex
|
|
@@ -2197,6 +2502,27 @@ var hardcodedSecrets = {
|
|
|
2197
2502
|
const lines = content.split("\n");
|
|
2198
2503
|
const fileIsGemini = GEMINI_FILE_CONTEXT_RE.test(content);
|
|
2199
2504
|
const matches = [];
|
|
2505
|
+
const columnFrom = /* @__PURE__ */ new Map();
|
|
2506
|
+
const locate = (lineNo, line, secret) => {
|
|
2507
|
+
if (!secret) return void 0;
|
|
2508
|
+
const key = `${lineNo}\0${secret}`;
|
|
2509
|
+
const start = columnFrom.get(key) ?? 0;
|
|
2510
|
+
const at = line.indexOf(secret, start);
|
|
2511
|
+
if (at < 0) return void 0;
|
|
2512
|
+
columnFrom.set(key, at + secret.length);
|
|
2513
|
+
return at + 1;
|
|
2514
|
+
};
|
|
2515
|
+
const emit = (rm, secret, extra = {}) => {
|
|
2516
|
+
const column = locate(rm.line, lines[rm.line - 1] || "", secret);
|
|
2517
|
+
const stripeSev = extra.live || extra.severity ? void 0 : stripeReportedSeverity(secret);
|
|
2518
|
+
matches.push({
|
|
2519
|
+
...rm,
|
|
2520
|
+
...extra,
|
|
2521
|
+
...stripeSev ? { severity: stripeSev } : {},
|
|
2522
|
+
...column ? { column } : {}
|
|
2523
|
+
});
|
|
2524
|
+
noteHardcodedSecret(secret);
|
|
2525
|
+
};
|
|
2200
2526
|
for (let pi = 0; pi < patterns.length; pi++) {
|
|
2201
2527
|
const pattern = patterns[pi];
|
|
2202
2528
|
if (pi === GOOGLE_PI && !fileIsGemini && !GEMINI_NAME_RE.test(content)) continue;
|
|
@@ -2221,30 +2547,27 @@ var hardcodedSecrets = {
|
|
|
2221
2547
|
if (isPlaceholderToken(token)) continue;
|
|
2222
2548
|
if (pi === GOOGLE_PI) {
|
|
2223
2549
|
if (!isGeminiKeyContext(lines, rm.line, fileIsGemini)) continue;
|
|
2224
|
-
|
|
2225
|
-
noteHardcodedSecret(secretText[ri] ?? "");
|
|
2550
|
+
emit(rm, secretText[ri] ?? token, textHasLiveCredential(token) ? { severity: "high", live: true } : { severity: "high" });
|
|
2226
2551
|
continue;
|
|
2227
2552
|
}
|
|
2228
2553
|
if (pi === STRIPE_RESTRICTED_PI && !token.startsWith("rk_live_")) {
|
|
2229
|
-
|
|
2230
|
-
noteHardcodedSecret(secretText[ri] ?? "");
|
|
2554
|
+
emit(rm, secretText[ri] ?? token, { severity: "high" });
|
|
2231
2555
|
continue;
|
|
2232
2556
|
}
|
|
2233
2557
|
if (textHasLiveCredential(token)) {
|
|
2234
|
-
|
|
2235
|
-
noteHardcodedSecret(secretText[ri] ?? "");
|
|
2558
|
+
emit(rm, secretText[ri] ?? token, { live: true });
|
|
2236
2559
|
continue;
|
|
2237
2560
|
}
|
|
2238
2561
|
}
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2562
|
+
const judged = secretText[ri] && secretText[ri].length > 0 ? secretText[ri] : matchedText[ri] ?? "";
|
|
2563
|
+
const judgedLive = textHasLiveCredential(judged) || liveDespiteIdenticalRun(judged);
|
|
2564
|
+
if (pi !== 9 && pi !== 10 && !judgedLive && isLockedVc001Placeholder(judged)) continue;
|
|
2565
|
+
const matchedLive = textHasLiveCredential(matchedText[ri] ?? "") || judgedLive;
|
|
2566
|
+
if (!matchedLive && floor > 0 && judged.length < floor) continue;
|
|
2243
2567
|
if (pi === 6) {
|
|
2244
|
-
const
|
|
2568
|
+
const value = judged;
|
|
2245
2569
|
const nameMatch = (matchedText[ri] ?? "").match(/^[A-Z][A-Z0-9_]{0,64}_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD)\b/);
|
|
2246
|
-
if (
|
|
2247
|
-
const value = valMatch[1];
|
|
2570
|
+
if (value && nameMatch) {
|
|
2248
2571
|
const isKeySuffix = nameMatch[0].endsWith("_KEY");
|
|
2249
2572
|
const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(nameMatch[0], value));
|
|
2250
2573
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
@@ -2253,15 +2576,18 @@ var hardcodedSecrets = {
|
|
|
2253
2576
|
if (pi === 10) {
|
|
2254
2577
|
const url = matchedText[ri] ?? "";
|
|
2255
2578
|
if (dbUrlLacksRealCredential(url)) continue;
|
|
2256
|
-
|
|
2257
|
-
|
|
2579
|
+
emit(
|
|
2580
|
+
rm,
|
|
2581
|
+
secretText[ri] ?? url,
|
|
2582
|
+
isLoopbackDevDefault(url) ? { severity: "low" } : textHasLiveCredential(url) ? { live: true } : {}
|
|
2583
|
+
);
|
|
2258
2584
|
continue;
|
|
2259
2585
|
}
|
|
2260
2586
|
const matched = matchedText[ri] ?? "";
|
|
2261
|
-
|
|
2262
|
-
noteHardcodedSecret(secretText[ri] ?? "");
|
|
2587
|
+
emit(rm, judged, textHasLiveCredential(matched) || matchedLive ? { live: true } : {});
|
|
2263
2588
|
}
|
|
2264
2589
|
}
|
|
2590
|
+
collectSupabaseCreateClientKeys(content, filePath, matches, hardcodedSecrets, fixMessages[3]);
|
|
2265
2591
|
return matches;
|
|
2266
2592
|
}
|
|
2267
2593
|
};
|
|
@@ -3838,7 +4164,7 @@ var hardcodedJWTSecret = {
|
|
|
3838
4164
|
category: "Secrets",
|
|
3839
4165
|
description: "JWT tokens signed with a hardcoded string secret can be forged by anyone who reads the source code.",
|
|
3840
4166
|
check(content, filePath) {
|
|
3841
|
-
if (filePath.endsWith(".example") || filePath.endsWith(".template") || filePath
|
|
4167
|
+
if (filePath.endsWith(".example") || filePath.endsWith(".template") || isTestFile(filePath)) return [];
|
|
3842
4168
|
const patterns = [
|
|
3843
4169
|
/jwt\.sign\s*\([^,]{1,300},\s*["'`][^"'`]{3,}["'`]/g,
|
|
3844
4170
|
/jwt\.verify\s*\([^,]{1,300},\s*["'`][^"'`]{3,}["'`]/g,
|
|
@@ -3930,7 +4256,7 @@ var exposedDebugMode = {
|
|
|
3930
4256
|
category: "Configuration",
|
|
3931
4257
|
description: "Debug mode, verbose logging, or development configuration left in production code exposes internal details and may enable debug endpoints.",
|
|
3932
4258
|
check(content, filePath) {
|
|
3933
|
-
if (filePath
|
|
4259
|
+
if (isTestFile(filePath) || filePath.endsWith(".example") || filePath.includes("node_modules")) return [];
|
|
3934
4260
|
if (filePath.match(/\.env\.development$/)) return [];
|
|
3935
4261
|
const matches = [];
|
|
3936
4262
|
const patterns = [
|
|
@@ -4094,7 +4420,7 @@ var weakHashing = {
|
|
|
4094
4420
|
category: "Cryptography",
|
|
4095
4421
|
description: "MD5 and SHA1/SHA256 are too fast for password hashing \u2014 they can be brute-forced at billions of attempts per second. Use bcrypt, scrypt, or argon2 instead.",
|
|
4096
4422
|
check(content, filePath) {
|
|
4097
|
-
if (
|
|
4423
|
+
if (isTestFile(filePath)) return [];
|
|
4098
4424
|
if (/bcrypt|scrypt|argon2/i.test(content)) return [];
|
|
4099
4425
|
const matches = [];
|
|
4100
4426
|
const inlinePatterns = [
|
|
@@ -4868,13 +5194,14 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4868
5194
|
live: match.live,
|
|
4869
5195
|
snippet: match.snippet
|
|
4870
5196
|
});
|
|
5197
|
+
const testFixture = onTestPath && !live;
|
|
4871
5198
|
findings.push({
|
|
4872
5199
|
...vendored ? { vendored: true } : {},
|
|
4873
|
-
...
|
|
5200
|
+
...testFixture ? { testFile: true } : {},
|
|
4874
5201
|
...live ? { live: true } : {},
|
|
4875
5202
|
id: `${match.rule}-${match.file}:${match.line}`,
|
|
4876
5203
|
rule: match.rule,
|
|
4877
|
-
severity: match.severity,
|
|
5204
|
+
severity: vc001TestFixtureSeverity(match.rule, testFixture ? true : void 0, match.severity),
|
|
4878
5205
|
title: match.title,
|
|
4879
5206
|
description: rule.description,
|
|
4880
5207
|
file: match.file,
|
|
@@ -5541,6 +5868,255 @@ function scanEntropyFiles(files, collect) {
|
|
|
5541
5868
|
return findings;
|
|
5542
5869
|
}
|
|
5543
5870
|
|
|
5871
|
+
// src/ai-status-constants.ts
|
|
5872
|
+
var AI_STATUSES = ["reviewed", "partial", "skipped", "failed", "unknown"];
|
|
5873
|
+
var AI_REASONS = [
|
|
5874
|
+
"no_api_key",
|
|
5875
|
+
"client_init",
|
|
5876
|
+
"capped",
|
|
5877
|
+
"budget_timeout",
|
|
5878
|
+
"model_bad_output",
|
|
5879
|
+
"model_error",
|
|
5880
|
+
"missing_content",
|
|
5881
|
+
"exception",
|
|
5882
|
+
"opted_out",
|
|
5883
|
+
"auth_failed",
|
|
5884
|
+
"jti_missing",
|
|
5885
|
+
"token_unverified",
|
|
5886
|
+
"pro_rules_unavailable",
|
|
5887
|
+
"engine_unavailable",
|
|
5888
|
+
"upload_failed",
|
|
5889
|
+
"upload_blocked",
|
|
5890
|
+
"upload_duplicate",
|
|
5891
|
+
"persist_failed",
|
|
5892
|
+
"quality_unavailable",
|
|
5893
|
+
"intent_unavailable",
|
|
5894
|
+
"not_supported",
|
|
5895
|
+
"token_secret_missing",
|
|
5896
|
+
"rate_limited",
|
|
5897
|
+
"jti_unavailable",
|
|
5898
|
+
"credit_error",
|
|
5899
|
+
"daily_limit",
|
|
5900
|
+
"signed_out"
|
|
5901
|
+
];
|
|
5902
|
+
var AI_SURFACES = ["upload", "cli", "action", "app", "api", "mcp", "web", "save"];
|
|
5903
|
+
var PLAN_CAUSES = [
|
|
5904
|
+
"missing",
|
|
5905
|
+
"malformed",
|
|
5906
|
+
"expired",
|
|
5907
|
+
"revoked",
|
|
5908
|
+
"network",
|
|
5909
|
+
"upstream_5xx",
|
|
5910
|
+
"unknown"
|
|
5911
|
+
];
|
|
5912
|
+
var WEBHOOK_REASONS = [
|
|
5913
|
+
"no_metadata_user",
|
|
5914
|
+
"malformed_user",
|
|
5915
|
+
"unknown_user",
|
|
5916
|
+
"user_bound_other_customer",
|
|
5917
|
+
"race_no_row",
|
|
5918
|
+
"deleted_unmatched",
|
|
5919
|
+
"clerk_lookup_failed"
|
|
5920
|
+
];
|
|
5921
|
+
var WEBHOOK_EVENT_TYPES = [
|
|
5922
|
+
"checkout.session.completed",
|
|
5923
|
+
"customer.subscription.created",
|
|
5924
|
+
"customer.subscription.updated",
|
|
5925
|
+
"customer.subscription.deleted",
|
|
5926
|
+
"invoice.paid",
|
|
5927
|
+
"invoice.payment_failed",
|
|
5928
|
+
"created",
|
|
5929
|
+
"updated"
|
|
5930
|
+
];
|
|
5931
|
+
|
|
5932
|
+
// src/ai-status.ts
|
|
5933
|
+
var PLAN_UNVERIFIED_NOTICE = "Couldn't verify your plan, scanned with free rules only.";
|
|
5934
|
+
var FAIL_REASONS = /* @__PURE__ */ new Set([
|
|
5935
|
+
"budget_timeout",
|
|
5936
|
+
"model_error",
|
|
5937
|
+
"model_bad_output",
|
|
5938
|
+
"auth_failed",
|
|
5939
|
+
"exception",
|
|
5940
|
+
"client_init"
|
|
5941
|
+
]);
|
|
5942
|
+
function clampCount(raw) {
|
|
5943
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) return 0;
|
|
5944
|
+
return Math.min(Math.trunc(raw), 1e6);
|
|
5945
|
+
}
|
|
5946
|
+
function isStatus(raw) {
|
|
5947
|
+
return typeof raw === "string" && AI_STATUSES.includes(raw);
|
|
5948
|
+
}
|
|
5949
|
+
function isReason(raw) {
|
|
5950
|
+
return typeof raw === "string" && AI_REASONS.includes(raw);
|
|
5951
|
+
}
|
|
5952
|
+
function isSurface(raw) {
|
|
5953
|
+
return typeof raw === "string" && AI_SURFACES.includes(raw);
|
|
5954
|
+
}
|
|
5955
|
+
function bucketFiles(n) {
|
|
5956
|
+
if (typeof n !== "number" || !Number.isFinite(n) || n <= 0) return "0";
|
|
5957
|
+
const v = Math.trunc(n);
|
|
5958
|
+
if (v < 5) return "1-4";
|
|
5959
|
+
if (v < 20) return "5-19";
|
|
5960
|
+
return "20+";
|
|
5961
|
+
}
|
|
5962
|
+
function planCause(specific) {
|
|
5963
|
+
switch (specific) {
|
|
5964
|
+
case "secret_missing":
|
|
5965
|
+
return "missing";
|
|
5966
|
+
case "bad_shape":
|
|
5967
|
+
case "sig_mismatch":
|
|
5968
|
+
case "sig_length_mismatch":
|
|
5969
|
+
case "hmac_error":
|
|
5970
|
+
case "payload_parse_error":
|
|
5971
|
+
case "uid_or_tier_wrong_type":
|
|
5972
|
+
return "malformed";
|
|
5973
|
+
case "expired":
|
|
5974
|
+
case "exp_missing_or_nan":
|
|
5975
|
+
return "expired";
|
|
5976
|
+
case "tier_not_paid_unknown_value":
|
|
5977
|
+
case "http_401":
|
|
5978
|
+
case "http_403":
|
|
5979
|
+
return "revoked";
|
|
5980
|
+
case "no_cached_bundle_and_network_error":
|
|
5981
|
+
case "timeout":
|
|
5982
|
+
case "network":
|
|
5983
|
+
return "network";
|
|
5984
|
+
case "http_5xx":
|
|
5985
|
+
case "upstream_5xx":
|
|
5986
|
+
return "upstream_5xx";
|
|
5987
|
+
default:
|
|
5988
|
+
return "unknown";
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
function toAiDegraded(input = {}) {
|
|
5992
|
+
const total = clampCount(input.total);
|
|
5993
|
+
let reviewed = clampCount(input.reviewed);
|
|
5994
|
+
let capped = clampCount(input.capped);
|
|
5995
|
+
if (reviewed > total) reviewed = total;
|
|
5996
|
+
if (reviewed + capped > total) capped = total - reviewed;
|
|
5997
|
+
const unreviewed = total - reviewed - capped;
|
|
5998
|
+
let status = isStatus(input.status) ? input.status : "unknown";
|
|
5999
|
+
let reason = isReason(input.reason) ? input.reason : null;
|
|
6000
|
+
const eligible = total - capped;
|
|
6001
|
+
if (status === "reviewed" && reviewed !== eligible) {
|
|
6002
|
+
status = reviewed === 0 && reason != null && FAIL_REASONS.has(reason) ? "failed" : "partial";
|
|
6003
|
+
}
|
|
6004
|
+
if (status === "reviewed" && unreviewed > 0) status = "partial";
|
|
6005
|
+
if (status === "skipped" && reason != null && FAIL_REASONS.has(reason)) status = "failed";
|
|
6006
|
+
if (status === "reviewed" || status === "unknown") {
|
|
6007
|
+
if (status === "unknown") reason = null;
|
|
6008
|
+
}
|
|
6009
|
+
const modelStatus = reason === "model_error" && typeof input.modelStatus === "number" && Number.isFinite(input.modelStatus) ? Math.trunc(input.modelStatus) : null;
|
|
6010
|
+
return {
|
|
6011
|
+
status,
|
|
6012
|
+
reason,
|
|
6013
|
+
surface: isSurface(input.surface) ? input.surface : "cli",
|
|
6014
|
+
total,
|
|
6015
|
+
reviewed,
|
|
6016
|
+
unreviewed,
|
|
6017
|
+
capped,
|
|
6018
|
+
modelStatus
|
|
6019
|
+
};
|
|
6020
|
+
}
|
|
6021
|
+
function unknownAiStatus(surface = "save") {
|
|
6022
|
+
return toAiDegraded({ status: "unknown", reason: null, surface, total: 0, reviewed: 0, unreviewed: 0, capped: 0 });
|
|
6023
|
+
}
|
|
6024
|
+
function aiStatusLine(d) {
|
|
6025
|
+
const shown = Math.max(0, d.total - d.capped);
|
|
6026
|
+
switch (d.reason) {
|
|
6027
|
+
case "no_api_key":
|
|
6028
|
+
return "AI review skipped: no Anthropic API key is set.";
|
|
6029
|
+
case "opted_out":
|
|
6030
|
+
return "AI review skipped: user opted out.";
|
|
6031
|
+
case "not_supported":
|
|
6032
|
+
return "AI review not run on MCP scans.";
|
|
6033
|
+
case "auth_failed":
|
|
6034
|
+
return "AI review failed: the Anthropic API key was rejected.";
|
|
6035
|
+
case "capped":
|
|
6036
|
+
return `AI review covered the first ${shown} of ${d.total} findings.`;
|
|
6037
|
+
case "budget_timeout":
|
|
6038
|
+
return d.status === "failed" ? `AI review failed: every batch timed out (${d.reviewed} reviewed, ${d.unreviewed} unreviewed, ${d.capped} capped, ${d.total} total).` : `AI review was partial: the time limit ran out (${d.reviewed} reviewed of ${d.total}).`;
|
|
6039
|
+
case "client_init":
|
|
6040
|
+
return "AI review failed: the AI client could not start.";
|
|
6041
|
+
case "model_bad_output":
|
|
6042
|
+
return "AI review failed: the model returned unusable output.";
|
|
6043
|
+
case "model_error":
|
|
6044
|
+
return `AI review failed: the model request was rejected (HTTP ${d.modelStatus ?? "error"}).`;
|
|
6045
|
+
case "missing_content":
|
|
6046
|
+
return "AI review was partial: source content was missing for some findings.";
|
|
6047
|
+
case "exception":
|
|
6048
|
+
return "AI review failed: an unexpected error occurred.";
|
|
6049
|
+
case "token_secret_missing":
|
|
6050
|
+
return "AI review skipped: scan token verification is not configured.";
|
|
6051
|
+
case "rate_limited":
|
|
6052
|
+
return "AI review skipped: rate limited.";
|
|
6053
|
+
case "jti_unavailable":
|
|
6054
|
+
return "AI review skipped: the review token could not be checked in time.";
|
|
6055
|
+
case "jti_missing":
|
|
6056
|
+
return "AI review skipped: the review token had no single-use id.";
|
|
6057
|
+
case "credit_error":
|
|
6058
|
+
return "AI review skipped: the review credit could not be spent.";
|
|
6059
|
+
case "daily_limit":
|
|
6060
|
+
return "AI review skipped: daily limit reached.";
|
|
6061
|
+
case "signed_out":
|
|
6062
|
+
return "AI review skipped: signed out.";
|
|
6063
|
+
case "quality_unavailable":
|
|
6064
|
+
return "Quality checks were unavailable for this scan.";
|
|
6065
|
+
case "intent_unavailable":
|
|
6066
|
+
return "Intent check was unavailable for this scan.";
|
|
6067
|
+
case "engine_unavailable":
|
|
6068
|
+
return "A scan engine was unavailable.";
|
|
6069
|
+
case "upload_failed":
|
|
6070
|
+
return "The scan could not be uploaded.";
|
|
6071
|
+
case "upload_blocked":
|
|
6072
|
+
return "The scan was not uploaded: the plan limit blocked it.";
|
|
6073
|
+
case "upload_duplicate":
|
|
6074
|
+
return "The scan was already uploaded for this job.";
|
|
6075
|
+
case "persist_failed":
|
|
6076
|
+
return "The scan status could not be stored.";
|
|
6077
|
+
case "token_unverified":
|
|
6078
|
+
case "pro_rules_unavailable":
|
|
6079
|
+
return PLAN_UNVERIFIED_NOTICE;
|
|
6080
|
+
default:
|
|
6081
|
+
if (d.status === "reviewed") return "AI review completed.";
|
|
6082
|
+
if (d.status === "unknown") return "AI review status is unknown.";
|
|
6083
|
+
if (d.status === "partial") return `AI review was partial: ${d.reviewed} of ${d.total} findings reviewed.`;
|
|
6084
|
+
if (d.status === "failed") return "AI review failed.";
|
|
6085
|
+
return "AI review skipped.";
|
|
6086
|
+
}
|
|
6087
|
+
}
|
|
6088
|
+
var SCAN_AI_DEGRADED_KEYS = [
|
|
6089
|
+
"status",
|
|
6090
|
+
"reason",
|
|
6091
|
+
"surface",
|
|
6092
|
+
"total",
|
|
6093
|
+
"reviewed",
|
|
6094
|
+
"capped",
|
|
6095
|
+
"files_received_bucket"
|
|
6096
|
+
];
|
|
6097
|
+
function scanAiDegradedProps(d, filesReceived) {
|
|
6098
|
+
return {
|
|
6099
|
+
status: d.status,
|
|
6100
|
+
reason: d.reason,
|
|
6101
|
+
surface: d.surface,
|
|
6102
|
+
total: d.total,
|
|
6103
|
+
reviewed: d.reviewed,
|
|
6104
|
+
capped: d.capped,
|
|
6105
|
+
files_received_bucket: bucketFiles(filesReceived)
|
|
6106
|
+
};
|
|
6107
|
+
}
|
|
6108
|
+
var SCAN_TOKEN_NULL_KEYS = ["cause", "surface", "tier_expected"];
|
|
6109
|
+
function scanTokenNullProps(cause, surface) {
|
|
6110
|
+
const safeSurface = isSurface(surface) ? surface : "api";
|
|
6111
|
+
return { cause, surface: safeSurface, tier_expected: "paid" };
|
|
6112
|
+
}
|
|
6113
|
+
var BILLING_WEBHOOK_UNMATCHED_KEYS = ["type", "reason", "final"];
|
|
6114
|
+
function billingWebhookUnmatchedProps(input) {
|
|
6115
|
+
const reason = typeof input.reason === "string" && WEBHOOK_REASONS.includes(input.reason) ? input.reason : "race_no_row";
|
|
6116
|
+
const type = typeof input.type === "string" && input.type.length > 0 && input.type.length < 80 ? input.type : "unknown";
|
|
6117
|
+
return { type, reason, final: input.final === true };
|
|
6118
|
+
}
|
|
6119
|
+
|
|
5544
6120
|
// src/ai-fp-filter.ts
|
|
5545
6121
|
var REVIEW_SYSTEM_PROMPT = `You are reviewing security scan findings for false positives. Your job is to look at each finding and the surrounding code to determine if it's a REAL security vulnerability or a FALSE POSITIVE.
|
|
5546
6122
|
|
|
@@ -5600,6 +6176,15 @@ var AI_FILTER_BUDGET_MS = (() => {
|
|
|
5600
6176
|
return Math.min(n, 6e4);
|
|
5601
6177
|
})();
|
|
5602
6178
|
var PER_CALL_TIMEOUT_MS = 8e3;
|
|
6179
|
+
function perCallTimeoutMs(budgetMs) {
|
|
6180
|
+
const budget = Number.isFinite(budgetMs) && budgetMs >= 1 ? Math.min(Math.trunc(budgetMs), 6e4) : DEFAULT_AI_FILTER_BUDGET_MS;
|
|
6181
|
+
const scaled = Math.floor(budget * 0.6);
|
|
6182
|
+
const perCall = Math.min(PER_CALL_TIMEOUT_MS, scaled);
|
|
6183
|
+
return perCall;
|
|
6184
|
+
}
|
|
6185
|
+
if (!(perCallTimeoutMs(AI_FILTER_BUDGET_MS) < AI_FILTER_BUDGET_MS)) {
|
|
6186
|
+
throw new Error("per-call AI timeout must be strictly below the filter budget");
|
|
6187
|
+
}
|
|
5603
6188
|
function isAbortError(err) {
|
|
5604
6189
|
if (!err || typeof err !== "object") return false;
|
|
5605
6190
|
const name = "name" in err ? String(err.name) : "";
|
|
@@ -5612,6 +6197,16 @@ function isTimeoutError(err) {
|
|
|
5612
6197
|
const message = err instanceof Error ? err.message : String(err);
|
|
5613
6198
|
return /\b(?:request|connection|operation|model call)\s+(?:has\s+)?timed out\b/i.test(message) || /\bETIMEDOUT\b/i.test(message);
|
|
5614
6199
|
}
|
|
6200
|
+
function errorHttpStatus(err) {
|
|
6201
|
+
if (!err || typeof err !== "object") return null;
|
|
6202
|
+
const status = err.status;
|
|
6203
|
+
return typeof status === "number" && Number.isFinite(status) ? Math.trunc(status) : null;
|
|
6204
|
+
}
|
|
6205
|
+
function callWasAborted(err) {
|
|
6206
|
+
if (!err || typeof err !== "object") return false;
|
|
6207
|
+
const name = "name" in err ? String(err.name) : "";
|
|
6208
|
+
return name === "AbortError" || name === "APIUserAbortError";
|
|
6209
|
+
}
|
|
5615
6210
|
var SEVERITY_PRIORITY = {
|
|
5616
6211
|
critical: 0,
|
|
5617
6212
|
high: 1,
|
|
@@ -5761,8 +6356,10 @@ function parseReviewResponse(text) {
|
|
|
5761
6356
|
return null;
|
|
5762
6357
|
}
|
|
5763
6358
|
}
|
|
5764
|
-
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS) {
|
|
5765
|
-
const
|
|
6359
|
+
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS, options) {
|
|
6360
|
+
const surface = options?.surface ?? "cli";
|
|
6361
|
+
const emptyMask = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
|
|
6362
|
+
const early = (status2, reason2, extra) => ({
|
|
5766
6363
|
findings,
|
|
5767
6364
|
filteredFindings: [],
|
|
5768
6365
|
policyRetainedFindings: [],
|
|
@@ -5770,15 +6367,27 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5770
6367
|
removedCount: 0,
|
|
5771
6368
|
policyRetainedCount: 0,
|
|
5772
6369
|
totalBefore: findings.length,
|
|
5773
|
-
reviewedCount: 0,
|
|
5774
|
-
unreviewedCount: findings.length,
|
|
5775
|
-
cappedCount: 0,
|
|
6370
|
+
reviewedCount: extra?.reviewed ?? 0,
|
|
6371
|
+
unreviewedCount: extra?.unreviewed ?? findings.length,
|
|
6372
|
+
cappedCount: extra?.capped ?? 0,
|
|
5776
6373
|
missingContentCount: 0,
|
|
5777
6374
|
timedOut: false,
|
|
5778
|
-
maskStats:
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
6375
|
+
maskStats: emptyMask,
|
|
6376
|
+
aiDegraded: toAiDegraded({
|
|
6377
|
+
status: status2,
|
|
6378
|
+
reason: reason2,
|
|
6379
|
+
surface,
|
|
6380
|
+
total: findings.length,
|
|
6381
|
+
reviewed: extra?.reviewed ?? 0,
|
|
6382
|
+
unreviewed: extra?.unreviewed ?? findings.length,
|
|
6383
|
+
capped: extra?.capped ?? 0,
|
|
6384
|
+
modelStatus: extra?.modelStatus ?? null
|
|
6385
|
+
})
|
|
6386
|
+
});
|
|
6387
|
+
if (findings.length === 0) {
|
|
6388
|
+
return early("reviewed", null, { reviewed: 0, unreviewed: 0, capped: 0 });
|
|
6389
|
+
}
|
|
6390
|
+
if (!process.env.ANTHROPIC_API_KEY) return early("skipped", "no_api_key");
|
|
5782
6391
|
const deadlineMs = Date.now() + Math.max(0, budgetMs);
|
|
5783
6392
|
const abortController = new AbortController();
|
|
5784
6393
|
let budgetExpired = budgetMs <= 0;
|
|
@@ -5808,12 +6417,20 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5808
6417
|
try {
|
|
5809
6418
|
client = new Anthropic();
|
|
5810
6419
|
} catch {
|
|
5811
|
-
|
|
6420
|
+
if (budgetTimer) clearTimeout(budgetTimer);
|
|
6421
|
+
return early("failed", "client_init", {
|
|
6422
|
+
reviewed: 0,
|
|
6423
|
+
capped: overflow.length,
|
|
6424
|
+
unreviewed: findings.length - overflow.length
|
|
6425
|
+
});
|
|
5812
6426
|
}
|
|
5813
6427
|
const fpMap = /* @__PURE__ */ new Map();
|
|
5814
6428
|
const policyRetainedMap = /* @__PURE__ */ new Map();
|
|
5815
6429
|
const reviewedIndices = /* @__PURE__ */ new Set();
|
|
5816
6430
|
let firstError = null;
|
|
6431
|
+
let firstErrorStatus = null;
|
|
6432
|
+
let authFailed = false;
|
|
6433
|
+
let badOutput = false;
|
|
5817
6434
|
const maskStats = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
|
|
5818
6435
|
let failedBatches = 0;
|
|
5819
6436
|
let timedOutCount = 0;
|
|
@@ -5839,9 +6456,11 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5839
6456
|
const reviewBatch = async (task) => {
|
|
5840
6457
|
const { targets, content, detections } = task;
|
|
5841
6458
|
const batch = targets.map((target) => target.finding);
|
|
5842
|
-
if (abortController.signal.aborted || Date.now() >= deadlineMs) {
|
|
5843
|
-
|
|
5844
|
-
|
|
6459
|
+
if (authFailed || abortController.signal.aborted || Date.now() >= deadlineMs) {
|
|
6460
|
+
if (!authFailed) {
|
|
6461
|
+
budgetExpired = true;
|
|
6462
|
+
timedOutCount += batch.length;
|
|
6463
|
+
}
|
|
5845
6464
|
return;
|
|
5846
6465
|
}
|
|
5847
6466
|
try {
|
|
@@ -5853,7 +6472,7 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5853
6472
|
maskStats.masked_count += proof.detected - proof.raw;
|
|
5854
6473
|
maskStats.raw_after_mask += proof.raw;
|
|
5855
6474
|
if (proof.detected > 0) maskStats.had_secret_pattern = true;
|
|
5856
|
-
console.
|
|
6475
|
+
console.error(
|
|
5857
6476
|
`[ai-fp-filter] batch prompt ${prompt.length} chars (~${Math.ceil(prompt.length / 4)} tokens), ${batch.length} finding(s)`
|
|
5858
6477
|
);
|
|
5859
6478
|
if (prompt.length > MAX_BATCH_PROMPT_CHARS) {
|
|
@@ -5861,38 +6480,52 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5861
6480
|
`[ai-fp-filter] batch prompt ${prompt.length} chars exceeds ${MAX_BATCH_PROMPT_CHARS} cap (single oversized finding after truncation)`
|
|
5862
6481
|
);
|
|
5863
6482
|
}
|
|
5864
|
-
const
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
6483
|
+
const perCall = perCallTimeoutMs(budgetMs);
|
|
6484
|
+
const callTimeout = Math.min(perCall, remaining);
|
|
6485
|
+
const callAbort = new AbortController();
|
|
6486
|
+
const onParentAbort = () => callAbort.abort();
|
|
6487
|
+
if (abortController.signal.aborted) callAbort.abort();
|
|
6488
|
+
else abortController.signal.addEventListener("abort", onParentAbort, { once: true });
|
|
6489
|
+
const callTimer = setTimeout(() => callAbort.abort(), callTimeout);
|
|
6490
|
+
let response;
|
|
6491
|
+
try {
|
|
6492
|
+
response = await client.messages.create(
|
|
6493
|
+
{
|
|
6494
|
+
model: MODEL_TRIAGE,
|
|
6495
|
+
max_tokens: 2048,
|
|
6496
|
+
// Haiku 5.5 rejects non-default sampling params with HTTP 400
|
|
6497
|
+
// ("temperature is deprecated for this model"). Omit temperature /
|
|
6498
|
+
// top_p / top_k entirely — do NOT send MODEL_TEMPERATURE (0).
|
|
6499
|
+
// Adaptive thinking is on by default for 5.5; disable it here: this
|
|
6500
|
+
// is binary FP classification, not open-ended analysis, and thinking
|
|
6501
|
+
// burns the shared AI budget (Isobar rescan: every call 400'd on
|
|
6502
|
+
// temperature, then timed_out with aiReviewed:false → grade D).
|
|
6503
|
+
thinking: { type: "disabled" },
|
|
6504
|
+
system: REVIEW_SYSTEM_PROMPT,
|
|
6505
|
+
messages: [{ role: "user", content: prompt }]
|
|
6506
|
+
},
|
|
6507
|
+
{ timeout: callTimeout, signal: callAbort.signal }
|
|
6508
|
+
);
|
|
6509
|
+
} finally {
|
|
6510
|
+
clearTimeout(callTimer);
|
|
6511
|
+
abortController.signal.removeEventListener("abort", onParentAbort);
|
|
6512
|
+
}
|
|
5883
6513
|
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
5884
6514
|
const results = parseReviewResponse(text);
|
|
5885
|
-
if (!results)
|
|
6515
|
+
if (!results) {
|
|
6516
|
+
badOutput = true;
|
|
6517
|
+
throw new Error("AI review returned malformed JSON");
|
|
6518
|
+
}
|
|
5886
6519
|
for (const r of results) {
|
|
5887
6520
|
if (r.index >= batch.length) continue;
|
|
5888
6521
|
const target = targets[r.index];
|
|
5889
6522
|
reviewedIndices.add(target.originalIndex);
|
|
5890
6523
|
if (r.verdict !== "fp") continue;
|
|
5891
|
-
const
|
|
6524
|
+
const reason2 = truncateChars(applySecretMasks(r.reason, secrets), MAX_FIELD_CHARS);
|
|
5892
6525
|
if (isProtectedFromAiRemoval(target.finding)) {
|
|
5893
|
-
policyRetainedMap.set(target.originalIndex,
|
|
6526
|
+
policyRetainedMap.set(target.originalIndex, reason2);
|
|
5894
6527
|
} else {
|
|
5895
|
-
fpMap.set(target.originalIndex,
|
|
6528
|
+
fpMap.set(target.originalIndex, reason2);
|
|
5896
6529
|
}
|
|
5897
6530
|
}
|
|
5898
6531
|
if (results.filter((result) => result.index < batch.length).length < batch.length) {
|
|
@@ -5900,21 +6533,35 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5900
6533
|
if (!firstError) firstError = new Error("AI review returned incomplete verdicts");
|
|
5901
6534
|
}
|
|
5902
6535
|
} catch (err) {
|
|
5903
|
-
const
|
|
6536
|
+
const status2 = errorHttpStatus(err);
|
|
6537
|
+
if (status2 === 401 || status2 === 403) {
|
|
6538
|
+
authFailed = true;
|
|
6539
|
+
failedBatches++;
|
|
6540
|
+
if (!firstError) {
|
|
6541
|
+
firstError = err;
|
|
6542
|
+
firstErrorStatus = status2;
|
|
6543
|
+
}
|
|
6544
|
+
console.error(`[ai-fp-filter] AI review failed: auth status ${status2}`);
|
|
6545
|
+
return;
|
|
6546
|
+
}
|
|
6547
|
+
const callTimedOut = isAbortError(err) || isTimeoutError(err) || abortController.signal.aborted || callWasAborted(err);
|
|
5904
6548
|
if (callTimedOut) {
|
|
5905
6549
|
timedOutCount += batch.length;
|
|
5906
6550
|
budgetExpired = true;
|
|
5907
6551
|
return;
|
|
5908
6552
|
}
|
|
5909
6553
|
failedBatches++;
|
|
5910
|
-
if (!firstError)
|
|
6554
|
+
if (!firstError) {
|
|
6555
|
+
firstError = err;
|
|
6556
|
+
firstErrorStatus = status2;
|
|
6557
|
+
}
|
|
5911
6558
|
}
|
|
5912
6559
|
};
|
|
5913
6560
|
try {
|
|
5914
6561
|
let next = 0;
|
|
5915
6562
|
const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
|
|
5916
6563
|
const workers = Array.from({ length: workerCount }, async () => {
|
|
5917
|
-
while (next < tasks.length) {
|
|
6564
|
+
while (next < tasks.length && !authFailed) {
|
|
5918
6565
|
const cur = next++;
|
|
5919
6566
|
await reviewBatch(tasks[cur]);
|
|
5920
6567
|
}
|
|
@@ -5932,28 +6579,70 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5932
6579
|
`[ai-fp-filter] budget expired or model call timed out \u2014 ${timedOutCount} finding(s) not reviewed; returning them unchanged`
|
|
5933
6580
|
);
|
|
5934
6581
|
}
|
|
5935
|
-
if (firstError) {
|
|
5936
|
-
const
|
|
6582
|
+
if (firstError && !authFailed) {
|
|
6583
|
+
const statusLabel = firstErrorStatus == null ? "none" : String(firstErrorStatus);
|
|
5937
6584
|
if (!reviewedAny) {
|
|
5938
6585
|
console.error(
|
|
5939
|
-
|
|
5940
|
-
msg
|
|
6586
|
+
`[ai-fp-filter] AI review unavailable \u2014 every model call failed; status ${statusLabel}`
|
|
5941
6587
|
);
|
|
5942
6588
|
} else {
|
|
5943
6589
|
console.warn(
|
|
5944
|
-
`[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed;
|
|
5945
|
-
msg
|
|
6590
|
+
`[ai-fp-filter] partial AI review \u2014 ${failedBatches} of ${tasks.length} batch(es) failed; status ${statusLabel}`
|
|
5946
6591
|
);
|
|
5947
6592
|
}
|
|
5948
6593
|
}
|
|
5949
6594
|
const filtered = findings.filter((_, index) => !fpMap.has(index));
|
|
5950
6595
|
const filteredFindings = [];
|
|
5951
|
-
for (const [index,
|
|
5952
|
-
filteredFindings.push({ finding: findings[index], reason });
|
|
6596
|
+
for (const [index, reason2] of [...fpMap].sort((a, b) => a[0] - b[0])) {
|
|
6597
|
+
filteredFindings.push({ finding: findings[index], reason: reason2 });
|
|
5953
6598
|
}
|
|
5954
6599
|
const policyRetainedFindings = [];
|
|
5955
|
-
for (const [index,
|
|
5956
|
-
policyRetainedFindings.push({ finding: findings[index], reason });
|
|
6600
|
+
for (const [index, reason2] of [...policyRetainedMap].sort((a, b) => a[0] - b[0])) {
|
|
6601
|
+
policyRetainedFindings.push({ finding: findings[index], reason: reason2 });
|
|
6602
|
+
}
|
|
6603
|
+
const cappedCount = overflow.length;
|
|
6604
|
+
const eligible = totalBefore - cappedCount;
|
|
6605
|
+
let reason = null;
|
|
6606
|
+
let status = "reviewed";
|
|
6607
|
+
let modelStatus = null;
|
|
6608
|
+
if (authFailed) {
|
|
6609
|
+
status = "failed";
|
|
6610
|
+
reason = "auth_failed";
|
|
6611
|
+
} else if (reviewedCount === 0 && (timedOut || budgetExpired && tasks.length > 0)) {
|
|
6612
|
+
status = "failed";
|
|
6613
|
+
reason = "budget_timeout";
|
|
6614
|
+
} else if (reviewedCount === 0 && badOutput) {
|
|
6615
|
+
status = "failed";
|
|
6616
|
+
reason = "model_bad_output";
|
|
6617
|
+
} else if (reviewedCount === 0 && firstErrorStatus != null) {
|
|
6618
|
+
status = "failed";
|
|
6619
|
+
reason = "model_error";
|
|
6620
|
+
modelStatus = firstErrorStatus;
|
|
6621
|
+
} else if (reviewedCount === 0 && firstError) {
|
|
6622
|
+
status = "failed";
|
|
6623
|
+
reason = "exception";
|
|
6624
|
+
} else if (reviewedCount === eligible && cappedCount > 0 && missingContentCount === 0) {
|
|
6625
|
+
status = "partial";
|
|
6626
|
+
reason = "capped";
|
|
6627
|
+
} else if (reviewedCount === eligible && missingContentCount === 0 && !firstError && !timedOut) {
|
|
6628
|
+
status = "reviewed";
|
|
6629
|
+
reason = null;
|
|
6630
|
+
} else if (timedOut) {
|
|
6631
|
+
status = reviewedCount === 0 ? "failed" : "partial";
|
|
6632
|
+
reason = "budget_timeout";
|
|
6633
|
+
} else if (missingContentCount > 0 && !firstError && !badOutput) {
|
|
6634
|
+
status = reviewedCount === 0 ? "partial" : "partial";
|
|
6635
|
+
reason = "missing_content";
|
|
6636
|
+
} else if (badOutput) {
|
|
6637
|
+
status = reviewedCount === 0 ? "failed" : "partial";
|
|
6638
|
+
reason = "model_bad_output";
|
|
6639
|
+
} else if (firstErrorStatus != null) {
|
|
6640
|
+
status = "partial";
|
|
6641
|
+
reason = "model_error";
|
|
6642
|
+
modelStatus = firstErrorStatus;
|
|
6643
|
+
} else if (firstError || reviewedCount < eligible) {
|
|
6644
|
+
status = reviewedCount === 0 ? "failed" : "partial";
|
|
6645
|
+
reason = "exception";
|
|
5957
6646
|
}
|
|
5958
6647
|
return {
|
|
5959
6648
|
findings: filtered,
|
|
@@ -5965,10 +6654,20 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5965
6654
|
totalBefore,
|
|
5966
6655
|
reviewedCount,
|
|
5967
6656
|
unreviewedCount,
|
|
5968
|
-
cappedCount
|
|
6657
|
+
cappedCount,
|
|
5969
6658
|
missingContentCount,
|
|
5970
6659
|
timedOut,
|
|
5971
|
-
maskStats
|
|
6660
|
+
maskStats,
|
|
6661
|
+
aiDegraded: toAiDegraded({
|
|
6662
|
+
status,
|
|
6663
|
+
reason,
|
|
6664
|
+
surface,
|
|
6665
|
+
total: totalBefore,
|
|
6666
|
+
reviewed: reviewedCount,
|
|
6667
|
+
unreviewed: totalBefore - reviewedCount - cappedCount,
|
|
6668
|
+
capped: cappedCount,
|
|
6669
|
+
modelStatus
|
|
6670
|
+
})
|
|
5972
6671
|
};
|
|
5973
6672
|
}
|
|
5974
6673
|
|
|
@@ -8081,10 +8780,10 @@ var READ_VERB = /\b(?:select|from|find\w*|query|scan|rows|fetchAll|getAll|list)\
|
|
|
8081
8780
|
function repoReselects(files, originPath, originIndex, table, value) {
|
|
8082
8781
|
const tableToken = table.replace(/["'`]/g, "");
|
|
8083
8782
|
if (tableToken.length < 3) return false;
|
|
8084
|
-
const
|
|
8085
|
-
if (!
|
|
8783
|
+
const valueToken2 = normValue(value);
|
|
8784
|
+
if (!valueToken2 || valueToken2.length < 2) return false;
|
|
8086
8785
|
const tableRe = new RegExp(`\\b${escapeRe(tableToken)}s?\\b`, "gi");
|
|
8087
|
-
const valueRe = new RegExp(`\\b${escapeRe(
|
|
8786
|
+
const valueRe = new RegExp(`\\b${escapeRe(valueToken2)}\\b`, "i");
|
|
8088
8787
|
for (const f of files) {
|
|
8089
8788
|
if (f.excluded) continue;
|
|
8090
8789
|
for (const m of f.code.matchAll(tableRe)) {
|
|
@@ -10610,6 +11309,10 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
10610
11309
|
return findings;
|
|
10611
11310
|
}
|
|
10612
11311
|
export {
|
|
11312
|
+
AI_REASONS,
|
|
11313
|
+
AI_STATUSES,
|
|
11314
|
+
AI_SURFACES,
|
|
11315
|
+
BILLING_WEBHOOK_UNMATCHED_KEYS,
|
|
10613
11316
|
CHECKABLE_CLAIMS,
|
|
10614
11317
|
DOTENV_ASSIGN_RE,
|
|
10615
11318
|
FREE_RULE_COUNT,
|
|
@@ -10621,17 +11324,26 @@ export {
|
|
|
10621
11324
|
MODEL_TEMPERATURE,
|
|
10622
11325
|
MODEL_TRIAGE,
|
|
10623
11326
|
NON_APP_PATH_PATTERNS,
|
|
11327
|
+
PLAN_CAUSES,
|
|
11328
|
+
PLAN_UNVERIFIED_NOTICE,
|
|
10624
11329
|
PRO_RULE_COUNT,
|
|
10625
11330
|
PUBLIC_ENV_PREFIX_RE,
|
|
10626
11331
|
QUALITY_EXAMPLES,
|
|
10627
11332
|
RULE_IMPACTS,
|
|
10628
11333
|
SCANNER_VERSION,
|
|
11334
|
+
SCAN_AI_DEGRADED_KEYS,
|
|
11335
|
+
SCAN_TOKEN_NULL_KEYS,
|
|
10629
11336
|
SERVER_ACTION_WRITE_RE,
|
|
10630
11337
|
TEST_FILE_PATTERN,
|
|
10631
11338
|
TOTAL_RULE_COUNT,
|
|
11339
|
+
WEBHOOK_EVENT_TYPES,
|
|
11340
|
+
WEBHOOK_REASONS,
|
|
11341
|
+
aiStatusLine,
|
|
10632
11342
|
allRules,
|
|
10633
11343
|
assessHeaders,
|
|
10634
11344
|
astMatch,
|
|
11345
|
+
billingWebhookUnmatchedProps,
|
|
11346
|
+
bucketFiles,
|
|
10635
11347
|
buildProjectContext,
|
|
10636
11348
|
buildQualityContext,
|
|
10637
11349
|
buildReviewPrompt,
|
|
@@ -10716,23 +11428,30 @@ export {
|
|
|
10716
11428
|
parseFile,
|
|
10717
11429
|
parseScanTarget,
|
|
10718
11430
|
parseSupabaseConfig,
|
|
11431
|
+
perCallTimeoutMs,
|
|
11432
|
+
planCause,
|
|
10719
11433
|
qualityRules,
|
|
10720
11434
|
replaceBlockComments,
|
|
10721
11435
|
routeForFile,
|
|
10722
11436
|
runCustomRules,
|
|
11437
|
+
scanAiDegradedProps,
|
|
10723
11438
|
scanConfigs,
|
|
10724
11439
|
scanDependencies,
|
|
10725
11440
|
scanEntropy,
|
|
10726
11441
|
scanMultiFile,
|
|
10727
11442
|
scanQuality,
|
|
11443
|
+
scanTokenNullProps,
|
|
10728
11444
|
sqlInjection,
|
|
10729
11445
|
stripeWebhookUnprotected,
|
|
10730
11446
|
supabaseFunctionName,
|
|
10731
11447
|
supabaseNoRLS,
|
|
11448
|
+
toAiDegraded,
|
|
10732
11449
|
todoLeftInCode,
|
|
10733
11450
|
tryParse,
|
|
11451
|
+
unknownAiStatus,
|
|
10734
11452
|
unmeasuredQualityRules,
|
|
10735
11453
|
unvalidatedRedirect,
|
|
11454
|
+
vc001TestFixtureSeverity,
|
|
10736
11455
|
vendoredReason,
|
|
10737
11456
|
visitBinary,
|
|
10738
11457
|
visitCalls,
|