@profullstack/threatcrush 0.12.6 → 0.12.8

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
@@ -17736,6 +17736,7 @@ var GENERIC_GUARD = (
17736
17736
  );
17737
17737
  var XXE_GUARD = /FEATURE_SECURE_PROCESSING|setExpandEntityReferences|disallow-doctype-decl|external-general-entities|external-parameter-entities|setXIncludeAware\s*\(\s*false/;
17738
17738
  var XML_PARSING_FILE = /\b(?:javax\.xml|org\.xml\.sax|org\.w3c\.dom|org\.jdom2?|org\.dom4j|XmlPullParser|DocumentBuilderFactory|DocumentBuilder|SAXParserFactory|SAXParser|XMLInputFactory|XMLReaderFactory|XMLReader|SAXBuilder|SAXReader)\b/;
17739
+ var PY_XPATH_FILE = /\b(?:lxml|xml\.etree|ElementTree|etree|defusedxml|xpath)\b/i;
17739
17740
  var CODE_SINK = /\bglobalThis\s*\[|\bconstructor\b|\beval\b|\bFunction\b|\brun\s*\(|\bvm\s*\.\s*run/;
17740
17741
  var EXFIL_SINK = /\bconsole\s*\.\s*(?:log|debug|info|warn|error)\s*\(|\bfetch\s*\(|\baxios\b|\brequest\s*\(|\.\s*send\s*\(/;
17741
17742
  var SQL_KEYWORDS = "SELECT\\b(?=[^`'\"\\n]*\\bFROM\\b)|INSERT\\s+INTO|UPDATE\\b(?=[^`'\"\\n]*\\bSET\\b)|DELETE\\s+FROM|DROP\\s+(?:TABLE|DATABASE|INDEX|VIEW|SCHEMA)|TRUNCATE\\s+TABLE|UNION\\s+SELECT";
@@ -18031,7 +18032,8 @@ var CODE_RULES = [
18031
18032
  severity: "high",
18032
18033
  languages: ["python"],
18033
18034
  pattern: /\brequests\.(?:get|request|head)\s*\(\s*[a-zA-Z_]\w*\s*[,)]|\burlopen\s*\(\s*[a-zA-Z_]\w*\s*[,)]|\bhttpx\.get\s*\(\s*[a-zA-Z_]\w*\s*[,)]/,
18034
- needsContext: true
18035
+ needsContext: true,
18036
+ constantRequestHostGuard: true
18035
18037
  },
18036
18038
  {
18037
18039
  id: "go-ssrf-outbound-request",
@@ -18696,8 +18698,11 @@ var CODE_RULES = [
18696
18698
  severity: "high",
18697
18699
  languages: ["python"],
18698
18700
  // Per-quote, so an inner `'` in a `"`-delimited f-string (`text()='{x}'`)
18699
- // does not truncate the match before the interpolation.
18700
- pattern: /\bf"[^"\n]*(?:\/\/|\/\w+\[)[^"\n]*\{[^}\n]+\}|\bf'[^'\n]*(?:\/\/|\/\w+\[)[^'\n]*\{[^}\n]+\}/
18701
+ // does not truncate the match before the interpolation. `(?<!:)` keeps the
18702
+ // `//` of a URL scheme out of it: `f"https://{host}/v1"` is a URL, not a
18703
+ // descendant-or-self step, and it was by far the commonest match here.
18704
+ pattern: /\bf"[^"\n]*(?:(?<!:)\/\/|\/\w+\[)[^"\n]*\{[^}\n]+\}|\bf'[^'\n]*(?:(?<!:)\/\/|\/\w+\[)[^'\n]*\{[^}\n]+\}/,
18705
+ fileRequires: PY_XPATH_FILE
18701
18706
  },
18702
18707
  {
18703
18708
  id: "py-fast-password-hash",
@@ -18943,6 +18948,21 @@ function identifierAfter(text, start) {
18943
18948
  while (isIdentifierPart(text[index])) index += 1;
18944
18949
  return text.slice(from, index);
18945
18950
  }
18951
+ function urlAuthority(text) {
18952
+ const found = /['"]\s*https?:\/\/([^'"/?#\s]*)/.exec(text);
18953
+ return found ? found[1] : null;
18954
+ }
18955
+ function requestHostIsConstant(line, fileText) {
18956
+ const call = /(?:urlopen|requests\.(?:get|request|head)|httpx\.get)\s*\(\s*([A-Za-z_]\w*)\s*[,)]/.exec(line);
18957
+ if (!call) return false;
18958
+ const assignment = new RegExp(String.raw`^[ \t]*${call[1]}[ \t]*=[ \t]*(.+)$`, "gm");
18959
+ const values = [...fileText.matchAll(assignment)].map((m) => m[1]);
18960
+ if (!values.length) return false;
18961
+ return values.every((value) => {
18962
+ const authority = urlAuthority(value);
18963
+ return authority !== null && /^[A-Za-z0-9.-]+(?::\d+)?$/.test(authority);
18964
+ });
18965
+ }
18946
18966
  function hasSafeRedirectValue(line, fileText) {
18947
18967
  const location = line.indexOf("window.location");
18948
18968
  const redirect = line.indexOf(".redirect");
@@ -19052,6 +19072,9 @@ function evaluateRule(rule, ctx) {
19052
19072
  if (rule.safeRedirectGuard && hasSafeRedirectValue(line, fileTextOf(ctx.lines))) {
19053
19073
  return null;
19054
19074
  }
19075
+ if (rule.constantRequestHostGuard && requestHostIsConstant(line, fileTextOf(ctx.lines))) {
19076
+ return null;
19077
+ }
19055
19078
  if (rule.filledBeforeUseGuard && bufferFilledBeforeUse(ctx)) return null;
19056
19079
  const guard = rule.guard === void 0 ? GENERIC_GUARD : rule.guard;
19057
19080
  if (guard && (guard.test(line) || guard.test(context))) return null;
@@ -19677,7 +19700,7 @@ var SECRET_RULES = [
19677
19700
  keywordShaped: true
19678
19701
  }
19679
19702
  ];
19680
- var INTERPOLATION = String.raw`(?:\{\{[^}]*\}\}|\$\{[^}]*\}|\$[A-Za-z_]\w*|%[sdv])`;
19703
+ var INTERPOLATION = String.raw`(?:\{\{[^}]*\}\}|\$\{[^}]*\}|\$[A-Za-z_]\w*|%[sdv]|\{[^{}\s'"@/]+\}|<[A-Za-z_][\w.-]*>)`;
19681
19704
  var KNOWN_PLACEHOLDERS = [
19682
19705
  // Deliberately NOT here: AWS's published documentation key/secret pair
19683
19706
  // (`AKIAIOSFODNN7EXAMPLE`, `wJalrXUtnFEMI/…`). GitHub allow-lists them, and
@@ -21670,14 +21693,12 @@ async function statusCommand() {
21670
21693
  const pid = findRunningDaemon();
21671
21694
  const client = new IpcClient();
21672
21695
  let live = null;
21673
- if (pid) {
21674
- try {
21675
- await client.connect();
21676
- live = await client.status();
21677
- } catch {
21678
- } finally {
21679
- client.close();
21680
- }
21696
+ try {
21697
+ await client.connect();
21698
+ live = await client.status();
21699
+ } catch {
21700
+ } finally {
21701
+ client.close();
21681
21702
  }
21682
21703
  console.log(source_default.green.bold(" Daemon Status"));
21683
21704
  console.log(source_default.gray(" " + "\u2500".repeat(60)));
@@ -27453,18 +27474,26 @@ async function allowlistCommand(opts) {
27453
27474
  const action = opts.action || "list";
27454
27475
  console.log(source_default.green.bold(" Allowlist (never banned)"));
27455
27476
  console.log(source_default.gray(" " + "\u2500".repeat(50)));
27477
+ const client = await connect();
27478
+ if (!client) return;
27479
+ let configPath = PATHS.configFile;
27480
+ let mode = null;
27481
+ try {
27482
+ const status = await client.status();
27483
+ configPath = status.paths.config;
27484
+ mode = status.mode;
27485
+ } catch {
27486
+ }
27456
27487
  if (action === "list" || action === "ls") {
27457
- const client = await connect();
27458
- if (!client) return;
27459
27488
  try {
27460
27489
  const reply = await client.blocklist();
27461
27490
  for (const entry of reply.protected) {
27462
27491
  console.log(` ${source_default.green("\u26CA")} ${source_default.white(entry)}`);
27463
27492
  }
27464
27493
  console.log();
27465
- console.log(source_default.gray(" Loopback, private ranges, the default gateway and the SSH client"));
27466
- console.log(source_default.gray(" that started the daemon are always protected. Add more under"));
27467
- console.log(source_default.gray(` [remediation] protected = [...] in ${PATHS.configFile}`));
27494
+ console.log(source_default.gray(" Loopback, private ranges, the default gateway and every live SSH"));
27495
+ console.log(source_default.gray(" peer are always protected. Add more under"));
27496
+ console.log(source_default.gray(` [remediation] protected = [...] in ${configPath}`));
27468
27497
  } catch (err) {
27469
27498
  console.log(` ${source_default.red("\u2717")} ${err.message}`);
27470
27499
  } finally {
@@ -27473,12 +27502,15 @@ async function allowlistCommand(opts) {
27473
27502
  }
27474
27503
  return;
27475
27504
  }
27476
- console.log(source_default.gray(` Edit ${PATHS.configFile}:`));
27505
+ client.close();
27506
+ console.log(source_default.gray(` Edit ${configPath}:`));
27477
27507
  console.log();
27478
27508
  console.log(source_default.gray(" [remediation]"));
27479
27509
  console.log(source_default.gray(` protected = ["${opts.value || "203.0.113.7/32"}"]`));
27480
27510
  console.log();
27481
- console.log(source_default.gray(" then: threatcrush restart"));
27511
+ console.log(source_default.gray(
27512
+ mode === "system" ? " then: sudo systemctl restart threatcrushd" : " then: threatcrush restart"
27513
+ ));
27482
27514
  console.log();
27483
27515
  }
27484
27516