@profullstack/threatcrush 0.13.26 → 0.13.28

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/daemon.js CHANGED
@@ -2448,10 +2448,12 @@ var IpcServer = class {
2448
2448
  }
2449
2449
  const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
2450
2450
  if (isRoot2) {
2451
- try {
2452
- const { gid } = nodeFs.statSync("/var/log/auth.log");
2453
- nodeFs.chownSync(PATHS.socket, 0, gid);
2454
- } catch {
2451
+ const gid = admGid();
2452
+ if (gid !== null) {
2453
+ try {
2454
+ nodeFs.chownSync(PATHS.socket, 0, gid);
2455
+ } catch {
2456
+ }
2455
2457
  }
2456
2458
  }
2457
2459
  resolve3();
@@ -2656,6 +2658,20 @@ var IpcServer = class {
2656
2658
  }
2657
2659
  }
2658
2660
  };
2661
+ function admGid(readGroup = () => (0, import_node_fs4.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs4.statSync)("/var/log/auth.log")) {
2662
+ try {
2663
+ for (const line of readGroup().split("\n")) {
2664
+ const [name, , gid] = line.split(":");
2665
+ if (name === "adm" && gid !== void 0 && /^\d+$/.test(gid)) return Number(gid);
2666
+ }
2667
+ } catch {
2668
+ }
2669
+ try {
2670
+ return statAuthLog().gid;
2671
+ } catch {
2672
+ return null;
2673
+ }
2674
+ }
2659
2675
 
2660
2676
  // src/daemon/module-host.ts
2661
2677
  var import_node_fs12 = require("fs");
@@ -9081,6 +9097,9 @@ function detectXSS(bytes) {
9081
9097
  var SEVERITY_POINTS = { CRITICAL: 5, ERROR: 4, WARNING: 3, NOTICE: 2 };
9082
9098
  var DEFAULT_ANOMALY_THRESHOLD = 5;
9083
9099
  var DEFAULT_EXCLUDED_RULE_IDS = [941130];
9100
+ var ARGUMENT_EXCLUSIONS = [
9101
+ { ruleIds: [942100], path: /^\/rest\/v1\//, arg: "select", value: /^[A-Za-z0-9_*,.:!()>-]+$/ }
9102
+ ];
9084
9103
  var ATTACK_TYPES = {
9085
9104
  "attack-sqli": "sqli",
9086
9105
  "attack-xss": "xss",
@@ -9214,18 +9233,31 @@ var RequestContext = class {
9214
9233
  values(target) {
9215
9234
  let slots = this.slots.get(target);
9216
9235
  if (!slots) {
9217
- slots = this.derive(target).map((value) => ({ value, cache: /* @__PURE__ */ new Map() }));
9236
+ slots = target === "ARGS" ? this.args() : this.derive(target).map((value) => ({ value, cache: /* @__PURE__ */ new Map() }));
9218
9237
  this.slots.set(target, slots);
9219
9238
  }
9220
9239
  return slots;
9221
9240
  }
9222
- derive(target) {
9223
- const { uri } = this.req;
9224
- const relative4 = uri.replace(ABSOLUTE_FORM, "");
9241
+ /** apr_uri_parse: path up to ? or #, query up to #, authority dropped. */
9242
+ split() {
9243
+ const relative4 = this.req.uri.replace(ABSOLUTE_FORM, "");
9225
9244
  const q = relative4.search(/[?#]/);
9226
9245
  const path = q === -1 ? relative4 : relative4.slice(0, q);
9227
9246
  const hasQuery = q !== -1 && relative4[q] === "?";
9228
- const query = hasQuery ? relative4.slice(q + 1).split("#")[0] : void 0;
9247
+ return { path, query: hasQuery ? relative4.slice(q + 1).split("#")[0] : void 0 };
9248
+ }
9249
+ args() {
9250
+ const { path, query } = this.split();
9251
+ if (query === void 0) return [];
9252
+ const exclusions = ARGUMENT_EXCLUSIONS.filter((e) => e.path.test(path));
9253
+ return parseArguments(query).map(({ name, value }) => {
9254
+ const ids = exclusions.filter((e) => e.arg === name && e.value.test(value)).flatMap((e) => e.ruleIds);
9255
+ return { value, cache: /* @__PURE__ */ new Map(), ...ids.length ? { excluded: new Set(ids) } : {} };
9256
+ });
9257
+ }
9258
+ derive(target) {
9259
+ const { uri } = this.req;
9260
+ const { path, query } = this.split();
9229
9261
  switch (target) {
9230
9262
  case "REQUEST_LINE":
9231
9263
  return this.req.method && this.req.protocol ? [`${this.req.method} ${uri} ${this.req.protocol}`] : [];
@@ -9377,7 +9409,9 @@ var CrsEngine = class {
9377
9409
  const hit = new Uint8Array(this.rules.length);
9378
9410
  for (const [target, rules] of this.byTarget) {
9379
9411
  for (const slot of ctx.values(target)) {
9380
- for (const index of this.slotMatches(target, rules, slot)) hit[index] = 1;
9412
+ for (const index of this.slotMatches(target, rules, slot)) {
9413
+ if (!slot.excluded?.has(this.rules[index].rule.id)) hit[index] = 1;
9414
+ }
9381
9415
  }
9382
9416
  }
9383
9417
  for (const compiled of this.chained) {