xploitscan-shared-rules 2.4.18 → 2.4.20

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SCANNER_VERSION = "2.4.18";
2
+ var SCANNER_VERSION = "2.4.20";
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. The floor check reads the FIRST quoted value on the
2171
- // line, which in `a = "x"; key = "sk-proj-…"` is not the token, so it
2172
- // must not run for them. ([4] was 40, which the regex's minimum of 48
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
- matches.push(textHasLiveCredential(token) ? { ...rm, severity: "high", live: true } : { ...rm, severity: "high" });
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
- matches.push({ ...rm, severity: "high" });
2230
- noteHardcodedSecret(secretText[ri] ?? "");
2554
+ emit(rm, secretText[ri] ?? token, { severity: "high" });
2231
2555
  continue;
2232
2556
  }
2233
2557
  if (textHasLiveCredential(token)) {
2234
- matches.push({ ...rm, live: true });
2235
- noteHardcodedSecret(secretText[ri] ?? "");
2558
+ emit(rm, secretText[ri] ?? token, { live: true });
2236
2559
  continue;
2237
2560
  }
2238
2561
  }
2239
- if (floor > 0) {
2240
- const secretMatch = lineText.match(/[:=]\s*["'`]([^"'`]*)["'`]/);
2241
- if (secretMatch && secretMatch[1].length < floor) continue;
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 valMatch = lineText.match(/[:=]\s*["'`]([^"'`]+)["'`]/);
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 (valMatch && nameMatch) {
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
- matches.push(isLoopbackDevDefault(url) ? { ...rm, severity: "low" } : textHasLiveCredential(url) ? { ...rm, live: true } : rm);
2257
- noteHardcodedSecret(secretText[ri] ?? "");
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
- matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
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.includes("test")) return [];
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.includes("test") || filePath.endsWith(".example") || filePath.includes("node_modules")) return [];
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 (filePath.includes("test") || filePath.includes("mock")) return [];
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
- ...onTestPath && !live ? { testFile: true } : {},
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,
@@ -5093,7 +5420,219 @@ var HASH_LIKE_VAR_NAMES = /(?:^|[^a-z])(?:hash|digest|checksum|fingerprint|etag|
5093
5420
  var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
5094
5421
  var VERIFICATION_BLOCK_RE = /\bverification\s*:\s*\{/;
5095
5422
  var VERIFICATION_KEY_NAMES = /^(?:google|yandex|yahoo|bing|me|other|["']?(?:google-site-verification|facebook-domain-verification|msvalidate\.01|norton-safeweb-site-verification|ahrefs-site-verification|p:domain_verify|wot-verification)["']?)$/i;
5096
- var VERIFICATION_META_RE = /<meta[^>]+name\s*=\s*["'][^"']*(?:site-verification|domain-verification|msvalidate|domain_verify)[^"']*["']/i;
5423
+ function isWsCode(code) {
5424
+ if (code <= 32) return code === 9 || code === 10 || code === 11 || code === 12 || code === 13 || code === 32;
5425
+ if (code < 160) return false;
5426
+ if (code === 160 || code === 5760 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288 || code === 65279) return true;
5427
+ return code >= 8192 && code <= 8202;
5428
+ }
5429
+ function isWordCode(code) {
5430
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 95;
5431
+ }
5432
+ function isWs(c) {
5433
+ return c !== void 0 && isWsCode(c.charCodeAt(0));
5434
+ }
5435
+ function isLineTerminator2(c) {
5436
+ return c === "\n" || c === "\r" || c === "\u2028" || c === "\u2029";
5437
+ }
5438
+ function isAsciiLetter(c) {
5439
+ if (c === void 0) return false;
5440
+ const a = c.charCodeAt(0);
5441
+ return a >= 65 && a <= 90 || a >= 97 && a <= 122;
5442
+ }
5443
+ function isKeyChar(c) {
5444
+ if (c === void 0) return false;
5445
+ const a = c.charCodeAt(0);
5446
+ return a >= 48 && a <= 57 || a >= 65 && a <= 90 || a >= 97 && a <= 122 || a === 95 || a === 46 || a === 45;
5447
+ }
5448
+ function ciAt(line, p, word) {
5449
+ if (p < 0 || p + word.length > line.length) return false;
5450
+ for (let k = 0; k < word.length; k++) {
5451
+ const a = line.charCodeAt(p + k);
5452
+ const b = word.charCodeAt(k);
5453
+ if (a !== b && !(a >= 65 && a <= 90 && a + 32 === b)) return false;
5454
+ }
5455
+ return true;
5456
+ }
5457
+ function matchConfigAssign(line) {
5458
+ const n = line.length;
5459
+ let i = 0;
5460
+ while (i < n && isWs(line[i])) i++;
5461
+ if (!isAsciiLetter(line[i])) return null;
5462
+ const keyStart = i;
5463
+ i++;
5464
+ let extra = 0;
5465
+ while (i < n && extra < 120 && isKeyChar(line[i])) {
5466
+ i++;
5467
+ extra++;
5468
+ }
5469
+ if (extra < 1) return null;
5470
+ if (isKeyChar(line[i])) return null;
5471
+ while (i < n && isWs(line[i])) i++;
5472
+ if (line[i] !== ":" && line[i] !== "=") return null;
5473
+ const valueFrom = i + 1;
5474
+ let j = valueFrom;
5475
+ while (j < n && isWs(line[j])) j++;
5476
+ let end = n;
5477
+ while (end > j && isWs(line[end - 1])) end--;
5478
+ let vs;
5479
+ let ve;
5480
+ if (end > j) {
5481
+ for (let k = j; k < end; k++) if (isLineTerminator2(line[k])) return null;
5482
+ vs = j;
5483
+ ve = end;
5484
+ } else {
5485
+ let k = n - 1;
5486
+ while (k >= valueFrom && isLineTerminator2(line[k])) k--;
5487
+ if (k < valueFrom) return null;
5488
+ vs = k;
5489
+ ve = k + 1;
5490
+ }
5491
+ const out = [line, line.slice(keyStart, keyStart + 1 + extra), line.slice(vs, ve)];
5492
+ out.index = 0;
5493
+ return out;
5494
+ }
5495
+ function isQuote(c) {
5496
+ return c === '"' || c === "'";
5497
+ }
5498
+ function eqQuote(line, p) {
5499
+ const n = line.length;
5500
+ while (p < n && isWs(line[p])) p++;
5501
+ if (line[p] !== "=") return -1;
5502
+ p++;
5503
+ while (p < n && isWs(line[p])) p++;
5504
+ if (!isQuote(line[p])) return -1;
5505
+ return p + 1;
5506
+ }
5507
+ function litAt(line, p, min, max) {
5508
+ let k = p;
5509
+ const lim = Math.min(line.length, p + max + 1);
5510
+ while (k < lim && !isQuote(line[k])) k++;
5511
+ if (k >= line.length || !isQuote(line[k])) return -1;
5512
+ const len = k - p;
5513
+ if (len < min || len > max) return -1;
5514
+ return k;
5515
+ }
5516
+ function rightmostIn(arr, lo, hi) {
5517
+ let a = 0;
5518
+ let b = arr.length - 1;
5519
+ let best = null;
5520
+ while (a <= b) {
5521
+ const mid = a + b >> 1;
5522
+ if (arr[mid][0] <= hi) {
5523
+ if (arr[mid][0] >= lo) best = arr[mid];
5524
+ a = mid + 1;
5525
+ } else b = mid - 1;
5526
+ }
5527
+ return best;
5528
+ }
5529
+ function gtOffsets(line) {
5530
+ const out = [];
5531
+ let from = 0;
5532
+ while (from < line.length) {
5533
+ const g = line.indexOf(">", from);
5534
+ if (g < 0) break;
5535
+ out.push(g);
5536
+ from = g + 1;
5537
+ }
5538
+ return out;
5539
+ }
5540
+ function firstGtAt(offsets, lineLength, from) {
5541
+ let lo = 0;
5542
+ let hi = offsets.length;
5543
+ while (lo < hi) {
5544
+ const mid = lo + hi >> 1;
5545
+ if (offsets[mid] < from) lo = mid + 1;
5546
+ else hi = mid;
5547
+ }
5548
+ return lo < offsets.length ? offsets[lo] : lineLength;
5549
+ }
5550
+ function attrStart(kind, code) {
5551
+ if (kind === "key") return code === 75 || code === 107 || code === 78 || code === 110;
5552
+ return code === 86 || code === 118;
5553
+ }
5554
+ function matchInto(line, p, kind, buf) {
5555
+ if (p > 0 && isWordCode(line.charCodeAt(p - 1))) return false;
5556
+ let w = 0;
5557
+ if (kind === "key") {
5558
+ w = ciAt(line, p, "key") ? 3 : ciAt(line, p, "name") ? 4 : 0;
5559
+ } else if (ciAt(line, p, "value")) {
5560
+ w = 5;
5561
+ }
5562
+ if (!w) return false;
5563
+ const q = eqQuote(line, p + w);
5564
+ if (q < 0) return false;
5565
+ const e = litAt(line, q, kind === "key" ? 1 : 20, kind === "key" ? Number.POSITIVE_INFINITY : 256);
5566
+ if (e < 0) return false;
5567
+ buf[0] = p;
5568
+ buf[1] = q;
5569
+ buf[2] = e;
5570
+ buf[3] = e + 1;
5571
+ return true;
5572
+ }
5573
+ function collectAttr(line, kind) {
5574
+ const buf = [0, 0, 0, 0];
5575
+ const out = [];
5576
+ for (let p = 0; p < line.length; p++) {
5577
+ if (!attrStart(kind, line.charCodeAt(p))) continue;
5578
+ if (!matchInto(line, p, kind, buf)) continue;
5579
+ out.push([buf[0], buf[1], buf[2], buf[3]]);
5580
+ }
5581
+ return out;
5582
+ }
5583
+ function pairScan(line, first, second) {
5584
+ const seconds = collectAttr(line, second);
5585
+ if (seconds.length === 0) return null;
5586
+ const gts = gtOffsets(line);
5587
+ const buf = [0, 0, 0, 0];
5588
+ const n = line.length;
5589
+ for (let p = 0; p < n; p++) {
5590
+ if (!attrStart(first, line.charCodeAt(p))) continue;
5591
+ if (!matchInto(line, p, first, buf)) continue;
5592
+ const s2 = rightmostIn(seconds, buf[3], firstGtAt(gts, n, buf[3]));
5593
+ if (!s2) continue;
5594
+ const out = [line.slice(buf[0], s2[3]), line.slice(buf[1], buf[2]), line.slice(s2[1], s2[2])];
5595
+ out.index = buf[0];
5596
+ return out;
5597
+ }
5598
+ return null;
5599
+ }
5600
+ function matchXmlAttr(line) {
5601
+ return pairScan(line, "key", "value");
5602
+ }
5603
+ function matchXmlElement(line) {
5604
+ return pairScan(line, "value", "key");
5605
+ }
5606
+ var VERIFICATION_META_KEYWORDS = ["site-verification", "domain-verification", "msvalidate", "domain_verify"];
5607
+ function ciIncludes(hay, word) {
5608
+ for (let p = 0; p + word.length <= hay.length; p++) if (ciAt(hay, p, word)) return true;
5609
+ return false;
5610
+ }
5611
+ function matchVerificationMeta(line) {
5612
+ const good = [];
5613
+ for (let p = 0; p < line.length; p++) {
5614
+ if (!ciAt(line, p, "name")) continue;
5615
+ const q = eqQuote(line, p + 4);
5616
+ if (q < 0) continue;
5617
+ const e = litAt(line, q, 0, Number.POSITIVE_INFINITY);
5618
+ if (e < 0) continue;
5619
+ const lit = line.slice(q, e);
5620
+ if (VERIFICATION_META_KEYWORDS.some((w) => ciIncludes(lit, w))) good.push([p]);
5621
+ }
5622
+ if (good.length === 0) return false;
5623
+ const gts = gtOffsets(line);
5624
+ for (let s = 0; s < line.length; s++) {
5625
+ if (!ciAt(line, s, "<meta")) continue;
5626
+ if (rightmostIn(good, s + 6, firstGtAt(gts, line.length, s + 5))) return true;
5627
+ }
5628
+ return false;
5629
+ }
5630
+ var entropyLineMatchers = {
5631
+ configAssign: matchConfigAssign,
5632
+ xmlAttr: matchXmlAttr,
5633
+ xmlElement: matchXmlElement,
5634
+ verificationMeta: matchVerificationMeta
5635
+ };
5097
5636
  var SECRET_VAR_NAMES = /(?:^|[^a-z])(?:key|secret|token|password|passwd|pwd|api[_-]?key|auth|credential|private|signing|bearer|access[_-]?token|refresh[_-]?token|session[_-]?id)(?:$|[^a-z])/i;
5098
5637
  var CAMEL_SECRET_VAR_NAMES = /(?:Key|Secret|Token|Password|Passwd|Credential|Private|Signing|Bearer|Auth)$/;
5099
5638
  var HUMAN_READABLE_ENV_REFERENCE_RE = /^(?:[a-z][a-z'-]*\s+){1,6}[A-Z][A-Z0-9_]{2,}$/;
@@ -5184,7 +5723,7 @@ function scanEntropyFiles(files, collect) {
5184
5723
  }
5185
5724
  } else {
5186
5725
  if (KEY_VALUE_CONFIG_RE.test(filePath)) {
5187
- const configAssign = /^\s*([A-Za-z][\w.-]{1,120})\s*[:=]\s*(.+?)\s*$/.exec(line);
5726
+ const configAssign = entropyLineMatchers.configAssign(line);
5188
5727
  if (configAssign && isSecretVariableName(configAssign[1])) {
5189
5728
  const value = dotenvValue(configAssign[2]);
5190
5729
  if (value.length >= 20 && value.length <= MAX_DOTENV_VALUE) {
@@ -5197,7 +5736,7 @@ function scanEntropyFiles(files, collect) {
5197
5736
  }
5198
5737
  }
5199
5738
  if (XML_CONFIG_RE.test(filePath)) {
5200
- const xmlPair = /\b(?:key|name)\s*=\s*["']([^"']+)["'][^>]*\bvalue\s*=\s*["']([^"']{20,256})["']/i.exec(line) || /\bvalue\s*=\s*["']([^"']{20,256})["'][^>]*\b(?:key|name)\s*=\s*["']([^"']+)["']/i.exec(line);
5739
+ const xmlPair = entropyLineMatchers.xmlAttr(line) || entropyLineMatchers.xmlElement(line);
5201
5740
  if (xmlPair) {
5202
5741
  const valueFirst = /^\s*<[^>]*\bvalue\s*=/i.test(line);
5203
5742
  const variableName = valueFirst ? xmlPair[2] : xmlPair[1];
@@ -5289,7 +5828,7 @@ function scanEntropyFiles(files, collect) {
5289
5828
  continue;
5290
5829
  }
5291
5830
  if (inVerificationBlock && VERIFICATION_KEY_NAMES.test(varName)) continue;
5292
- if (verificationMeta === void 0) verificationMeta = VERIFICATION_META_RE.test(line);
5831
+ if (verificationMeta === void 0) verificationMeta = entropyLineMatchers.verificationMeta(line);
5293
5832
  if (verificationMeta) continue;
5294
5833
  if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
5295
5834
  if (JWT_RE.test(value) && !isSecretVariableName(varName)) continue;
@@ -7869,10 +8408,10 @@ var READ_VERB = /\b(?:select|from|find\w*|query|scan|rows|fetchAll|getAll|list)\
7869
8408
  function repoReselects(files, originPath, originIndex, table, value) {
7870
8409
  const tableToken = table.replace(/["'`]/g, "");
7871
8410
  if (tableToken.length < 3) return false;
7872
- const valueToken = normValue(value);
7873
- if (!valueToken || valueToken.length < 2) return false;
8411
+ const valueToken2 = normValue(value);
8412
+ if (!valueToken2 || valueToken2.length < 2) return false;
7874
8413
  const tableRe = new RegExp(`\\b${escapeRe(tableToken)}s?\\b`, "gi");
7875
- const valueRe = new RegExp(`\\b${escapeRe(valueToken)}\\b`, "i");
8414
+ const valueRe = new RegExp(`\\b${escapeRe(valueToken2)}\\b`, "i");
7876
8415
  for (const f of files) {
7877
8416
  if (f.excluded) continue;
7878
8417
  for (const m of f.code.matchAll(tableRe)) {
@@ -10521,6 +11060,7 @@ export {
10521
11060
  tryParse,
10522
11061
  unmeasuredQualityRules,
10523
11062
  unvalidatedRedirect,
11063
+ vc001TestFixtureSeverity,
10524
11064
  vendoredReason,
10525
11065
  visitBinary,
10526
11066
  visitCalls,