@profullstack/threatcrush 0.13.27 → 0.13.29

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
@@ -9097,6 +9097,9 @@ function detectXSS(bytes) {
9097
9097
  var SEVERITY_POINTS = { CRITICAL: 5, ERROR: 4, WARNING: 3, NOTICE: 2 };
9098
9098
  var DEFAULT_ANOMALY_THRESHOLD = 5;
9099
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
+ ];
9100
9103
  var ATTACK_TYPES = {
9101
9104
  "attack-sqli": "sqli",
9102
9105
  "attack-xss": "xss",
@@ -9230,18 +9233,31 @@ var RequestContext = class {
9230
9233
  values(target) {
9231
9234
  let slots = this.slots.get(target);
9232
9235
  if (!slots) {
9233
- 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() }));
9234
9237
  this.slots.set(target, slots);
9235
9238
  }
9236
9239
  return slots;
9237
9240
  }
9238
- derive(target) {
9239
- const { uri } = this.req;
9240
- 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, "");
9241
9244
  const q = relative4.search(/[?#]/);
9242
9245
  const path = q === -1 ? relative4 : relative4.slice(0, q);
9243
9246
  const hasQuery = q !== -1 && relative4[q] === "?";
9244
- 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();
9245
9261
  switch (target) {
9246
9262
  case "REQUEST_LINE":
9247
9263
  return this.req.method && this.req.protocol ? [`${this.req.method} ${uri} ${this.req.protocol}`] : [];
@@ -9393,7 +9409,9 @@ var CrsEngine = class {
9393
9409
  const hit = new Uint8Array(this.rules.length);
9394
9410
  for (const [target, rules] of this.byTarget) {
9395
9411
  for (const slot of ctx.values(target)) {
9396
- 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
+ }
9397
9415
  }
9398
9416
  }
9399
9417
  for (const compiled of this.chained) {
@@ -12641,8 +12659,11 @@ var CODE_RULES = [
12641
12659
  // escalates when nearby evidence shows that input can choose the download.
12642
12660
  guard: false,
12643
12661
  // Installer instructions printed by the script do not execute. Matching
12644
- // them made a script report its own documentation as a network pipeline.
12645
- lineGuard: /^\s*(?:echo|printf|say|info|warn|error)\s+["'][^"'\n]*\b(?:curl|wget)\b/,
12662
+ // them made a script report its own documentation as a network pipeline,
12663
+ // including the usual `-h | --help) echo "Usage: curl … | sh"; exit ;;` case
12664
+ // branch, which a start-of-line guard missed. Only the quoted text is
12665
+ // discounted, so `echo "see docs"; curl … | sh` still reports.
12666
+ displayStringGuard: true,
12646
12667
  // The same instructions written as a `cat <<USAGE` help block.
12647
12668
  displayedHeredocGuard: true
12648
12669
  },
@@ -13352,6 +13373,13 @@ function insideDisplayedHeredoc(lines, index) {
13352
13373
  const opener = open.opener.replace(/\s[12]?>&2\b/g, " ");
13353
13374
  return /^\s*cat\b/.test(opener) && !/>/.test(opener) && !/\|/.test(opener);
13354
13375
  }
13376
+ var DISPLAY_STRING = /(\b(?:echo|printf|say|info|warn|error)\s+(?:-[A-Za-z]+\s+)*)((?:"(?:[^"\\\n]|\\.)*"|'[^'\n]*')(?:\s+(?:"(?:[^"\\\n]|\\.)*"|'[^'\n]*'))*)(?=\s*(?:$|;|&&|\|\||[12]?>&2|>\s*\/dev\/(?:stderr|tty)\b|\)|#))/g;
13377
+ function stripDisplayedStrings(line) {
13378
+ return line.replace(
13379
+ DISPLAY_STRING,
13380
+ (whole, head, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head}""`
13381
+ );
13382
+ }
13355
13383
  function evaluateRule(rule, ctx) {
13356
13384
  if (rule.languages && !rule.languages.includes(ctx.language)) return null;
13357
13385
  const line = ctx.lines[ctx.index] ?? "";
@@ -13364,6 +13392,7 @@ function evaluateRule(rule, ctx) {
13364
13392
  if (rule.requires && !rule.requires.test(context)) return null;
13365
13393
  if (rule.lineGuard?.test(line)) return null;
13366
13394
  if (rule.displayedHeredocGuard && insideDisplayedHeredoc(ctx.lines, ctx.index)) return null;
13395
+ if (rule.displayStringGuard && !rule.pattern.test(stripDisplayedStrings(line))) return null;
13367
13396
  if (rule.enclosingCallGuard) {
13368
13397
  const callees = enclosingCallees(ctx.lines, ctx.index, back);
13369
13398
  if (callees.some((callee) => rule.enclosingCallGuard.test(callee))) return null;