@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/index.js CHANGED
@@ -22822,6 +22822,9 @@ function detectXSS(bytes) {
22822
22822
  var SEVERITY_POINTS = { CRITICAL: 5, ERROR: 4, WARNING: 3, NOTICE: 2 };
22823
22823
  var DEFAULT_ANOMALY_THRESHOLD = 5;
22824
22824
  var DEFAULT_EXCLUDED_RULE_IDS = [941130];
22825
+ var ARGUMENT_EXCLUSIONS = [
22826
+ { ruleIds: [942100], path: /^\/rest\/v1\//, arg: "select", value: /^[A-Za-z0-9_*,.:!()>-]+$/ }
22827
+ ];
22825
22828
  var ATTACK_TYPES = {
22826
22829
  "attack-sqli": "sqli",
22827
22830
  "attack-xss": "xss",
@@ -22955,18 +22958,31 @@ var RequestContext = class {
22955
22958
  values(target) {
22956
22959
  let slots = this.slots.get(target);
22957
22960
  if (!slots) {
22958
- slots = this.derive(target).map((value) => ({ value, cache: /* @__PURE__ */ new Map() }));
22961
+ slots = target === "ARGS" ? this.args() : this.derive(target).map((value) => ({ value, cache: /* @__PURE__ */ new Map() }));
22959
22962
  this.slots.set(target, slots);
22960
22963
  }
22961
22964
  return slots;
22962
22965
  }
22963
- derive(target) {
22964
- const { uri } = this.req;
22965
- const relative4 = uri.replace(ABSOLUTE_FORM, "");
22966
+ /** apr_uri_parse: path up to ? or #, query up to #, authority dropped. */
22967
+ split() {
22968
+ const relative4 = this.req.uri.replace(ABSOLUTE_FORM, "");
22966
22969
  const q = relative4.search(/[?#]/);
22967
22970
  const path = q === -1 ? relative4 : relative4.slice(0, q);
22968
22971
  const hasQuery = q !== -1 && relative4[q] === "?";
22969
- const query = hasQuery ? relative4.slice(q + 1).split("#")[0] : void 0;
22972
+ return { path, query: hasQuery ? relative4.slice(q + 1).split("#")[0] : void 0 };
22973
+ }
22974
+ args() {
22975
+ const { path, query } = this.split();
22976
+ if (query === void 0) return [];
22977
+ const exclusions = ARGUMENT_EXCLUSIONS.filter((e) => e.path.test(path));
22978
+ return parseArguments(query).map(({ name, value }) => {
22979
+ const ids = exclusions.filter((e) => e.arg === name && e.value.test(value)).flatMap((e) => e.ruleIds);
22980
+ return { value, cache: /* @__PURE__ */ new Map(), ...ids.length ? { excluded: new Set(ids) } : {} };
22981
+ });
22982
+ }
22983
+ derive(target) {
22984
+ const { uri } = this.req;
22985
+ const { path, query } = this.split();
22970
22986
  switch (target) {
22971
22987
  case "REQUEST_LINE":
22972
22988
  return this.req.method && this.req.protocol ? [`${this.req.method} ${uri} ${this.req.protocol}`] : [];
@@ -23118,7 +23134,9 @@ var CrsEngine = class {
23118
23134
  const hit = new Uint8Array(this.rules.length);
23119
23135
  for (const [target, rules] of this.byTarget) {
23120
23136
  for (const slot of ctx.values(target)) {
23121
- for (const index of this.slotMatches(target, rules, slot)) hit[index] = 1;
23137
+ for (const index of this.slotMatches(target, rules, slot)) {
23138
+ if (!slot.excluded?.has(this.rules[index].rule.id)) hit[index] = 1;
23139
+ }
23122
23140
  }
23123
23141
  }
23124
23142
  for (const compiled of this.chained) {
@@ -26171,8 +26189,11 @@ var CODE_RULES = [
26171
26189
  // escalates when nearby evidence shows that input can choose the download.
26172
26190
  guard: false,
26173
26191
  // Installer instructions printed by the script do not execute. Matching
26174
- // them made a script report its own documentation as a network pipeline.
26175
- lineGuard: /^\s*(?:echo|printf|say|info|warn|error)\s+["'][^"'\n]*\b(?:curl|wget)\b/,
26192
+ // them made a script report its own documentation as a network pipeline,
26193
+ // including the usual `-h | --help) echo "Usage: curl … | sh"; exit ;;` case
26194
+ // branch, which a start-of-line guard missed. Only the quoted text is
26195
+ // discounted, so `echo "see docs"; curl … | sh` still reports.
26196
+ displayStringGuard: true,
26176
26197
  // The same instructions written as a `cat <<USAGE` help block.
26177
26198
  displayedHeredocGuard: true
26178
26199
  },
@@ -26882,6 +26903,13 @@ function insideDisplayedHeredoc(lines, index) {
26882
26903
  const opener = open.opener.replace(/\s[12]?>&2\b/g, " ");
26883
26904
  return /^\s*cat\b/.test(opener) && !/>/.test(opener) && !/\|/.test(opener);
26884
26905
  }
26906
+ 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;
26907
+ function stripDisplayedStrings(line) {
26908
+ return line.replace(
26909
+ DISPLAY_STRING,
26910
+ (whole, head, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head}""`
26911
+ );
26912
+ }
26885
26913
  function evaluateRule(rule, ctx) {
26886
26914
  if (rule.languages && !rule.languages.includes(ctx.language)) return null;
26887
26915
  const line = ctx.lines[ctx.index] ?? "";
@@ -26894,6 +26922,7 @@ function evaluateRule(rule, ctx) {
26894
26922
  if (rule.requires && !rule.requires.test(context)) return null;
26895
26923
  if (rule.lineGuard?.test(line)) return null;
26896
26924
  if (rule.displayedHeredocGuard && insideDisplayedHeredoc(ctx.lines, ctx.index)) return null;
26925
+ if (rule.displayStringGuard && !rule.pattern.test(stripDisplayedStrings(line))) return null;
26897
26926
  if (rule.enclosingCallGuard) {
26898
26927
  const callees = enclosingCallees(ctx.lines, ctx.index, back);
26899
26928
  if (callees.some((callee) => rule.enclosingCallGuard.test(callee))) return null;