@profullstack/threatcrush 0.13.43 → 0.13.45

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
@@ -31117,6 +31117,11 @@ var DEFAULT_EXCLUDED_RULE_IDS = [941130];
31117
31117
  var ARGUMENT_EXCLUSIONS = [
31118
31118
  { ruleIds: [942100], path: /^\/rest\/v1\//, arg: "select", value: /^[A-Za-z0-9_*,.:!()>-]+$/ }
31119
31119
  ];
31120
+ var COMMAND_WORD_RULE_IDS = /* @__PURE__ */ new Set([932260, 932340, 932370, 932380]);
31121
+ var PLAIN_WORDS = /^[\p{L}\p{N}][\p{L}\p{N} .,_+/-]*(?: & [\p{L}\p{N}][\p{L}\p{N} .,_+/-]*)*$/u;
31122
+ function isPlainWords(value) {
31123
+ return value.length <= 200 && PLAIN_WORDS.test(value);
31124
+ }
31120
31125
  var ATTACK_TYPES = {
31121
31126
  "attack-sqli": "sqli",
31122
31127
  "attack-xss": "xss",
@@ -31269,6 +31274,7 @@ var RequestContext = class {
31269
31274
  const exclusions = ARGUMENT_EXCLUSIONS.filter((e) => e.path.test(path));
31270
31275
  return parseArguments(query).map(({ name, value }) => {
31271
31276
  const ids = exclusions.filter((e) => e.arg === name && e.value.test(value)).flatMap((e) => e.ruleIds);
31277
+ if (isPlainWords(value)) ids.push(...COMMAND_WORD_RULE_IDS);
31272
31278
  return { value, cache: /* @__PURE__ */ new Map(), ...ids.length ? { excluded: new Set(ids) } : {} };
31273
31279
  });
31274
31280
  }
@@ -40723,6 +40729,38 @@ var DEFAULT_PROTECTED = [
40723
40729
  "fc00::/7",
40724
40730
  "fe80::/10"
40725
40731
  ];
40732
+ var SHARED_INFRASTRUCTURE = [
40733
+ "173.245.48.0/20",
40734
+ "103.21.244.0/22",
40735
+ "103.22.200.0/22",
40736
+ "103.31.4.0/22",
40737
+ "141.101.64.0/18",
40738
+ "108.162.192.0/18",
40739
+ "190.93.240.0/20",
40740
+ "188.114.96.0/20",
40741
+ "197.234.240.0/22",
40742
+ "198.41.128.0/17",
40743
+ "162.158.0.0/15",
40744
+ "104.16.0.0/13",
40745
+ "104.24.0.0/14",
40746
+ "172.64.0.0/13",
40747
+ "131.0.72.0/22",
40748
+ "2400:cb00::/32",
40749
+ "2606:4700::/32",
40750
+ "2803:f800::/32",
40751
+ "2405:b500::/32",
40752
+ "2405:8100::/32",
40753
+ "2a06:98c0::/29",
40754
+ "2c0f:f248::/32",
40755
+ "1.1.1.1/32",
40756
+ "1.0.0.1/32",
40757
+ "8.8.8.8/32",
40758
+ "8.8.4.4/32",
40759
+ "9.9.9.9/32",
40760
+ "149.112.112.112/32",
40761
+ "208.67.222.222/32",
40762
+ "208.67.220.220/32"
40763
+ ];
40726
40764
  function ipToBytes(ip) {
40727
40765
  const version = (0, import_node_net4.isIP)(ip);
40728
40766
  if (version === 4) return v4ToBytes(ip);
@@ -42484,6 +42522,17 @@ var NEVER_REPORT_RANGES = [
42484
42522
  ];
42485
42523
  var CONNECTION_VERIFIED_CATEGORIES = /* @__PURE__ */ new Set(["auth", "web", "pentest"]);
42486
42524
  var CONNECTION_VERIFIED_MODULES = ["honeypot", "honey-pot", "webhoneypot"];
42525
+ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
42526
+ function formSpamIdentity(event) {
42527
+ const raw = event.details?.form_spam;
42528
+ if (!raw || typeof raw !== "object") return void 0;
42529
+ const { username, email } = raw;
42530
+ if (typeof username !== "string" || typeof email !== "string") return void 0;
42531
+ const u = username.trim();
42532
+ const e = email.trim();
42533
+ if (!u || u.length > 255 || !EMAIL_RE.test(e) || e.length > 254) return void 0;
42534
+ return { username: u, email: e };
42535
+ }
42487
42536
  function summarizeEvidence(events) {
42488
42537
  const modules = /* @__PURE__ */ new Set();
42489
42538
  const categories = /* @__PURE__ */ new Set();
@@ -42492,9 +42541,12 @@ function summarizeEvidence(events) {
42492
42541
  let firstSeen = Infinity;
42493
42542
  let lastSeen = 0;
42494
42543
  let total = 0;
42544
+ let formSpam;
42495
42545
  for (const event of events) {
42496
42546
  if (event.module === "firewall-rules") continue;
42497
42547
  total++;
42548
+ const identity = formSpamIdentity(event);
42549
+ if (identity && event.timestamp.getTime() >= lastSeen) formSpam = identity;
42498
42550
  modules.add(event.module);
42499
42551
  categories.add(event.category);
42500
42552
  const ruleId = event.details?.rule_id;
@@ -42513,7 +42565,8 @@ function summarizeEvidence(events) {
42513
42565
  lastSeen,
42514
42566
  total,
42515
42567
  categories: [...categories],
42516
- ruleIds: [...ruleIds]
42568
+ ruleIds: [...ruleIds],
42569
+ ...formSpam ? { formSpam } : {}
42517
42570
  };
42518
42571
  }
42519
42572
  function isReportable(ip, evidence, config, now = Date.now()) {
@@ -42608,22 +42661,28 @@ async function reportToAbuseIPDB(payload, apiKey) {
42608
42661
  }
42609
42662
  }
42610
42663
  async function reportToStopForumSpam(payload, apiKey) {
42664
+ const identity = payload.evidence.formSpam;
42665
+ if (!identity) {
42666
+ return { destination: "stopforumspam", ok: false, detail: "skipped: no form-spam username/email in evidence" };
42667
+ }
42611
42668
  const body = new URLSearchParams({
42612
- api_key: apiKey,
42613
- ip: payload.ip,
42614
- evidence: payload.comment.slice(0, 1e3)
42669
+ username: identity.username,
42670
+ email: identity.email,
42671
+ ip_addr: payload.ip,
42672
+ evidence: payload.comment.slice(0, 1e3),
42673
+ api_key: apiKey
42615
42674
  });
42616
42675
  try {
42617
- const res = await fetch("https://www.stopforumspam.org/add.php", {
42676
+ const res = await fetch("https://www.stopforumspam.com/add.php", {
42618
42677
  method: "POST",
42619
- headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
42678
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
42620
42679
  body,
42621
42680
  signal: AbortSignal.timeout(TIMEOUT_MS)
42622
42681
  });
42623
42682
  const text = await res.text().catch(() => "");
42624
- if (!res.ok) return { destination: "stopforumspam", ok: false, detail: `HTTP ${res.status} ${text.slice(0, 120)}` };
42625
- const ok = /success|"success"\s*:\s*true/i.test(text);
42626
- return { destination: "stopforumspam", ok, detail: ok ? "reported" : text.slice(0, 120) || "refused" };
42683
+ if (res.status === 200) return { destination: "stopforumspam", ok: true, detail: "reported" };
42684
+ const reason = /<p[^>]*>([\s\S]*?)<\/p>/i.exec(text)?.[1]?.replace(/<[^>]+>/g, "").trim();
42685
+ return { destination: "stopforumspam", ok: false, detail: `HTTP ${res.status} ${(reason || text).slice(0, 160)}`.trim() };
42627
42686
  } catch (err) {
42628
42687
  return { destination: "stopforumspam", ok: false, detail: err.message };
42629
42688
  }
@@ -42632,7 +42691,7 @@ async function dispatch(payload, destinations, keys) {
42632
42691
  const jobs = [];
42633
42692
  for (const dest of destinations) {
42634
42693
  if (dest === "abuseipdb" && keys.abuseipdb) jobs.push(reportToAbuseIPDB(payload, keys.abuseipdb));
42635
- else if (dest === "stopforumspam" && keys.stopforumspam) jobs.push(reportToStopForumSpam(payload, keys.stopforumspam));
42694
+ else if (dest === "stopforumspam" && keys.stopforumspam && payload.evidence.formSpam) jobs.push(reportToStopForumSpam(payload, keys.stopforumspam));
42636
42695
  }
42637
42696
  return Promise.all(jobs);
42638
42697
  }
@@ -42758,7 +42817,7 @@ var AbuseReporter = class {
42758
42817
  }
42759
42818
  if (!this.active) {
42760
42819
  this.opts.log(
42761
- "[abuse] reporter on but inert: no destination API key set (ABUSEIPDB_API_KEY or [abuse-reporter] abuseipdb_api_key). Nothing will be reported."
42820
+ "[abuse] reporter on but inert: no destination API key set (ABUSEIPDB_API_KEY / STOPFORUMSPAM_API_KEY or [abuse-reporter] *_api_key). Nothing will be reported."
42762
42821
  );
42763
42822
  return;
42764
42823
  }
@@ -45020,7 +45079,7 @@ var RemediationManager = class {
45020
45079
  this.discovery = discovery;
45021
45080
  this.config = { ...DEFAULT_CONFIG2, ...config };
45022
45081
  this.config.allowlist = [...this.config.allowlist];
45023
- this.protectedList = [...DEFAULT_PROTECTED, ...this.config.allowlist];
45082
+ this.protectedList = [...DEFAULT_PROTECTED, ...SHARED_INFRASTRUCTURE, ...this.config.allowlist];
45024
45083
  for (const gateway of defaultGateways()) this.protectedList.push(gateway);
45025
45084
  if (this.adapter.enforces === false) this.config.dry_run = true;
45026
45085
  this.loadState();