@profullstack/threatcrush 0.13.73 → 0.13.74

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
@@ -37589,7 +37589,8 @@ var SECRET_RULES = [
37589
37589
  pattern: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?-----/,
37590
37590
  severity: "critical",
37591
37591
  cwe: "CWE-798",
37592
- consequence: "Key material, committed. Rotation is the only remediation."
37592
+ consequence: "Key material, committed. Rotation is the only remediation.",
37593
+ confirm: (lines, index, match) => hasPemBody(lines, index, match)
37593
37594
  },
37594
37595
  {
37595
37596
  id: "secret-slack-token",
@@ -37738,6 +37739,18 @@ var KNOWN_PLACEHOLDERS = [
37738
37739
  function isKnownPlaceholder(text) {
37739
37740
  return KNOWN_PLACEHOLDERS.some((pattern) => pattern.test(text));
37740
37741
  }
37742
+ var PEM_BODY_LOOKAHEAD = 6;
37743
+ var PEM_BODY_RUN = /[A-Za-z0-9+/]{40,}/;
37744
+ var PEM_BODY_LINE = /^[\s'"`+(]*(?:\\n)?[A-Za-z0-9+/]{40,}={0,2}(?:\\n)?['"`,;+)\s]*$/;
37745
+ function hasPemBody(lines, index, match) {
37746
+ const rest = (lines[index] ?? "").slice(match.index + match[0].length).replace(/\\[nr]/g, " ");
37747
+ if (PEM_BODY_RUN.test(rest)) return true;
37748
+ const last = Math.min(lines.length - 1, index + PEM_BODY_LOOKAHEAD);
37749
+ for (let i = index + 1; i <= last; i++) {
37750
+ if (PEM_BODY_LINE.test(lines[i])) return true;
37751
+ }
37752
+ return false;
37753
+ }
37741
37754
  function isPlaceholderAttribute(line2, value) {
37742
37755
  const at = line2.lastIndexOf(value);
37743
37756
  if (at === -1) return false;
@@ -37997,14 +38010,6 @@ function isSuppressed(suppressions, index, ruleId) {
37997
38010
  if (!rules) return false;
37998
38011
  return rules.has("*") || rules.has(ruleId);
37999
38012
  }
38000
- function pemPlaceholder(lines, index) {
38001
- const first = lines[index] ?? "";
38002
- const header2 = /-----BEGIN ((?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?)-----/.exec(first);
38003
- if (!header2) return false;
38004
- const tail = [first.slice(header2.index + header2[0].length), ...lines.slice(index + 1, index + 21)].join("\n").replace(/\\n/g, "\n");
38005
- const end = tail.indexOf(`-----END ${header2[1]}-----`);
38006
- return end >= 0 && ["your-pem-body-here", "your-private-key-here", "your-private-key-body-here"].includes(tail.slice(0, end).trim().toLowerCase());
38007
- }
38008
38013
  function isTestPath(relativePath) {
38009
38014
  const p = relativePath.replace(/\\/g, "/");
38010
38015
  return /(?:^|\/)(?:tests?|__tests__|__mocks__|spec|specs|fixtures?|mocks?|e2e|testdata|testutils?|harness)\//i.test(p) || /(?:^|\/)(?:test|conftest)_[^/]+$/i.test(p) || /[._-](?:test|spec)\.[a-z]+$/i.test(p) || /_test\.[a-z]+$/i.test(p);
@@ -38192,6 +38197,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
38192
38197
  const match = rule.pattern.exec(line2);
38193
38198
  if (!match) continue;
38194
38199
  if (isKnownPlaceholder(match[0])) continue;
38200
+ if (rule.confirm && !rule.confirm(lines, index, match)) continue;
38195
38201
  if (isSuppressed(suppressions, index, rule.id)) continue;
38196
38202
  const value = match[1] ?? match[0];
38197
38203
  if (isVariableReference(value)) continue;
@@ -38200,7 +38206,9 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
38200
38206
  test: inTests,
38201
38207
  "test-block": inlineTests.has(index),
38202
38208
  suppressed: foreignSecurityMark(line2),
38203
- placeholder: isPlaceholderAttribute(line2, value) || rule.id === "secret-private-key" && pemPlaceholder(lines, index),
38209
+ // A dummy PEM body (`your-pem-body-here`) never reaches here: it is not a
38210
+ // base64 body, so `hasPemBody` already dropped it.
38211
+ placeholder: isPlaceholderAttribute(line2, value),
38204
38212
  "self-describing": rule.keywordShaped === true && describesItsOwnKey(line2, value)
38205
38213
  });
38206
38214
  findings2.push({