@contrast/agent 4.10.3 → 4.10.4

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.
@@ -26,7 +26,7 @@ const { isString } = require('../../util/is-string');
26
26
  const { emitSendEvent } = require('../../hooks/frameworks/common');
27
27
  const {
28
28
  prototype: { decorateRequest },
29
- setFrameworkRequest
29
+ setFrameworkRequest,
30
30
  } = require('../../hooks/frameworks/base');
31
31
  const ExpressRequest = require('../../reporter/models/frameworks/express-request');
32
32
 
@@ -40,7 +40,7 @@ const {
40
40
  INPUT_TYPES,
41
41
  SINK_TYPES,
42
42
  MW_PATH,
43
- LAYER_STACK
43
+ LAYER_STACK,
44
44
  } = constants;
45
45
  const { EVENTS } = Helpers;
46
46
 
@@ -111,14 +111,14 @@ class ExpressFramework {
111
111
  agentEmitter.emit(
112
112
  EVENTS.REQUEST_SEND,
113
113
  data.args[0],
114
- SINK_TYPES.RESPONSE_BODY
114
+ SINK_TYPES.RESPONSE_BODY,
115
115
  );
116
116
 
117
- const body = data.args[0];
117
+ const [body] = data.args;
118
118
  if (isString(body)) {
119
119
  emitSendEvent(body.valueOf());
120
120
  }
121
- }
121
+ },
122
122
  });
123
123
 
124
124
  patcher.patch(express.response, 'push', {
@@ -128,14 +128,14 @@ class ExpressFramework {
128
128
  agentEmitter.emit(
129
129
  EVENTS.REQUEST_SEND,
130
130
  data.args[0],
131
- SINK_TYPES.RESPONSE_BODY
131
+ SINK_TYPES.RESPONSE_BODY,
132
132
  );
133
133
 
134
- const body = data.args[0];
134
+ const [body] = data.args;
135
135
  if (isString(body)) {
136
136
  emitSendEvent(body.valueOf());
137
137
  }
138
- }
138
+ },
139
139
  });
140
140
 
141
141
  patcher.patch(express.response, 'end', {
@@ -145,9 +145,9 @@ class ExpressFramework {
145
145
  agentEmitter.emit(
146
146
  EVENTS.REQUEST_SEND,
147
147
  data.args[0],
148
- SINK_TYPES.RESPONSE_BODY
148
+ SINK_TYPES.RESPONSE_BODY,
149
149
  );
150
- }
150
+ },
151
151
  });
152
152
 
153
153
  patcher.patch(express.Router, 'use', {
@@ -157,7 +157,7 @@ class ExpressFramework {
157
157
  pre: self.injectContrastMiddleware.bind(self),
158
158
  post: (wrapCtx) => {
159
159
  agentEmitter.emit(EVENTS.ROUTER_USE, self, wrapCtx);
160
- }
160
+ },
161
161
  });
162
162
 
163
163
  patcher.patch(express.Router, 'route', {
@@ -166,7 +166,7 @@ class ExpressFramework {
166
166
  alwaysRun: true,
167
167
  post: (wrapCtx) => {
168
168
  agentEmitter.emit(EVENTS.ROUTER_ROUTE, self, wrapCtx);
169
- }
169
+ },
170
170
  });
171
171
 
172
172
  LC_HTTP_VERBS.forEach((verb) => {
@@ -177,7 +177,7 @@ class ExpressFramework {
177
177
  pre: self.injectContrastMiddleware.bind(self),
178
178
  post: (wrapCtx) => {
179
179
  agentEmitter.emit(EVENTS.ROUTER_METHOD, self, wrapCtx, verb);
180
- }
180
+ },
181
181
  });
182
182
  });
183
183
 
@@ -188,7 +188,7 @@ class ExpressFramework {
188
188
  pre: self.injectContrastMiddleware.bind(self),
189
189
  post: (wrapCtx) => {
190
190
  agentEmitter.emit(EVENTS.ROUTER_METHOD, self, wrapCtx, 'all');
191
- }
191
+ },
192
192
  });
193
193
 
194
194
  patcher.patch(express.application, 'use', {
@@ -198,7 +198,7 @@ class ExpressFramework {
198
198
  pre: self.injectContrastMiddleware.bind(self),
199
199
  post: (wrapCtx) => {
200
200
  agentEmitter.emit(EVENTS.APP_USE, self, wrapCtx);
201
- }
201
+ },
202
202
  });
203
203
 
204
204
  LC_HTTP_VERBS.forEach((verb) => {
@@ -209,7 +209,7 @@ class ExpressFramework {
209
209
  pre: self.injectContrastMiddleware.bind(self),
210
210
  post: (wrapCtx) => {
211
211
  agentEmitter.emit(EVENTS.APP_METHOD, self, wrapCtx, verb);
212
- }
212
+ },
213
213
  });
214
214
  });
215
215
 
@@ -220,7 +220,7 @@ class ExpressFramework {
220
220
  pre: self.injectContrastMiddleware.bind(self),
221
221
  post: (wrapCtx) => {
222
222
  agentEmitter.emit(EVENTS.APP_METHOD, self, wrapCtx, 'all');
223
- }
223
+ },
224
224
  });
225
225
 
226
226
  agentEmitter.on(HTTP_EVENTS.SERVER_CREATE, this.onServerCreate.bind(this));
@@ -238,7 +238,7 @@ class ExpressFramework {
238
238
  if (!app || !app.defaultConfiguration) {
239
239
  logger.error(
240
240
  `non-express application mistakenly registered`,
241
- new Error().stack
241
+ new Error().stack,
242
242
  );
243
243
  return;
244
244
  }
@@ -305,7 +305,7 @@ class ExpressFramework {
305
305
  EVENTS.REQUEST_READY,
306
306
  req,
307
307
  res,
308
- INPUT_TYPES.QUERYSTRING
308
+ INPUT_TYPES.QUERYSTRING,
309
309
  );
310
310
  next();
311
311
  }, 'query');
@@ -322,6 +322,14 @@ class ExpressFramework {
322
322
  next();
323
323
  }, 'rawParser');
324
324
 
325
+ // ... bodyParser in Sails Framework ............................
326
+ this.useAfter(function ContrastBodyParsed(req, res, next) {
327
+ if (req._sails && req.body) {
328
+ agentEmitter.emit(EVENTS.BODY_PARSED, req, res, INPUT_TYPES.BODY);
329
+ }
330
+ next();
331
+ }, '_parseHTTPBody');
332
+
325
333
  this.useAfter(function ContrastTextBodyParsed(req, res, next) {
326
334
  agentEmitter.emit(EVENTS.BODY_PARSED, req, res, INPUT_TYPES.BODY);
327
335
  next();
@@ -329,7 +337,7 @@ class ExpressFramework {
329
337
 
330
338
  this.useAfter(function ContrastBodyParsed(req, res, next) {
331
339
  agentEmitter.emit(EVENTS.BODY_PARSED, req, res, {
332
- type: INPUT_TYPES.BODY
340
+ type: INPUT_TYPES.BODY,
333
341
  });
334
342
  next();
335
343
  }, 'urlencodedParser');
@@ -345,7 +353,7 @@ class ExpressFramework {
345
353
  EVENTS.COOKIES_PARSED,
346
354
  req,
347
355
  res,
348
- INPUT_TYPES.COOKIE_VALUE
356
+ INPUT_TYPES.COOKIE_VALUE,
349
357
  );
350
358
 
351
359
  next();
@@ -395,7 +403,7 @@ class ExpressFramework {
395
403
  patchType: PATCH_TYPES.SOURCE,
396
404
  pre(data) {
397
405
  req[LAYER_STACK].pop();
398
- }
406
+ },
399
407
  });
400
408
  if (req.query) {
401
409
  decorateRequest({ query: req.query });
@@ -406,11 +414,11 @@ class ExpressFramework {
406
414
  EVENTS.PARAM_PARSED,
407
415
  req,
408
416
  res,
409
- INPUT_TYPES.URL_PARAMETER
417
+ INPUT_TYPES.URL_PARAMETER,
410
418
  );
411
419
 
412
420
  decorateRequest({
413
- parameters: req.params
421
+ parameters: req.params,
414
422
  });
415
423
  }
416
424
 
@@ -425,20 +433,15 @@ class ExpressFramework {
425
433
  */
426
434
  if (req.body) {
427
435
  decorateRequest({ body: req.body });
428
-
429
- // BODY_PARSED event is emitted to support Sails framework
430
- if (req._sails) {
431
- agentEmitter.emit(EVENTS.BODY_PARSED, req, res, req.body);
432
- }
433
436
  }
434
- }
437
+ },
435
438
  });
436
439
  }
437
440
  }
438
441
 
439
442
  useAfter(fn, after) {
440
443
  this.handlers[after] = {
441
- post: fn
444
+ post: fn,
442
445
  };
443
446
  }
444
447
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agent",
3
- "version": "4.10.3",
3
+ "version": "4.10.4",
4
4
  "description": "Node.js security instrumentation by Contrast Security",
5
5
  "keywords": [
6
6
  "security",