@contrast/agent 4.10.4 → 4.11.0

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.
@@ -59,7 +59,7 @@ class Path extends Stack {
59
59
 
60
60
  super.push({
61
61
  key,
62
- array
62
+ array,
63
63
  });
64
64
  }
65
65
  }
@@ -74,7 +74,16 @@ class Visitor {
74
74
  this.cache = new WeakSet();
75
75
  }
76
76
 
77
- visit(key, value) {
77
+ visit(key, value, isMaxDepthReached) {
78
+ if (isMaxDepthReached) {
79
+ this.updateStacks(
80
+ { counter: this.counter, path: this.path },
81
+ null,
82
+ null,
83
+ isMaxDepthReached,
84
+ );
85
+ return;
86
+ }
78
87
  // skip circular objects
79
88
  if (typeof value === 'object' && value !== null) {
80
89
  if (this.cache.has(value)) {
@@ -96,7 +105,11 @@ class Visitor {
96
105
  return newVal || value;
97
106
  }
98
107
 
99
- updateStacks(stacks, key, value) {
108
+ updateStacks(stacks, key, value, isMaxDepthReached) {
109
+ if (isMaxDepthReached) {
110
+ stacks.counter.pop();
111
+ stacks.path.pop();
112
+ }
100
113
  // We're decending into the object, so here we're
101
114
  // just building up the stacks.
102
115
 
@@ -123,7 +136,7 @@ class Visitor {
123
136
  return this.updateStacks(
124
137
  { counter: this.counter, path: this.path },
125
138
  key,
126
- value
139
+ value,
127
140
  );
128
141
  }
129
142
  return;
@@ -136,16 +149,34 @@ function traverse(obj, fn, visitor, maxDepth) {
136
149
  maxDepth = visitor;
137
150
  visitor = undefined;
138
151
  }
139
-
140
152
  visitor =
141
153
  visitor ||
142
- new Visitor(function(key, value, depth, paths) {
154
+ new Visitor(function (key, value, depth, paths) {
143
155
  fn(key, value, depth, paths);
144
156
  }, maxDepth);
145
157
 
146
- JSON.stringify(obj, function(k, v) {
147
- // if is traversable and empty, call traverse on value and pass in existing visitor
148
- return visitor.visit(k, v);
158
+ traverseObject(obj, visitor, maxDepth);
159
+ }
160
+
161
+ function traverseObject(obj, visitor, remainingDepth = Infinity) {
162
+ if (!obj) {
163
+ return;
164
+ }
165
+ if (visitor.path.length() < 1) {
166
+ visitor.visit('', obj);
167
+ }
168
+
169
+ // This is done just to reset the stack, without changing the current impletion
170
+ if (remainingDepth == 0) {
171
+ visitor.visit(null, null, true);
172
+ return;
173
+ }
174
+
175
+ Object.entries(obj).forEach(([key, value]) => {
176
+ visitor.visit(key, value);
177
+ if (value && typeof value === 'object') {
178
+ traverseObject(value, visitor, remainingDepth - 1);
179
+ }
149
180
  });
150
181
  }
151
182
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agent",
3
- "version": "4.10.4",
3
+ "version": "4.11.0",
4
4
  "description": "Node.js security instrumentation by Contrast Security",
5
5
  "keywords": [
6
6
  "security",