@profullstack/threatcrush 0.13.27 → 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/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) {