xploitscan-shared-rules 2.4.8 → 2.4.10

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 CHANGED
@@ -66,6 +66,7 @@ __export(index_exports, {
66
66
  consoleLogProduction: () => consoleLogProduction,
67
67
  corsWildcard: () => corsWildcard,
68
68
  dangerousInnerHTML: () => dangerousInnerHTML,
69
+ deduplicateFindings: () => deduplicateFindings,
69
70
  detectBuilder: () => detectBuilder,
70
71
  detectExposedConfig: () => detectExposedConfig,
71
72
  detectFramework: () => detectFramework,
@@ -158,7 +159,7 @@ __export(index_exports, {
158
159
  module.exports = __toCommonJS(index_exports);
159
160
 
160
161
  // src/version.ts
161
- var SCANNER_VERSION = "2.4.8";
162
+ var SCANNER_VERSION = "2.4.10";
162
163
 
163
164
  // src/snippet.ts
164
165
  var cacheContent = null;
@@ -207,6 +208,28 @@ function getSnippet(content, line, contextLines = 2) {
207
208
  return out.join("\n");
208
209
  }
209
210
 
211
+ // src/dedupe.ts
212
+ function deduplicateFindings(findings) {
213
+ const seen = /* @__PURE__ */ new Set();
214
+ const unique = [];
215
+ for (const finding of findings) {
216
+ let key;
217
+ if (finding.rule === "VC001" || finding.rule === "ENTROPY") {
218
+ key = `hardcoded-secret:${finding.file}:${finding.line}`;
219
+ } else if (finding.rule === "VC014" || finding.rule === "MFA002") {
220
+ key = `env-not-ignored:${finding.file}:${finding.line}`;
221
+ } else if (finding.source === "gitleaks") {
222
+ key = `gitleaks-secret:${finding.file}:${finding.line}`;
223
+ } else {
224
+ key = `${finding.rule}:${finding.file}:${finding.line}:${finding.title}`;
225
+ }
226
+ if (seen.has(key)) continue;
227
+ seen.add(key);
228
+ unique.push(finding);
229
+ }
230
+ return unique;
231
+ }
232
+
210
233
  // src/silencing.ts
211
234
  function isInlineSilenced(content, matchIndex, ruleId) {
212
235
  const lines = content.split("\n");
@@ -2062,11 +2085,14 @@ var hardcodedSecrets = {
2062
2085
  /\b(?:password|passwd|pwd)\s*:\s*["'`]([a-zA-Z0-9_\-!@#$%^&*.\/:\-]{8,})["'`]/gi,
2063
2086
  // Private keys
2064
2087
  /-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----/g,
2065
- // Database URLs with credentials. The user and password cannot cross
2066
- // whitespace or a newline, and each is capped at 1024 characters, so
2067
- // a localhost URL cannot run forward to a later `@` and a run of
2068
- // `postgres://a:b` with no `@` cannot backtrack.
2069
- /(?:postgres|mysql|mongodb(?:\+srv)?):\/\/[^:@\s/]{1,1024}:[^@\s]{1,1024}@[^/\s"'`]{1,256}/gi,
2088
+ // Database URLs with credentials. Align with Pro VC049: `postgresql://`
2089
+ // and `postgresql+asyncpg://` (and mysql/mongodb+srv) are what providers
2090
+ // actually hand out — `postgres://` alone missed Supabase/Prisma URLs.
2091
+ // The user and password cannot cross whitespace or a newline, and each
2092
+ // is capped at 1024 characters, so a localhost URL cannot run forward
2093
+ // to a later `@` and a run of `postgres://a:b` with no `@` cannot
2094
+ // backtrack.
2095
+ /(?:postgres(?:ql)?(?:\+[a-z0-9]{1,20})?|mysql|mongodb(?:\+srv)?):\/\/[^:@\s/]{1,1024}:[^@\s]{1,1024}@[^/\s"'`]{1,256}/gi,
2070
2096
  // ── [11]–[14] Fixed-prefix AI-provider and payment keys ──
2071
2097
  // These match the token itself, so they fire whatever it is bound to:
2072
2098
  // `const k = "…"`, a positional `new OpenAI("…")`, an unquoted .env
@@ -2181,11 +2207,11 @@ var hardcodedSecrets = {
2181
2207
  }
2182
2208
  if (pi === 6) {
2183
2209
  const valMatch = lineText.match(/[:=]\s*["'`]([^"'`]+)["'`]/);
2184
- const nameMatch = lineText.match(/([A-Z][A-Z0-9_]*_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD))\b/);
2210
+ const nameMatch = (matchedText[ri] ?? "").match(/^[A-Z][A-Z0-9_]{0,64}_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD)\b/);
2185
2211
  if (valMatch && nameMatch) {
2186
2212
  const value = valMatch[1];
2187
- const isKeySuffix = nameMatch[1].endsWith("_KEY");
2188
- const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(nameMatch[1], value));
2213
+ const isKeySuffix = nameMatch[0].endsWith("_KEY");
2214
+ const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(nameMatch[0], value));
2189
2215
  if (isKeySuffix && isSlotIdentifier) continue;
2190
2216
  }
2191
2217
  }
@@ -2765,7 +2791,11 @@ var missingAuthMiddleware = {
2765
2791
  if (content[i] === "\n") lineStarts.push(i + 1);
2766
2792
  }
2767
2793
  const indexOfLine = (line) => lineStarts[Math.max(0, Math.min(line - 1, lineStarts.length - 1))];
2768
- const unauthenticated = matches.filter((m) => !handlerHasAuth(indexOfLine(m.line)));
2794
+ const isPublicRootGet = (index) => /\.\s*get\s*\(\s*["'`]\/["'`]\s*,/i.test(content.slice(index, index + 240));
2795
+ const unauthenticated = matches.filter((m) => {
2796
+ const index = indexOfLine(m.line);
2797
+ return !isPublicRootGet(index) && !handlerHasAuth(index);
2798
+ });
2769
2799
  if (serverSide || tanstackCandidate) {
2770
2800
  for (const idx of unauthenticatedTanStackHandlers(maskedForScope, filePath)) {
2771
2801
  const line = lineNumberAt(content, idx);
@@ -4687,7 +4717,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
4687
4717
  });
4688
4718
  }
4689
4719
  }
4690
- return findings;
4720
+ return deduplicateFindings(findings);
4691
4721
  }
4692
4722
 
4693
4723
  // src/rule-counts.ts
@@ -5315,7 +5345,8 @@ function scanEntropy(files) {
5315
5345
  if (value.includes("${")) continue;
5316
5346
  if (value.includes("\\(")) continue;
5317
5347
  if (value.includes("#{") || value.includes("{{")) continue;
5318
- if (SAFE_PATTERNS.some((p) => p.test(value))) continue;
5348
+ const isUuidShape = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
5349
+ if (!isUuidShape && SAFE_PATTERNS.some((p) => p.test(value))) continue;
5319
5350
  if (HASH_PREFIX_RE.test(value)) continue;
5320
5351
  if (SAFE_VAR_NAMES.test(beforeAssign)) continue;
5321
5352
  if (/^https?:\/\/[^:@]*$/.test(value)) continue;
@@ -5326,9 +5357,10 @@ function scanEntropy(files) {
5326
5357
  if (isHex) threshold = 3;
5327
5358
  else if (isBase64) threshold = 4.5;
5328
5359
  if (value.length < 20) continue;
5329
- const entropy = shannonEntropy(value);
5330
- if (entropy < threshold) continue;
5331
5360
  const varName = variableName || dotenvName || beforeAssign.match(/["']([^"']+)["']\s*$/)?.[1] || beforeAssign.match(/([\w$-]+)\s*$/)?.[1] || "";
5361
+ if (isUuidShape && !isSecretVariableName(varName)) continue;
5362
+ const entropy = shannonEntropy(value);
5363
+ if (entropy < threshold && !(isUuidShape && isSecretVariableName(varName))) continue;
5332
5364
  if (HUMAN_READABLE_ENV_REFERENCE_RE.test(value) && !isSecretVariableName(varName)) {
5333
5365
  continue;
5334
5366
  }
@@ -9865,6 +9897,7 @@ function scanQuality(input, rules = qualityRules) {
9865
9897
  consoleLogProduction,
9866
9898
  corsWildcard,
9867
9899
  dangerousInnerHTML,
9900
+ deduplicateFindings,
9868
9901
  detectBuilder,
9869
9902
  detectExposedConfig,
9870
9903
  detectFramework,