@newrelic/security-agent 0.5.0 → 0.7.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +1 -0
  3. package/THIRD_PARTY_NOTICES.md +1 -211
  4. package/lib/instrumentation-security/core/sec-utils.js +1 -0
  5. package/lib/instrumentation-security/hooks/@nestjs/nr-nestjs-core.js +1 -0
  6. package/lib/instrumentation-security/hooks/express/nr-express.js +2 -0
  7. package/lib/instrumentation-security/hooks/fastify/nr-fastify.js +1 -0
  8. package/lib/instrumentation-security/hooks/fs/nr-fs.js +56 -20
  9. package/lib/instrumentation-security/hooks/hapi/nr-hapi.js +2 -1
  10. package/lib/instrumentation-security/hooks/http/nr-http.js +96 -4
  11. package/lib/instrumentation-security/hooks/koa/@koa/nr-@koa-router.js +3 -1
  12. package/lib/instrumentation-security/hooks/ldap/nr-ldap.js +1 -0
  13. package/lib/instrumentation-security/hooks/mongodb/common.js +2 -0
  14. package/lib/instrumentation-security/hooks/mongodb/nr-mongodb.js +1 -1
  15. package/lib/instrumentation-security/hooks/mysql/nr-mysql.js +5 -2
  16. package/lib/instrumentation-security/hooks/native/nr-childProcess.js +3 -0
  17. package/lib/instrumentation-security/hooks/postgres/nr-postgres.js +1 -0
  18. package/lib/instrumentation-security/hooks/require/nr-require.js +3 -2
  19. package/lib/instrumentation-security/hooks/restify/nr-restify.js +3 -1
  20. package/lib/instrumentation-security/hooks/xpath/nr-xpath.js +4 -2
  21. package/lib/nr-security-agent/index.js +9 -4
  22. package/lib/nr-security-agent/lib/core/Auth-headers.js +7 -0
  23. package/lib/nr-security-agent/lib/core/LogMessage.js +40 -14
  24. package/lib/nr-security-agent/lib/core/commonUtils.js +35 -4
  25. package/lib/nr-security-agent/lib/core/connections/aws-lambda-client.js +6 -8
  26. package/lib/nr-security-agent/lib/core/connections/websocket/response/fuzz-request-handler.js +21 -6
  27. package/lib/nr-security-agent/lib/core/connections/websocket/response/index.js +5 -2
  28. package/lib/nr-security-agent/lib/core/connections/websocket/websocket.js +20 -1
  29. package/lib/nr-security-agent/lib/core/sec-agent-constants.js +3 -0
  30. package/lib/nr-security-agent/lib/core/sec-util.js +14 -6
  31. package/lib/nr-security-agent/lib/core/statusUtils.js +4 -1
  32. package/lib/nr-security-agent/lib/core/websocket-client.js +19 -8
  33. package/package.json +4 -5
package/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ### v0.7.0 (2024-01-18)
2
+ #### Features
3
+ * Handling to exclude unsupported content types from rxss processing
4
+ * Handling to report errors/critical messages to Security Engine
5
+ #### Bug fixes
6
+ * Fix for file operation event's parameter must be absolute path of file
7
+ * Fix for ReferenceError of commonUtils module
8
+ #### Miscellaneous chores
9
+ * Updated log event jsonName to "critical-messages"
10
+ * Removed dependency @aws-sdk/client-lambda
11
+ * Bumped follow-redirects from v1.15.2 to v1.15.4
12
+ * Upgraded axios to v1.6.5
13
+
14
+ ### v0.6.0 (2024-01-03)
15
+ #### Features
16
+ * Added ws headers NR-CSEC-ENTITY-GUID and NR-CSEC-ENTITY-NAME
17
+ * Updated jsonVersion to 1.1.1 in security events
18
+ * Support to send important logs/errors to security engine
19
+ #### Bug fixes
20
+ * Added missing protocol in http request object
21
+ * Fix for honouring probing interval from policy
22
+ #### Miscellaneous chores
23
+ * Added nestjs test cases
24
+ * Additional logging for instrumented modules and methods
25
+ * Upgraded axios to v1.6.3
26
+ * Removed pinned version for axios and check-disk-space
27
+ * Update in lockfileVersion of package-lock.json
28
+ * Updated @babel/traverse, protobufjs, fast-xml-parser and @aws-sdk/credential-providers
29
+ * Updated Readme.md
30
+
31
+
1
32
  ### v0.5.0 (2023-11-17)
2
33
  #### Features
3
34
  * IAST support for NestJS framework
package/README.md CHANGED
@@ -62,6 +62,7 @@ The [Developer docs](http://newrelic.github.io/node-newrelic/) for writing instr
62
62
  - [fastify](https://www.npmjs.com/package/fastify)(2.x, 3.x and 4.x)
63
63
  - [restify](https://www.npmjs.com/package/restify)(8.x, 9.x, 10.x and 11.x)
64
64
  - [director](https://www.npmjs.com/package/director)(1.2.x)
65
+ - [@nestjs/core](https://www.npmjs.com/package/@nestjs/core)(8.x and above)
65
66
  - [ldapjs](https://www.npmjs.com/package/ldapjs)(2.x and above)
66
67
  - [ldapts](https://www.npmjs.com/package/ldapts)(2.x and above)
67
68
  - [xpath](https://www.npmjs.com/package/xpath)(0.0.20 and above)
@@ -14,7 +14,6 @@ code, the source code can be found at [https://github.com/newrelic/csec-node-age
14
14
 
15
15
  **[dependencies](#dependencies)**
16
16
 
17
- * [@aws-sdk/client-lambda](#aws-sdkclient-lambda)
18
17
  * [axios](#axios)
19
18
  * [check-disk-space](#check-disk-space)
20
19
  * [content-type](#content-type)
@@ -73,218 +72,9 @@ code, the source code can be found at [https://github.com/newrelic/csec-node-age
73
72
 
74
73
  ## dependencies
75
74
 
76
- ### @aws-sdk/client-lambda
77
-
78
- This product includes source derived from [@aws-sdk/client-lambda](https://github.com/aws/aws-sdk-js-v3) ([v3.436.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.436.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.436.0/LICENSE):
79
-
80
- ```
81
- Apache License
82
- Version 2.0, January 2004
83
- http://www.apache.org/licenses/
84
-
85
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
86
-
87
- 1. Definitions.
88
-
89
- "License" shall mean the terms and conditions for use, reproduction,
90
- and distribution as defined by Sections 1 through 9 of this document.
91
-
92
- "Licensor" shall mean the copyright owner or entity authorized by
93
- the copyright owner that is granting the License.
94
-
95
- "Legal Entity" shall mean the union of the acting entity and all
96
- other entities that control, are controlled by, or are under common
97
- control with that entity. For the purposes of this definition,
98
- "control" means (i) the power, direct or indirect, to cause the
99
- direction or management of such entity, whether by contract or
100
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
101
- outstanding shares, or (iii) beneficial ownership of such entity.
102
-
103
- "You" (or "Your") shall mean an individual or Legal Entity
104
- exercising permissions granted by this License.
105
-
106
- "Source" form shall mean the preferred form for making modifications,
107
- including but not limited to software source code, documentation
108
- source, and configuration files.
109
-
110
- "Object" form shall mean any form resulting from mechanical
111
- transformation or translation of a Source form, including but
112
- not limited to compiled object code, generated documentation,
113
- and conversions to other media types.
114
-
115
- "Work" shall mean the work of authorship, whether in Source or
116
- Object form, made available under the License, as indicated by a
117
- copyright notice that is included in or attached to the work
118
- (an example is provided in the Appendix below).
119
-
120
- "Derivative Works" shall mean any work, whether in Source or Object
121
- form, that is based on (or derived from) the Work and for which the
122
- editorial revisions, annotations, elaborations, or other modifications
123
- represent, as a whole, an original work of authorship. For the purposes
124
- of this License, Derivative Works shall not include works that remain
125
- separable from, or merely link (or bind by name) to the interfaces of,
126
- the Work and Derivative Works thereof.
127
-
128
- "Contribution" shall mean any work of authorship, including
129
- the original version of the Work and any modifications or additions
130
- to that Work or Derivative Works thereof, that is intentionally
131
- submitted to Licensor for inclusion in the Work by the copyright owner
132
- or by an individual or Legal Entity authorized to submit on behalf of
133
- the copyright owner. For the purposes of this definition, "submitted"
134
- means any form of electronic, verbal, or written communication sent
135
- to the Licensor or its representatives, including but not limited to
136
- communication on electronic mailing lists, source code control systems,
137
- and issue tracking systems that are managed by, or on behalf of, the
138
- Licensor for the purpose of discussing and improving the Work, but
139
- excluding communication that is conspicuously marked or otherwise
140
- designated in writing by the copyright owner as "Not a Contribution."
141
-
142
- "Contributor" shall mean Licensor and any individual or Legal Entity
143
- on behalf of whom a Contribution has been received by Licensor and
144
- subsequently incorporated within the Work.
145
-
146
- 2. Grant of Copyright License. Subject to the terms and conditions of
147
- this License, each Contributor hereby grants to You a perpetual,
148
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
149
- copyright license to reproduce, prepare Derivative Works of,
150
- publicly display, publicly perform, sublicense, and distribute the
151
- Work and such Derivative Works in Source or Object form.
152
-
153
- 3. Grant of Patent License. Subject to the terms and conditions of
154
- this License, each Contributor hereby grants to You a perpetual,
155
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
156
- (except as stated in this section) patent license to make, have made,
157
- use, offer to sell, sell, import, and otherwise transfer the Work,
158
- where such license applies only to those patent claims licensable
159
- by such Contributor that are necessarily infringed by their
160
- Contribution(s) alone or by combination of their Contribution(s)
161
- with the Work to which such Contribution(s) was submitted. If You
162
- institute patent litigation against any entity (including a
163
- cross-claim or counterclaim in a lawsuit) alleging that the Work
164
- or a Contribution incorporated within the Work constitutes direct
165
- or contributory patent infringement, then any patent licenses
166
- granted to You under this License for that Work shall terminate
167
- as of the date such litigation is filed.
168
-
169
- 4. Redistribution. You may reproduce and distribute copies of the
170
- Work or Derivative Works thereof in any medium, with or without
171
- modifications, and in Source or Object form, provided that You
172
- meet the following conditions:
173
-
174
- (a) You must give any other recipients of the Work or
175
- Derivative Works a copy of this License; and
176
-
177
- (b) You must cause any modified files to carry prominent notices
178
- stating that You changed the files; and
179
-
180
- (c) You must retain, in the Source form of any Derivative Works
181
- that You distribute, all copyright, patent, trademark, and
182
- attribution notices from the Source form of the Work,
183
- excluding those notices that do not pertain to any part of
184
- the Derivative Works; and
185
-
186
- (d) If the Work includes a "NOTICE" text file as part of its
187
- distribution, then any Derivative Works that You distribute must
188
- include a readable copy of the attribution notices contained
189
- within such NOTICE file, excluding those notices that do not
190
- pertain to any part of the Derivative Works, in at least one
191
- of the following places: within a NOTICE text file distributed
192
- as part of the Derivative Works; within the Source form or
193
- documentation, if provided along with the Derivative Works; or,
194
- within a display generated by the Derivative Works, if and
195
- wherever such third-party notices normally appear. The contents
196
- of the NOTICE file are for informational purposes only and
197
- do not modify the License. You may add Your own attribution
198
- notices within Derivative Works that You distribute, alongside
199
- or as an addendum to the NOTICE text from the Work, provided
200
- that such additional attribution notices cannot be construed
201
- as modifying the License.
202
-
203
- You may add Your own copyright statement to Your modifications and
204
- may provide additional or different license terms and conditions
205
- for use, reproduction, or distribution of Your modifications, or
206
- for any such Derivative Works as a whole, provided Your use,
207
- reproduction, and distribution of the Work otherwise complies with
208
- the conditions stated in this License.
209
-
210
- 5. Submission of Contributions. Unless You explicitly state otherwise,
211
- any Contribution intentionally submitted for inclusion in the Work
212
- by You to the Licensor shall be under the terms and conditions of
213
- this License, without any additional terms or conditions.
214
- Notwithstanding the above, nothing herein shall supersede or modify
215
- the terms of any separate license agreement you may have executed
216
- with Licensor regarding such Contributions.
217
-
218
- 6. Trademarks. This License does not grant permission to use the trade
219
- names, trademarks, service marks, or product names of the Licensor,
220
- except as required for reasonable and customary use in describing the
221
- origin of the Work and reproducing the content of the NOTICE file.
222
-
223
- 7. Disclaimer of Warranty. Unless required by applicable law or
224
- agreed to in writing, Licensor provides the Work (and each
225
- Contributor provides its Contributions) on an "AS IS" BASIS,
226
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
227
- implied, including, without limitation, any warranties or conditions
228
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
229
- PARTICULAR PURPOSE. You are solely responsible for determining the
230
- appropriateness of using or redistributing the Work and assume any
231
- risks associated with Your exercise of permissions under this License.
232
-
233
- 8. Limitation of Liability. In no event and under no legal theory,
234
- whether in tort (including negligence), contract, or otherwise,
235
- unless required by applicable law (such as deliberate and grossly
236
- negligent acts) or agreed to in writing, shall any Contributor be
237
- liable to You for damages, including any direct, indirect, special,
238
- incidental, or consequential damages of any character arising as a
239
- result of this License or out of the use or inability to use the
240
- Work (including but not limited to damages for loss of goodwill,
241
- work stoppage, computer failure or malfunction, or any and all
242
- other commercial damages or losses), even if such Contributor
243
- has been advised of the possibility of such damages.
244
-
245
- 9. Accepting Warranty or Additional Liability. While redistributing
246
- the Work or Derivative Works thereof, You may choose to offer,
247
- and charge a fee for, acceptance of support, warranty, indemnity,
248
- or other liability obligations and/or rights consistent with this
249
- License. However, in accepting such obligations, You may act only
250
- on Your own behalf and on Your sole responsibility, not on behalf
251
- of any other Contributor, and only if You agree to indemnify,
252
- defend, and hold each Contributor harmless for any liability
253
- incurred by, or claims asserted against, such Contributor by reason
254
- of your accepting any such warranty or additional liability.
255
-
256
- END OF TERMS AND CONDITIONS
257
-
258
- APPENDIX: How to apply the Apache License to your work.
259
-
260
- To apply the Apache License to your work, attach the following
261
- boilerplate notice, with the fields enclosed by brackets "{}"
262
- replaced with your own identifying information. (Don't include
263
- the brackets!) The text should be enclosed in the appropriate
264
- comment syntax for the file format. We also recommend that a
265
- file or class name and description of purpose be included on the
266
- same "printed page" as the copyright notice for easier
267
- identification within third-party archives.
268
-
269
- Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
270
-
271
- Licensed under the Apache License, Version 2.0 (the "License");
272
- you may not use this file except in compliance with the License.
273
- You may obtain a copy of the License at
274
-
275
- http://www.apache.org/licenses/LICENSE-2.0
276
-
277
- Unless required by applicable law or agreed to in writing, software
278
- distributed under the License is distributed on an "AS IS" BASIS,
279
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
280
- See the License for the specific language governing permissions and
281
- limitations under the License.
282
-
283
- ```
284
-
285
75
  ### axios
286
76
 
287
- This product includes source derived from [axios](https://github.com/axios/axios) ([v1.6.0](https://github.com/axios/axios/tree/v1.6.0)), distributed under the [MIT License](https://github.com/axios/axios/blob/v1.6.0/LICENSE):
77
+ This product includes source derived from [axios](https://github.com/axios/axios) ([v1.6.5](https://github.com/axios/axios/tree/v1.6.5)), distributed under the [MIT License](https://github.com/axios/axios/blob/v1.6.5/LICENSE):
288
78
 
289
79
  ```
290
80
  # Copyright (c) 2014-present Matt Zabriskie & Collaborators
@@ -172,6 +172,7 @@ function addRequestData(shim, request) {
172
172
  const data = Object.assign({});
173
173
  const segment = shim.getActiveSegment();
174
174
  if (segment && segment.transaction) {
175
+ data.protocol = (request.connection && request.connection.encrypted) ? 'https' : 'http';
175
176
  data.body = null;
176
177
  data.headers = request.headers;
177
178
  data.url = request.url;
@@ -40,6 +40,7 @@ module.exports = function initialize(shim) {
40
40
  if (!shim.isFunction(fn)) {
41
41
  return fn
42
42
  }
43
+ logger.debug(`Instrumenting routerExplorer.prototype.applyCallbackToRouter`)
43
44
  return function wrappedApplyCallbackToRouter() {
44
45
  try {
45
46
  const stakTrace = secUtils.traceElementForRoute();
@@ -42,6 +42,7 @@ function wrapExpress4(shim, express) {
42
42
  if (!shim.isFunction(fn)) {
43
43
  return fn
44
44
  }
45
+ logger.debug('Instrumenting express.Router.route');
45
46
  return function wrappedRoute() {
46
47
  try {
47
48
  const stakTrace = secUtils.traceElementForRoute();
@@ -62,6 +63,7 @@ function wrapExpress4(shim, express) {
62
63
  if (!shim.isFunction(fn)) {
63
64
  return fn
64
65
  }
66
+ logger.debug('Instrumenting express.Router.process_params')
65
67
  return function wrappedParam() {
66
68
  extractParams(shim, arguments[2]);
67
69
  const route = fn.apply(this, arguments)
@@ -40,6 +40,7 @@ const setupRouteHandler = (shim, fastify, moduleName) => {
40
40
  if (!shim.isFunction(fn)) {
41
41
  return fn
42
42
  }
43
+ logger.debug(`Instrumenting ${moduleName}.${fun}`);
43
44
  return function wrappedRoute() {
44
45
  try {
45
46
  const stakTrace = secUtils.traceElementForRoute();
@@ -94,8 +94,8 @@ const promiseFunctionProbableToFI = [
94
94
  */
95
95
  function initialize(shim, mod, moduleName) {
96
96
 
97
-
98
- logger.info("Instrumenting FS module");
97
+
98
+ logger.info(`Instrumenting ${moduleName}`);
99
99
  requireHook.initialize(shim)
100
100
  const binding = process.binding("fs");
101
101
  openHook(shim, binding, moduleName);
@@ -116,8 +116,9 @@ function initialize(shim, mod, moduleName) {
116
116
  */
117
117
  function openHook(shim, mod, moduleName) {
118
118
  shim.wrap(mod, "open", function makeOpenWrapper(shim, fn) {
119
+ logger.debug(`Instrumenting ${moduleName}.open`);
119
120
  return function openWrapper() {
120
- const parameters = Array.prototype.slice.apply(arguments);
121
+ let parameters = Array.prototype.slice.apply(arguments);
121
122
  const interceptedArgs = [arguments[0]];
122
123
  shim.interceptedArgs = interceptedArgs;
123
124
  const request = requestManager.getRequest(shim);
@@ -128,7 +129,7 @@ function openHook(shim, mod, moduleName) {
128
129
  parameters[0] = arguments[0];
129
130
  }
130
131
  }
131
- if (request && typeof parameters[0] === STRING && !lodash.isEmpty(parameters[0]) ) {
132
+ if (request && typeof parameters[0] === STRING && !lodash.isEmpty(parameters[0])) {
132
133
  const policy = API.getPolicy();
133
134
  const dynamicScanningFlag = policy.data ? policy.data.vulnerabilityScan.iastScan.enabled : false;
134
135
  const url = request.url;
@@ -146,19 +147,20 @@ function openHook(shim, mod, moduleName) {
146
147
  } catch (error) {
147
148
 
148
149
  }
150
+ let absoluteParameters = [parameters[0]];
149
151
  const traceObject = secUtils.getTraceObject(shim);
150
- const secMetadata = securityMetaData.getSecurityMetaData(request, interceptedArgs, traceObject, secUtils.getExecutionId(), getCaseType(parameters[1], parameters[0]), EVENT_CATEGORY.FILE)
152
+ const secMetadata = securityMetaData.getSecurityMetaData(request, absoluteParameters, traceObject, secUtils.getExecutionId(), getCaseType(parameters[1], parameters[0]), EVENT_CATEGORY.FILE)
151
153
  this.secEvent = API.generateSecEvent(secMetadata);
152
154
  API.sendEvent(this.secEvent);
153
155
  const callbackFlag = isCallback(arguments);
154
- if (callbackFlag && request.headers[NR_CSEC_FUZZ_REQUEST_ID]) {
156
+ if (callbackFlag && request.headers[NR_CSEC_FUZZ_REQUEST_ID]) {
155
157
  callbackHook(shim, arguments[3], 'oncomplete', this.secEvent);
156
158
  }
157
159
  }
158
160
 
159
161
  }
160
162
  const result = fn.apply(this, arguments);
161
- if(result>0 && request && request.headers[NR_CSEC_FUZZ_REQUEST_ID]){
163
+ if (result > 0 && request && request.headers[NR_CSEC_FUZZ_REQUEST_ID]) {
162
164
  //here generate exit event.
163
165
  API.generateExitEvent(this.secEvent);
164
166
  delete this.secEvent;
@@ -177,18 +179,26 @@ function openHook(shim, mod, moduleName) {
177
179
  function probableToFAHooks(shim, mod, moduleName) {
178
180
  functionsProbableToFA.forEach(function (fun) {
179
181
  shim.wrap(mod, fun, function makeFAWrapper(shim, fn) {
182
+ logger.debug(`Instrumenting ${moduleName}.${fun}`);
180
183
  return function FAWrapper() {
184
+ let parameters = Array.prototype.slice.apply(arguments);
181
185
  const interceptedArgs = [arguments[0]];
182
186
  shim.interceptedArgs = interceptedArgs;
183
187
  const request = requestManager.getRequest(shim);
184
- if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
188
+ if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
185
189
  const traceObject = secUtils.getTraceObject(shim);
186
- const secMetadata = securityMetaData.getSecurityMetaData(request, interceptedArgs, traceObject, secUtils.getExecutionId(), EVENT_TYPE.FILE_OPERATION, EVENT_CATEGORY.FILE)
190
+ try {
191
+ parameters[0] = path.resolve(parameters[0]);
192
+ } catch (error) {
193
+
194
+ }
195
+ let absoluteParameters = [parameters[0]];
196
+ const secMetadata = securityMetaData.getSecurityMetaData(request, absoluteParameters, traceObject, secUtils.getExecutionId(), EVENT_TYPE.FILE_OPERATION, EVENT_CATEGORY.FILE)
187
197
  this.secEvent = API.generateSecEvent(secMetadata);
188
198
  API.sendEvent(this.secEvent);
189
199
  const callbackFlag = isCallback(arguments);
190
- if (callbackFlag && request.headers[NR_CSEC_FUZZ_REQUEST_ID]) {
191
- callbackHook(shim, arguments, arguments.length-1, this.secEvent);
200
+ if (callbackFlag && request.headers[NR_CSEC_FUZZ_REQUEST_ID]) {
201
+ callbackHook(shim, arguments, arguments.length - 1, this.secEvent);
192
202
  }
193
203
  }
194
204
  return fn.apply(this, arguments);
@@ -206,23 +216,32 @@ function probableToFAHooks(shim, mod, moduleName) {
206
216
  function probableToFIHooks(shim, mod, moduleName) {
207
217
  functionProbableToFI.forEach(function (fun) {
208
218
  shim.wrap(mod, fun, function makeFIWrapper(shim, fn) {
219
+ logger.debug(`Instrumenting ${moduleName}.${fun}`);
209
220
  return function FIWrapper() {
221
+ let parameters = Array.prototype.slice.apply(arguments);
210
222
  const interceptedArgs = [arguments[0]];
211
223
  shim.interceptedArgs = interceptedArgs;
212
224
  const request = requestManager.getRequest(shim);
213
- if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
225
+ if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
214
226
  const traceObject = secUtils.getTraceObject(shim);
227
+ try {
228
+ parameters[0] = path.resolve(parameters[0]);
229
+ parameters[1] = path.resolve(parameters[1]);
230
+ } catch (error) {
231
+
232
+ }
233
+ let absoluteParameters = [parameters[0]];
215
234
  if (fun === COPY_FILE || fun === RENAME) {
216
- const secMetadata = securityMetaData.getSecurityMetaData(request, arguments[1], traceObject, secUtils.getExecutionId(), getCase(arguments[1]), EVENT_CATEGORY.FILE)
235
+ const secMetadata = securityMetaData.getSecurityMetaData(request, parameters[1], traceObject, secUtils.getExecutionId(), getCase(arguments[1]), EVENT_CATEGORY.FILE)
217
236
  this.secEvent = API.generateSecEvent(secMetadata);
218
237
  API.sendEvent(this.secEvent);
219
238
  }
220
- const secMetadata = securityMetaData.getSecurityMetaData(request, interceptedArgs, traceObject, secUtils.getExecutionId(), getCase(arguments[0]), EVENT_CATEGORY.FILE)
239
+ const secMetadata = securityMetaData.getSecurityMetaData(request, absoluteParameters, traceObject, secUtils.getExecutionId(), getCase(arguments[0]), EVENT_CATEGORY.FILE)
221
240
  this.secEvent = API.generateSecEvent(secMetadata);
222
241
  API.sendEvent(this.secEvent);
223
242
  const callbackFlag = isCallback(arguments);
224
243
  if (callbackFlag && request.headers[NR_CSEC_FUZZ_REQUEST_ID]) {
225
- callbackHook(shim, arguments, arguments.length-1, this.secEvent);
244
+ callbackHook(shim, arguments, arguments.length - 1, this.secEvent);
226
245
  }
227
246
  }
228
247
  return fn.apply(this, arguments);
@@ -239,14 +258,22 @@ function probableToFIHooks(shim, mod, moduleName) {
239
258
  */
240
259
  function probablePromiseToFAHooks(shim, mod, moduleName) {
241
260
  promiseFunctionsProbableToFA.forEach(function (fun) {
261
+ logger.debug(`Instrumenting Promise ${moduleName}.${fun}`);
242
262
  shim.wrap(mod, fun, function makeFAWrapper(shim, fn) {
243
263
  return function FAWrapper() {
264
+ let parameters = Array.prototype.slice.apply(arguments);
244
265
  const interceptedArgs = [arguments[0]];
245
266
  shim.interceptedArgs = interceptedArgs;
246
267
  const request = requestManager.getRequest(shim);
247
- if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
268
+ if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
248
269
  const traceObject = secUtils.getTraceObject(shim);
249
- const secMetadata = securityMetaData.getSecurityMetaData(request, interceptedArgs, traceObject, secUtils.getExecutionId(), EVENT_TYPE.FILE_OPERATION, EVENT_CATEGORY.FILE)
270
+ try {
271
+ parameters[0] = path.resolve(parameters[0]);
272
+ } catch (error) {
273
+
274
+ }
275
+ let absoluteParameters = [parameters[0]];
276
+ const secMetadata = securityMetaData.getSecurityMetaData(request, absoluteParameters, traceObject, secUtils.getExecutionId(), EVENT_TYPE.FILE_OPERATION, EVENT_CATEGORY.FILE)
250
277
  this.secEvent = API.generateSecEvent(secMetadata);
251
278
  API.sendEvent(this.secEvent);
252
279
  }
@@ -264,19 +291,28 @@ function probablePromiseToFAHooks(shim, mod, moduleName) {
264
291
  */
265
292
  function probablePromiseToFIHooks(shim, mod, moduleName) {
266
293
  promiseFunctionProbableToFI.forEach(function (fun) {
294
+ logger.debug(`Instrumenting Promise ${moduleName}.${fun}`);
267
295
  shim.wrap(mod, fun, function makeFIWrapper(shim, fn) {
268
296
  return function FIWrapper() {
297
+ let parameters = Array.prototype.slice.apply(arguments);
269
298
  const interceptedArgs = [arguments[0]];
270
299
  shim.interceptedArgs = interceptedArgs;
271
300
  const request = requestManager.getRequest(shim);
272
- if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
301
+ if (request && typeof arguments[0] === STRING && !lodash.isEmpty(arguments[0])) {
273
302
  const traceObject = secUtils.getTraceObject(shim);
303
+ try {
304
+ parameters[0] = path.resolve(parameters[0]);
305
+ parameters[1] = path.resolve(parameters[1]);
306
+ } catch (error) {
307
+
308
+ }
309
+ let absoluteParameters = [parameters[0]];
274
310
  if (fun === COPY_FILE || fun === RENAME) {
275
- const secMetadata = securityMetaData.getSecurityMetaData(request, arguments[1], traceObject, secUtils.getExecutionId(), getCase(arguments[1]), EVENT_CATEGORY.FILE)
311
+ const secMetadata = securityMetaData.getSecurityMetaData(request, parameters[1], traceObject, secUtils.getExecutionId(), getCase(arguments[1]), EVENT_CATEGORY.FILE)
276
312
  this.secEvent = API.generateSecEvent(secMetadata);
277
313
  API.sendEvent(this.secEvent);
278
314
  }
279
- const secMetadata = securityMetaData.getSecurityMetaData(request, interceptedArgs, traceObject, secUtils.getExecutionId(), getCase(arguments[0]), EVENT_CATEGORY.FILE)
315
+ const secMetadata = securityMetaData.getSecurityMetaData(request, absoluteParameters, traceObject, secUtils.getExecutionId(), getCase(arguments[0]), EVENT_CATEGORY.FILE)
280
316
  this.secEvent = API.generateSecEvent(secMetadata);
281
317
  API.sendEvent(this.secEvent);
282
318
  }
@@ -25,7 +25,7 @@ module.exports = function initialize(shim, hapi, moduleName) {
25
25
  return
26
26
  }
27
27
 
28
- logger.info("Instrumenting Hapi")
28
+ logger.info(`Instrumenting ${moduleName}`);
29
29
  // 'Server' and 'server' both point to the same export,
30
30
  // but we can't make any assumption about which will be used.
31
31
  // Since we wrap the prototype, the second wrap should exit early.
@@ -49,6 +49,7 @@ function serverPostConstructor(shim) {
49
49
  */
50
50
  function wrapProtoRoute(shim, proto) {
51
51
  shim.wrap(proto, 'route', function wrapRoute(shim, original) {
52
+ logger.debug(`Instrumenting ${proto}.route`);
52
53
  return function wrappedRoute() {
53
54
  const args = shim.argsToArray.apply(shim, arguments)
54
55
  if (!shim.isObject(args[0])) {