@contrast/instrumentation 1.0.0 → 1.1.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.
package/lib/http.js ADDED
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright: 2022 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ const { get } = require('./utils');
18
+
19
+ module.exports = function(core) {
20
+ const {
21
+ patcher,
22
+ depHooks
23
+ } = core;
24
+
25
+ function hook (moduleName, patchObjects) {
26
+ depHooks.resolve({ name: moduleName }, (module) => {
27
+ patchObjects.forEach((obj) => {
28
+ const { name, methods, around, patchType } = obj;
29
+ methods.forEach((method) => {
30
+ const patchObj = get(module, name);
31
+ patcher.patch(patchObj, method, {
32
+ name: `${moduleName}.${name}.${method}`,
33
+ patchType,
34
+ around,
35
+ });
36
+ });
37
+ });
38
+ });
39
+ }
40
+ return {
41
+ 'http'(opts) {
42
+ hook('http', opts.patchObjects);
43
+ },
44
+ 'https'(opts) {
45
+ hook('https', opts.patchObjects);
46
+ },
47
+ 'spdy'(opts) {
48
+ hook('spdy', opts.patchObjects);
49
+ }
50
+ };
51
+ };
package/lib/http2.js ADDED
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Copyright: 2022 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ module.exports = function(core) {
18
+ const {
19
+ patcher,
20
+ depHooks
21
+ } = core;
22
+
23
+ return {
24
+ 'http2'(opts) {
25
+ depHooks.resolve({ name: 'http2' }, (http2) => {
26
+ opts.patchObjects.forEach((obj) => {
27
+ const { methods, patchType, patchObjects } = obj;
28
+ methods.forEach((method) => {
29
+ patcher.patch(http2, method, {
30
+ name: `http2.${method}`,
31
+ patchType,
32
+ post(data) {
33
+ const { result: server } = data;
34
+ const serverPrototype = server ? Object.getPrototypeOf(server) : null;
35
+
36
+ if (!serverPrototype) {
37
+ core.logger.error('Unable to patch server prototype, continue without instrumentation');
38
+ return;
39
+ }
40
+ patchObjects.forEach((obj) => {
41
+ const { name, methods, patchType, around } = obj;
42
+ methods.forEach((method) => {
43
+ patcher.patch(serverPrototype, method, {
44
+ name: `http2.${name}.${method}`,
45
+ patchType,
46
+ around
47
+ });
48
+ });
49
+ });
50
+ }
51
+ });
52
+ });
53
+ });
54
+ });
55
+ }
56
+ };
57
+ };
package/lib/index.js CHANGED
@@ -16,7 +16,9 @@
16
16
  'use strict';
17
17
  module.exports = function(core) {
18
18
  const installers = {
19
- ...require('./mongodb')(core)
19
+ ...require('./mongodb')(core),
20
+ ...require('./http')(core),
21
+ ...require('./http2')(core)
20
22
  };
21
23
 
22
24
  return core.instrumentation = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/instrumentation",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shared hooks and patches between Protect and Assess components",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",