@newrelic/security-agent 2.4.0 → 2.4.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### v2.4.2 (2025-05-14)
2
+ #### Bug fixes
3
+ * Fixed usage of incorrect method
4
+
5
+ ### v2.4.1 (2025-05-13)
6
+ #### Bug fixes
7
+ * Only listen once for uncaughtException
8
+ #### Miscellaneous chores
9
+ * (deps-dev): bump koa from v2.14.2 to v2.16.1
10
+ * (deps-dev): bump tar-fs from v2.1.1 to v2.1.2
11
+
12
+
1
13
  ### v2.4.0 (2025-03-21)
2
14
  #### Features
3
15
  * Support for gRPC error reporting
@@ -46,9 +46,9 @@ const requestBodyLimit = 500;
46
46
 
47
47
  /**
48
48
  * Entry point of http module hook
49
- * @param {*} shim
50
- * @param {*} mod
51
- * @param {*} moduleName
49
+ * @param {*} shim
50
+ * @param {*} mod
51
+ * @param {*} moduleName
52
52
  */
53
53
  function initialize(shim, mod, moduleName) {
54
54
  logger.info(`Instrumenting ${moduleName}`);
@@ -87,9 +87,9 @@ function setupRequestMapCleanup() {
87
87
 
88
88
  /**
89
89
  * Hook to intercept outbound http requests.
90
- * @param {*} shim
91
- * @param {*} mod
92
- * @param {*} moduleName
90
+ * @param {*} shim
91
+ * @param {*} mod
92
+ * @param {*} moduleName
93
93
  */
94
94
  function outboundHook(shim, mod, method, moduleName) {
95
95
  if (API && API.getNRAgent() && API.getNRAgent().config.security.exclude_from_iast_scan.iast_detection_category.ssrf) {
@@ -167,7 +167,7 @@ function outboundHook(shim, mod, method, moduleName) {
167
167
  /**
168
168
  * Function to parse fuzzheaders and create temp files in case of dynamic scanning
169
169
  * Not functional
170
- * @param {*} fuzzheaders
170
+ * @param {*} fuzzheaders
171
171
  */
172
172
  function parseFuzzheaders(requestData, transactionId) {
173
173
  let fuzzheaders = requestData.headers;
@@ -226,14 +226,14 @@ function parseFuzzheaders(requestData, transactionId) {
226
226
 
227
227
  /**
228
228
  * Utility function to add request data in a Map
229
- * @param {*} shim
230
- * @param {*} request
231
- * @param {*} resp
229
+ * @param {*} shim
230
+ * @param {*} request
231
+ * @param {*} resp
232
232
  */
233
233
  function addRequestData(shim, request) {
234
234
  try {
235
235
  const data = Object.assign({});
236
- const transaction = shim.tracer.getTransaction();
236
+ const transaction = shim.tracer.getTransaction();
237
237
  if (transaction) {
238
238
  data.protocol = (request.connection && request.connection.encrypted) ? 'https' : 'http';
239
239
  data.body = null;
@@ -280,10 +280,10 @@ function addRequestData(shim, request) {
280
280
  }
281
281
 
282
282
  /**
283
- * Wrappert to hook http.server.emit()
284
- * @param {*} shim
285
- * @param {*} mod
286
- * @param {*} moduleName
283
+ * Wrappert to hook http.server.emit()
284
+ * @param {*} shim
285
+ * @param {*} mod
286
+ * @param {*} moduleName
287
287
  */
288
288
  function emitHook(shim, mod, moduleName) {
289
289
  shim.wrap(mod && mod.Server && mod.Server.prototype, 'emit', function makeEmitWrapper(shim, fn) {
@@ -328,8 +328,8 @@ function emitHook(shim, mod, moduleName) {
328
328
 
329
329
  /**
330
330
  * Wrapper for http.createServer method
331
- * @param {*} shim
332
- * @param {*} mod
331
+ * @param {*} shim
332
+ * @param {*} mod
333
333
  */
334
334
  function createServerHook(shim, mod, moduleName) {
335
335
  shim.wrap(mod, 'createServer', function createServerWrapper(shim, fn) {
@@ -356,9 +356,9 @@ function createServerHook(shim, mod, moduleName) {
356
356
  }
357
357
 
358
358
  /**
359
- * Wrapper to hook http request body
360
- * @param {*} shim
361
- * @param {*} mod
359
+ * Wrapper to hook http request body
360
+ * @param {*} shim
361
+ * @param {*} mod
362
362
  */
363
363
  function onDataHook(shim, mod) {
364
364
  shim.wrap(mod, '1', function makeOnDataWrapper(shim, fn) {
@@ -399,13 +399,13 @@ function onDataHook(shim, mod) {
399
399
  }
400
400
 
401
401
  /**
402
- * Wrapper to hook response.write() and reponse.end() method
403
- * @param {*} resp
404
- * @param {*} req
405
- * @param {*} shim
402
+ * Wrapper to hook response.write() and reponse.end() method
403
+ * @param {*} resp
404
+ * @param {*} req
405
+ * @param {*} shim
406
406
  */
407
407
  function responseHook(resp, req, shim) {
408
- // wrapper for response.write()
408
+ // wrapper for response.write()
409
409
  resp.res = {};
410
410
  resp.res.body = EMPTY_STRING;
411
411
 
@@ -419,7 +419,7 @@ function responseHook(resp, req, shim) {
419
419
  return fn.apply(this, arguments);
420
420
  }
421
421
  })
422
- // wrapper for response.end()
422
+ // wrapper for response.end()
423
423
  shim.wrap(resp, 'end', function makeEndWrapper(shim, fn) {
424
424
  if (!shim.isFunction(fn)) {
425
425
  return fn
@@ -460,7 +460,7 @@ function responseHook(resp, req, shim) {
460
460
  const dynamicScanningFlag = policy.data ? (policy.data.vulnerabilityScan?.enabled && policy.data.vulnerabilityScan.iastScan.enabled) : false;
461
461
  const type = response.getHeader(CONTENT_TYPE);
462
462
  let isUnsupportedType = isUnsupportedContentType(type, response);
463
-
463
+
464
464
  if (request && (construct || dynamicScanningFlag) && !isUnsupportedType) {
465
465
  const args = [];
466
466
  args.push(construct);
@@ -478,8 +478,8 @@ function responseHook(resp, req, shim) {
478
478
  }
479
479
  /**
480
480
  * Utility to check unsupported content types
481
- * @param {*} conType
482
- * @returns
481
+ * @param {*} conType
482
+ * @returns
483
483
  */
484
484
  function isUnsupportedContentType(conType, response) {
485
485
  try {
@@ -570,10 +570,10 @@ function responseBodyCompute(response, args) {
570
570
 
571
571
  /**
572
572
  * Callback hook to generate exit event
573
- * @param {*} shim
574
- * @param {*} mod
575
- * @param {*} fun
576
- * @param {*} secEvent
573
+ * @param {*} shim
574
+ * @param {*} mod
575
+ * @param {*} fun
576
+ * @param {*} secEvent
577
577
  */
578
578
  function callbackHook(shim, mod, fun, secEvent) {
579
579
  shim.secEvent = secEvent;
@@ -593,9 +593,9 @@ function callbackHook(shim, mod, fun, secEvent) {
593
593
 
594
594
  /**
595
595
  * Utility to check if child path is inside parent path
596
- * @param {*} childPath
597
- * @param {*} parentPath
598
- * @returns
596
+ * @param {*} childPath
597
+ * @param {*} parentPath
598
+ * @returns
599
599
  */
600
600
  function isPathInside(childPath, parentPath) {
601
601
  childPath = path.resolve(childPath);
@@ -614,7 +614,7 @@ function isPathInside(childPath, parentPath) {
614
614
 
615
615
  /**
616
616
  * Delete Temporary file for IAST. Do not call this in RASP
617
- * @param {*} file
617
+ * @param {*} file
618
618
  */
619
619
  function deleteTempFileForIAST(file) {
620
620
  try {
@@ -629,7 +629,12 @@ function deleteTempFileForIAST(file) {
629
629
  /**
630
630
  * Collect and report the uncaught Exception
631
631
  */
632
- process.on('uncaughtException', (err, origin) => {
632
+ const listeners = process.listeners('uncaughtException')
633
+ if (listeners.indexOf(uncaughtListener) === -1) {
634
+ process.on('uncaughtException', uncaughtListener);
635
+ }
636
+
637
+ function uncaughtListener(err, origin) {
633
638
  console.error(err);
634
639
  if (uncaughtExceptionReportFlag) {
635
640
  process.exit(1);
@@ -641,12 +646,12 @@ process.on('uncaughtException', (err, origin) => {
641
646
  }
642
647
  logger.error("An uncaughtException is detected:", err);
643
648
  uncaughtExceptionReportFlag = true;
644
- });
649
+ }
645
650
 
646
651
  /**
647
652
  * utility to parse response headers for cookie check
648
- * @param {*} headersString
649
- * @returns
653
+ * @param {*} headersString
654
+ * @returns
650
655
  */
651
656
  function responseRawHeaderParsing(headersString) {
652
657
  let setCookieValue;
@@ -666,8 +671,8 @@ function responseRawHeaderParsing(headersString) {
666
671
 
667
672
  /**
668
673
  * Utility to check insecure cookie settings
669
- * @param {*} response
670
- * @param {*} shim
674
+ * @param {*} response
675
+ * @param {*} shim
671
676
  */
672
677
  function secureCookieCheck(response, shim) {
673
678
  let cookieHeader = response.getHeader('set-cookie') ? response.getHeader('set-cookie') : responseRawHeaderParsing(response._header);
@@ -738,8 +743,8 @@ function truncateStringToBytes(inputString, maxBytes) {
738
743
 
739
744
  /**
740
745
  * Utility to generate trustboundary events.
741
- * @param {*} sessionObject
742
- * @param {*} shim
746
+ * @param {*} sessionObject
747
+ * @param {*} shim
743
748
  */
744
749
  function trustBoundaryCheck(sessionObject, shim) {
745
750
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/security-agent",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "New Relic Security Agent for Node.js",
5
5
  "main": "index.js",
6
6
  "jsonVersion": "1.2.9",