@contrast/protect 1.73.0 → 1.74.1

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.
@@ -74,7 +74,7 @@ module.exports = function (core) {
74
74
  * Instruments fastify in order to add our custom error handler.
75
75
  */
76
76
  fastifyErrorHandler.install = function () {
77
- depHooks.resolve({ name: 'fastify', version: '>=3 <6' }, (fastify) => patcher.patch(fastify, {
77
+ depHooks.resolve({ name: 'fastify', version: '>=4 <6' }, (fastify) => patcher.patch(fastify, {
78
78
  name: 'fastify',
79
79
  patchType,
80
80
  post(data) {
package/lib/index.d.ts CHANGED
@@ -116,7 +116,7 @@ export interface Protect {
116
116
  errorHandlers: {
117
117
  commonHandler: (err: Error) => void;
118
118
  initDomain: () => Domain;
119
- fastify3ErrorHandler: {
119
+ fastifyErrorHandler: {
120
120
  _userHandler: null | ((...args: any[]) => any),
121
121
  defaultErrorHandler: (error: Error, request: IncomingMessage, reply: ServerResponse) => void,
122
122
  handler: (err: Error, request: IncomingMessage, reply: ServerResponse) => void,
@@ -20,6 +20,7 @@ const {
20
20
  BLOCKING_MODES,
21
21
  Rule,
22
22
  ProtectRuleMode: { OFF, MONITOR },
23
+ identity,
23
24
  isString,
24
25
  traverseKeysAndValues,
25
26
  traverseValues,
@@ -676,41 +677,48 @@ module.exports = Core.makeComponent({
676
677
  const findingsForScoreAtom = {};
677
678
  const valueToResultByRuleId = {};
678
679
 
679
- Object.values(resultsMap).forEach(resultsByRuleId => {
680
- resultsByRuleId.forEach(resultByRuleId => {
681
- const {
682
- ruleId,
683
- exploited,
684
- score,
685
- value,
686
- key,
687
- inputType
688
- } = resultByRuleId;
680
+ const flattened = Object.values(resultsMap).flatMap(identity);
681
+ for (const result of flattened) {
682
+ const {
683
+ ruleId,
684
+ exploited,
685
+ score,
686
+ value,
687
+ key,
688
+ inputType
689
+ } = result;
690
+ if (
691
+ sourceContext.policy.getRuleMode(ruleId) !== MONITOR ||
692
+ exploited === true ||
693
+ score >= 90 ||
694
+ !probesRules.some((rule) => rule === ruleId) ||
695
+ inputType == InputType.UNKNOWN ||
696
+ flattened.some((maybeReported) => (
697
+ // remove chances of duplicate analysis for "similar" findings that
698
+ // would have already been reported for being blocked or exploited
699
+ maybeReported.value == result.value &&
700
+ maybeReported.inputType == result.inputType &&
701
+ maybeReported.key == result.key &&
702
+ (maybeReported.exploited || maybeReported.blocked)
703
+ ))
704
+ ) {
705
+ continue;
706
+ }
689
707
 
690
- if (
691
- sourceContext.policy.getRuleMode(ruleId) !== MONITOR ||
692
- exploited === true || // todo: remove
693
- score >= 90 ||
694
- !probesRules.some((rule) => rule === ruleId) ||
695
- inputType == InputType.UNKNOWN
696
- ) {
697
- return;
708
+ const dataType = findingsForScoreRequest[inputType];
709
+ if (!dataType) {
710
+ if (!findingsForScoreAtom[value]) {
711
+ findingsForScoreAtom[value] = {};
698
712
  }
699
713
 
700
- const dataType = findingsForScoreRequest[inputType];
701
- if (!dataType) {
702
- if (!findingsForScoreAtom[value]) {
703
- findingsForScoreAtom[value] = {};
704
- }
714
+ findingsForScoreAtom[value][inputType] = result;
715
+ continue;
716
+ }
705
717
 
706
- findingsForScoreAtom[value][inputType] = resultByRuleId;
707
- return;
708
- }
718
+ dataType[key] = value;
719
+ valueToResultByRuleId[value] = result;
720
+ }
709
721
 
710
- dataType[key] = value;
711
- valueToResultByRuleId[value] = resultByRuleId;
712
- });
713
- });
714
722
  const { ParameterValue, HeaderValue, CookieValue } = findingsForScoreRequest;
715
723
  const results =
716
724
  agentLib.scoreRequestConnect(
@@ -36,7 +36,7 @@ module.exports = (core) => {
36
36
  * registers a depHook for fastify module instrumentation
37
37
  */
38
38
  function install() {
39
- depHooks.resolve({ name: 'fastify', version: '>=3 <6' }, (fastify) => patcher.patch(fastify, {
39
+ depHooks.resolve({ name: 'fastify', version: '>=4 <6' }, (fastify) => patcher.patch(fastify, {
40
40
  name: 'fastify.build',
41
41
  patchType,
42
42
  post({ result: server, funcKey }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/protect",
3
- "version": "1.73.0",
3
+ "version": "1.74.1",
4
4
  "description": "Contrast service providing framework-agnostic Protect support",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -21,17 +21,17 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@contrast/agent-lib": "^9.1.0",
24
- "@contrast/common": "1.40.0",
25
- "@contrast/config": "1.56.0",
26
- "@contrast/core": "1.61.0",
27
- "@contrast/dep-hooks": "1.30.0",
28
- "@contrast/esm-hooks": "2.36.0",
29
- "@contrast/instrumentation": "1.40.0",
30
- "@contrast/logger": "1.34.0",
31
- "@contrast/patcher": "1.33.0",
32
- "@contrast/rewriter": "1.38.0",
33
- "@contrast/scopes": "1.31.0",
34
- "@contrast/stack-trace-factory": "1.1.0",
24
+ "@contrast/common": "1.41.1",
25
+ "@contrast/config": "1.57.1",
26
+ "@contrast/core": "1.62.1",
27
+ "@contrast/dep-hooks": "1.31.1",
28
+ "@contrast/esm-hooks": "2.37.1",
29
+ "@contrast/instrumentation": "1.41.1",
30
+ "@contrast/logger": "1.35.1",
31
+ "@contrast/patcher": "1.34.1",
32
+ "@contrast/rewriter": "1.39.1",
33
+ "@contrast/scopes": "1.32.1",
34
+ "@contrast/stack-trace-factory": "1.2.1",
35
35
  "async-hook-domain": "^4.0.1",
36
36
  "ipaddr.js": "^2.0.1",
37
37
  "on-finished": "^2.4.1",