feat: Support to generate HTTP Response Security Event - #260
feat: Support to generate HTTP Response Security Event #260sumitsuthar wants to merge 15 commits into
Conversation
…_body flag to false
| transactionEvent.httpResponse.statusCode = response.statusCode; | ||
| transactionEvent.httpResponse.headers = response.getHeaders(); | ||
| transactionEvent.httpResponse.contentType = response.getHeader(CONTENT_TYPE); | ||
| logger.debug("Response event is:", JSON.stringify(transactionEvent)) |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to ensure that sensitive information is not logged in clear text. The best way to fix this without changing existing functionality is to sanitize the transactionEvent object before logging it. We can remove or mask sensitive fields from the object before converting it to a JSON string and logging it.
We will modify the generateTransactionEvent function in the lib/instrumentation-security/hooks/http/nr-http.js file to sanitize the transactionEvent object before logging it. Specifically, we will remove or mask the sensitive fields such as applicationUUID, policyVersion, collectorVersion, and httpRequest.
| @@ -527,3 +527,11 @@ | ||
| transactionEvent.httpResponse.contentType = response.getHeader(CONTENT_TYPE); | ||
| logger.debug("Response event is:", JSON.stringify(transactionEvent)) | ||
|
|
||
| // Sanitize sensitive information before logging | ||
| const sanitizedTransactionEvent = { ...transactionEvent }; | ||
| delete sanitizedTransactionEvent.applicationUUID; | ||
| delete sanitizedTransactionEvent.policyVersion; | ||
| delete sanitizedTransactionEvent.collectorVersion; | ||
| delete sanitizedTransactionEvent.httpRequest; | ||
|
|
||
| logger.debug("Response event is:", JSON.stringify(sanitizedTransactionEvent)) | ||
| API.sendEvent(transactionEvent); |
Description
How to Test
npm run testRelated Issues
Fixes: NR-325528