@contrast/agentify 1.1.2 → 1.2.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.
@@ -15,20 +15,72 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- module.exports = function(deps) {
18
+ module.exports = function(core) {
19
+ const { logger, patcher } = core;
20
+
21
+ const getOrig = (v) => patcher.unwrap(v);
22
+ const slice = patcher.unwrap(String.prototype.slice);
23
+ const toUntrackedString = (v) => slice.call(` ${v}`, 1);
24
+
19
25
  /**
20
26
  * Components e.g. Assess, Protect, can
21
27
  * 1) configure rewriter to add desired ContrastMethod functions to source code
22
28
  * 2) patch those functions on `contrastMethods.api` in order to add instrumentation
23
29
  */
24
- const contrastMethods = deps.contrastMethods = {
30
+ const contrastMethods = {
25
31
  // TODO: Assess will require add'l methods
26
32
  // TODO: ESM will require add'l methods
27
33
  api: {
28
34
  eval(v) {
29
35
  return v;
30
36
  },
31
- Function: deps.patcher.patch(global.Function, {
37
+ plus(left, right) {
38
+ const ret = getOrig(left) + getOrig(right);
39
+ return ret;
40
+ },
41
+ doubleEqual(left, right) {
42
+ left = getOrig(left);
43
+ right = getOrig(right);
44
+
45
+ return left == right;
46
+ },
47
+ notTripleEqual(left, right) {
48
+ left = getOrig(left);
49
+ right = getOrig(right);
50
+
51
+ return left !== right;
52
+ },
53
+ tripleEqual(left, right) {
54
+ left = getOrig(left);
55
+ right = getOrig(right);
56
+
57
+ return left === right;
58
+ },
59
+ notDoubleEqual(left, right) {
60
+ left = getOrig(left);
61
+ right = getOrig(right);
62
+
63
+ return left != right;
64
+ },
65
+ forceCopy(handle) {
66
+ // Used to force a copy of handle:
67
+ // https://stackoverflow.com/a/31733628
68
+ // This is a workaround for CONTRAST-30333, in which something we
69
+ // suspect is a v8 bug means that handle will otherwise be clobbered
70
+ // and if it was externalized, we will lose the data associated with it
71
+ if (typeof handle === 'string') {
72
+ handle = toUntrackedString(handle);
73
+ }
74
+ return handle;
75
+ },
76
+ cast: function __cast(val) {
77
+ return getOrig(val);
78
+ },
79
+ tag: function __contrastTag(strings) {
80
+ // XXX implemented in lib/assess/propagators/templates.js
81
+ },
82
+
83
+ Function: core.patcher.patch(global.Function, {
32
84
  name: 'global.Function',
33
85
  patchType: 'rewrite-injection'
34
86
  }),
@@ -56,9 +108,9 @@ module.exports = function(deps) {
56
108
  } catch (err) {
57
109
  // We should never expect this since the installation process is well
58
110
  // controlled, but still we should have the defensive code.
59
- deps.logger.error({ err }, 'Unable to install global.ContrastMethods');
111
+ logger.error({ err }, 'Unable to install global.ContrastMethods');
60
112
  }
61
113
  };
62
114
 
63
- return deps.contrastMethods;
115
+ return core.contrastMethods = contrastMethods;
64
116
  };
package/lib/index.js CHANGED
@@ -22,9 +22,10 @@ const defaultOpts = {
22
22
  svcList: [
23
23
  'reporter',
24
24
  'contrastMethods',
25
- 'instrumentationLocks',
25
+ 'deadzones',
26
26
  'scopes',
27
27
  'sources',
28
+ 'assess',
28
29
  'protect',
29
30
  'depHooks',
30
31
  'rewriteHooks',
@@ -36,10 +37,8 @@ module.exports = function(deps) {
36
37
  // compose add'l local services
37
38
  require('./sources')(deps);
38
39
  require('./contrast-methods')(deps);
39
- require('./instrumentation-locks')(deps);
40
40
  require('./function-hooks')(deps);
41
41
  require('./rewrite-hooks')(deps);
42
- // TODO: NODE-2229
43
42
 
44
43
  /**
45
44
  * The interface is a function, which when called, will hook runMain
@@ -28,6 +28,7 @@ module.exports = function(deps) {
28
28
  Module.prototype._compile = function(content, filename) {
29
29
  let compiled;
30
30
  const { code } = deps.rewriter.rewrite(content, { filename, inject: true, wrap: true });
31
+
31
32
  try {
32
33
  compiled = origCompile.call(this, code, filename);
33
34
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agentify",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Configures Contrast agent services and instrumentation within an application",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -16,4 +16,4 @@
16
16
  "scripts": {
17
17
  "test": "../scripts/test.sh"
18
18
  }
19
- }
19
+ }
@@ -1,51 +0,0 @@
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
-
16
- 'use strict';
17
-
18
- const Module = require('module');
19
-
20
- module.exports = function(deps) {
21
- const {
22
- patcher: { patch },
23
- scopes: { instrumentation }
24
- } = deps;
25
-
26
- deps.instrumentationLocks = {
27
- install() {
28
- const name = 'Module.prototype.require';
29
- const store = {
30
- name: `${name}`,
31
- lock: true,
32
- };
33
-
34
- // `require` has sinks and propagators that run
35
- patch(Module.prototype, 'require', {
36
- name,
37
- patchType: 'instrumentation-lock',
38
- around(next, data) {
39
- if (!instrumentation.isLocked()) {
40
- return instrumentation.run(store, next);
41
- }
42
- return next();
43
- }
44
- });
45
-
46
- // likely more to come e.g. v4 deadzones
47
- }
48
- };
49
-
50
- return deps.instrumentationLocks;
51
- };