@newrelic/security-agent 2.4.1 → 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
|
@@ -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 {
|
|
@@ -630,7 +630,7 @@ function deleteTempFileForIAST(file) {
|
|
|
630
630
|
* Collect and report the uncaught Exception
|
|
631
631
|
*/
|
|
632
632
|
const listeners = process.listeners('uncaughtException')
|
|
633
|
-
if (listeners.
|
|
633
|
+
if (listeners.indexOf(uncaughtListener) === -1) {
|
|
634
634
|
process.on('uncaughtException', uncaughtListener);
|
|
635
635
|
}
|
|
636
636
|
|
|
@@ -650,8 +650,8 @@ function uncaughtListener(err, origin) {
|
|
|
650
650
|
|
|
651
651
|
/**
|
|
652
652
|
* utility to parse response headers for cookie check
|
|
653
|
-
* @param {*} headersString
|
|
654
|
-
* @returns
|
|
653
|
+
* @param {*} headersString
|
|
654
|
+
* @returns
|
|
655
655
|
*/
|
|
656
656
|
function responseRawHeaderParsing(headersString) {
|
|
657
657
|
let setCookieValue;
|
|
@@ -671,8 +671,8 @@ function responseRawHeaderParsing(headersString) {
|
|
|
671
671
|
|
|
672
672
|
/**
|
|
673
673
|
* Utility to check insecure cookie settings
|
|
674
|
-
* @param {*} response
|
|
675
|
-
* @param {*} shim
|
|
674
|
+
* @param {*} response
|
|
675
|
+
* @param {*} shim
|
|
676
676
|
*/
|
|
677
677
|
function secureCookieCheck(response, shim) {
|
|
678
678
|
let cookieHeader = response.getHeader('set-cookie') ? response.getHeader('set-cookie') : responseRawHeaderParsing(response._header);
|
|
@@ -743,8 +743,8 @@ function truncateStringToBytes(inputString, maxBytes) {
|
|
|
743
743
|
|
|
744
744
|
/**
|
|
745
745
|
* Utility to generate trustboundary events.
|
|
746
|
-
* @param {*} sessionObject
|
|
747
|
-
* @param {*} shim
|
|
746
|
+
* @param {*} sessionObject
|
|
747
|
+
* @param {*} shim
|
|
748
748
|
*/
|
|
749
749
|
function trustBoundaryCheck(sessionObject, shim) {
|
|
750
750
|
try {
|