@contrast/core 1.11.1 → 1.12.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/agent-info.js +30 -0
- package/lib/contrast-methods.js +167 -0
- package/lib/effective-config/index.js +24 -26
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -2
- package/lib/system-info/index.js +21 -10
- package/package.json +6 -6
|
@@ -0,0 +1,30 @@
|
|
|
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 { name: agentName, version: agentVersion } = require('../package.json');
|
|
19
|
+
|
|
20
|
+
module.exports = function init(core) {
|
|
21
|
+
// default to version of core
|
|
22
|
+
if (!core.agentName) {
|
|
23
|
+
core.agentName = agentName;
|
|
24
|
+
}
|
|
25
|
+
if (!core.agentVersion) {
|
|
26
|
+
core.agentVersion = agentVersion;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return core;
|
|
30
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
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
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Components e.g. Assess, Protect, can
|
|
27
|
+
* 1) configure rewriter to add desired ContrastMethod functions to source code
|
|
28
|
+
* 2) patch those functions on `contrastMethods.api` in order to add instrumentation
|
|
29
|
+
*/
|
|
30
|
+
core.contrastMethods = {
|
|
31
|
+
api: {
|
|
32
|
+
eval(val) {
|
|
33
|
+
return val;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// Assignment Operators
|
|
37
|
+
addAssign(left, right) {
|
|
38
|
+
return this.add(left, right);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// Binary Operators
|
|
42
|
+
add(left, right) {
|
|
43
|
+
const ret = getOrig(left) + getOrig(right);
|
|
44
|
+
return ret;
|
|
45
|
+
},
|
|
46
|
+
eqEq(left, right) {
|
|
47
|
+
left = getOrig(left);
|
|
48
|
+
right = getOrig(right);
|
|
49
|
+
|
|
50
|
+
return left == right;
|
|
51
|
+
},
|
|
52
|
+
eqEqEq(left, right) {
|
|
53
|
+
left = getOrig(left);
|
|
54
|
+
right = getOrig(right);
|
|
55
|
+
|
|
56
|
+
return left === right;
|
|
57
|
+
},
|
|
58
|
+
notEq(left, right) {
|
|
59
|
+
left = getOrig(left);
|
|
60
|
+
right = getOrig(right);
|
|
61
|
+
|
|
62
|
+
return left != right;
|
|
63
|
+
},
|
|
64
|
+
notEqEq(left, right) {
|
|
65
|
+
left = getOrig(left);
|
|
66
|
+
right = getOrig(right);
|
|
67
|
+
|
|
68
|
+
return left !== right;
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
// Computed Properties
|
|
72
|
+
// Used to force a copy of handle:
|
|
73
|
+
// https://stackoverflow.com/a/31733628
|
|
74
|
+
// This is a workaround for CONTRAST-30333, in which something we
|
|
75
|
+
// suspect is a v8 bug means that handle will otherwise be clobbered
|
|
76
|
+
// and if it was externalized, we will lose the data associated with it
|
|
77
|
+
forceCopy(handle) {
|
|
78
|
+
if (typeof handle === 'string') {
|
|
79
|
+
handle = toUntrackedString(handle);
|
|
80
|
+
}
|
|
81
|
+
return handle;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
// Switch Case
|
|
85
|
+
cast(val) {
|
|
86
|
+
return getOrig(val);
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Tagged Templates
|
|
91
|
+
* The first argument received by the tag function is an array of strings.
|
|
92
|
+
* For any template literal, its length is equal to the number of
|
|
93
|
+
* substitutions (occurrences of ${...}) plus one, and is therefore always
|
|
94
|
+
* non-empty.
|
|
95
|
+
* see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
|
|
96
|
+
* @param {string[]} strings length n+1
|
|
97
|
+
* @param {string[]} args length n
|
|
98
|
+
* @returns {string}
|
|
99
|
+
*/
|
|
100
|
+
tag(strings, ...args) {
|
|
101
|
+
const [first, ...rest] = strings;
|
|
102
|
+
|
|
103
|
+
return rest.reduce(
|
|
104
|
+
(result, str, i) => result.concat(args[i], str),
|
|
105
|
+
first,
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
// Import Statements
|
|
110
|
+
importDefault(...args) {
|
|
111
|
+
// noop
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
importStarAs(...args) {
|
|
115
|
+
// noop
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
importNamed(...args) {
|
|
119
|
+
// noop
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// Injections
|
|
123
|
+
Function: core.patcher.patch(global.Function, {
|
|
124
|
+
name: 'global.Function',
|
|
125
|
+
patchType: 'rewrite-injection',
|
|
126
|
+
}),
|
|
127
|
+
Number: core.patcher.patch(global.Number, {
|
|
128
|
+
name: 'global.Number',
|
|
129
|
+
patchType: 'rewrite-injection',
|
|
130
|
+
}),
|
|
131
|
+
Object: core.patcher.patch(global.Object, {
|
|
132
|
+
name: 'global.Object',
|
|
133
|
+
patchType: 'rewrite-injection',
|
|
134
|
+
}),
|
|
135
|
+
String: core.patcher.patch(global.String, {
|
|
136
|
+
name: 'global.String',
|
|
137
|
+
patchType: 'rewrite-injection',
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
installed: false,
|
|
142
|
+
|
|
143
|
+
getGlobal() {
|
|
144
|
+
return global;
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
install() {
|
|
148
|
+
if (this.installed) return;
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
Object.defineProperty(this.getGlobal(), 'ContrastMethods', {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
configurable: false,
|
|
154
|
+
value: this.api,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
this.installed = true;
|
|
158
|
+
} catch (err) {
|
|
159
|
+
// We should never expect this since the installation process is well
|
|
160
|
+
// controlled, but still we should have the defensive code.
|
|
161
|
+
logger.error({ err }, 'Unable to define global.ContrastMethods');
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
return core.contrastMethods;
|
|
167
|
+
};
|
|
@@ -21,19 +21,14 @@ const { configOptions } = require('@contrast/config/lib/options');
|
|
|
21
21
|
module.exports = function(core) {
|
|
22
22
|
const { config, messages } = core;
|
|
23
23
|
const effectiveConfig = createEffectiveConfig({ config, remoteData: {} });
|
|
24
|
-
|
|
25
|
-
let remoteValue = value;
|
|
26
|
-
if (typeof value === 'string') remoteValue = remoteValue.toLowerCase();
|
|
27
|
-
target.set(name, {
|
|
28
|
-
CanonicalName: name,
|
|
29
|
-
Name: name,
|
|
30
|
-
Value: remoteValue,
|
|
31
|
-
Source: 'ContrastUI',
|
|
32
|
-
});
|
|
33
|
-
}
|
|
24
|
+
let Status = '';
|
|
34
25
|
|
|
35
26
|
if (core.config?.protect?.enable === true) {
|
|
36
27
|
messages.on(Event.SERVER_SETTINGS_UPDATE, (msg) => {
|
|
28
|
+
if (!Status) {
|
|
29
|
+
Status = 'Success';
|
|
30
|
+
}
|
|
31
|
+
|
|
37
32
|
msg.features && mergeRemoteData(config, msg, featureReaders, setterFn, effectiveConfig);
|
|
38
33
|
msg.settings && mergeRemoteData(config, msg, settingsReaders, setterFn, effectiveConfig);
|
|
39
34
|
});
|
|
@@ -42,8 +37,20 @@ module.exports = function(core) {
|
|
|
42
37
|
core.getEffectiveConfig = function () {
|
|
43
38
|
return formatEffectiveConfig(effectiveConfig);
|
|
44
39
|
};
|
|
40
|
+
|
|
45
41
|
return;
|
|
46
42
|
|
|
43
|
+
function setterFn(target, name, value) {
|
|
44
|
+
let remoteValue = value;
|
|
45
|
+
if (typeof value === 'string') remoteValue = remoteValue.toLowerCase();
|
|
46
|
+
target.set(name, {
|
|
47
|
+
CanonicalName: name,
|
|
48
|
+
Name: name,
|
|
49
|
+
Value: remoteValue,
|
|
50
|
+
Source: 'ContrastUI',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
function createEffectiveConfig({ config, remoteData }) {
|
|
48
55
|
const list = configOptions.map(({ name }) => ({
|
|
49
56
|
CanonicalName: name,
|
|
@@ -57,26 +64,17 @@ module.exports = function(core) {
|
|
|
57
64
|
|
|
58
65
|
function formatEffectiveConfig(configMap) {
|
|
59
66
|
const values = Array.from(configMap.values()).filter(s => s.Value != undefined);
|
|
60
|
-
|
|
61
67
|
const content = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
Status,
|
|
69
|
+
ReportCreate: new Date(),
|
|
70
|
+
Config: {
|
|
71
|
+
EffectiveConfig: values,
|
|
72
|
+
Environment: values.filter(v => v.Source === 'ENV'),
|
|
73
|
+
ContrastUI: values.filter(v => v.Source === 'ContrastUI'),
|
|
74
|
+
File: values.filter(v => v.Source === 'YAML'),
|
|
69
75
|
}
|
|
70
76
|
};
|
|
71
77
|
|
|
72
|
-
const api = values.filter(v => v.CanonicalName == 'api.enable')[0];
|
|
73
|
-
const apiEnabled = api && api.Value;
|
|
74
|
-
if (apiEnabled) {
|
|
75
|
-
content.status = 'Success!';
|
|
76
|
-
} else {
|
|
77
|
-
content.status = 'Success! Couldn\'t connect to Teamserver, so no Teamserver data will be included!';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
78
|
return content;
|
|
81
79
|
}
|
|
82
80
|
};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -19,7 +19,7 @@ const EventEmitter = require('events');
|
|
|
19
19
|
|
|
20
20
|
module.exports = function init(core = {}) {
|
|
21
21
|
core.messages = new EventEmitter();
|
|
22
|
-
|
|
22
|
+
require('./agent-info')(core);
|
|
23
23
|
require('@contrast/config')(core);
|
|
24
24
|
require('./logger-factory')(core);
|
|
25
25
|
require('./effective-config')(core);
|
|
@@ -29,6 +29,7 @@ module.exports = function init(core = {}) {
|
|
|
29
29
|
require('./is-agent-path')(core);
|
|
30
30
|
require('./capture-stacktrace')(core);
|
|
31
31
|
require('@contrast/patcher')(core);
|
|
32
|
+
require('./contrast-methods')(core);
|
|
32
33
|
require('@contrast/rewriter')(core);
|
|
33
34
|
require('@contrast/dep-hooks')(core);
|
|
34
35
|
require('@contrast/scopes')(core);
|
|
@@ -37,6 +38,5 @@ module.exports = function init(core = {}) {
|
|
|
37
38
|
require('@contrast/instrumentation')(core);
|
|
38
39
|
require('@contrast/agentify')(core);
|
|
39
40
|
|
|
40
|
-
console.log('test');
|
|
41
41
|
return core;
|
|
42
42
|
};
|
package/lib/system-info/index.js
CHANGED
|
@@ -58,30 +58,41 @@ function isDocker() {
|
|
|
58
58
|
|
|
59
59
|
try {
|
|
60
60
|
const result = fs.statSync('/.dockerenv');
|
|
61
|
-
if (result) return { isDocker: true, containerID:
|
|
61
|
+
if (result) return { isDocker: true, containerID: null };
|
|
62
62
|
} catch (err) {
|
|
63
63
|
// if there's not such file we can conclude it's not docker env
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
return { isDocker: false, containerID:
|
|
66
|
+
return { isDocker: false, containerID: null };
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
module.exports = function(core) {
|
|
70
|
-
const {
|
|
70
|
+
const {
|
|
71
|
+
agentName,
|
|
72
|
+
agentVersion,
|
|
73
|
+
config
|
|
74
|
+
} = core;
|
|
71
75
|
|
|
76
|
+
// have values default to null so all required keys get serialized
|
|
72
77
|
core.getSystemInfo = function() {
|
|
73
78
|
const appPath = process.cwd();
|
|
74
79
|
|
|
75
80
|
const info = {
|
|
76
|
-
ReportDate: new Date(),
|
|
81
|
+
ReportDate: new Date().toISOString(),
|
|
77
82
|
MachineName: os.hostname(),
|
|
78
83
|
Contrast: {
|
|
79
|
-
Url: config.api.url,
|
|
80
|
-
Proxy:
|
|
84
|
+
Url: config.api.url || null,
|
|
85
|
+
Proxy: {
|
|
86
|
+
enable: !!config.api.proxy.enable,
|
|
87
|
+
url: config.api.proxy.url || null,
|
|
88
|
+
},
|
|
81
89
|
Server: {
|
|
82
90
|
Name: config.server.name,
|
|
83
|
-
}
|
|
84
|
-
|
|
91
|
+
},
|
|
92
|
+
Agent: {
|
|
93
|
+
Name: agentName,
|
|
94
|
+
Version: agentVersion,
|
|
95
|
+
},
|
|
85
96
|
},
|
|
86
97
|
Node: {
|
|
87
98
|
Version: process.version
|
|
@@ -92,8 +103,8 @@ module.exports = function(core) {
|
|
|
92
103
|
Version: os.release(),
|
|
93
104
|
KernelVersion: os.version(),
|
|
94
105
|
CPU: {
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
Type: os.cpus()[0].model,
|
|
107
|
+
Count: os.cpus().length,
|
|
97
108
|
}
|
|
98
109
|
},
|
|
99
110
|
Host: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Preconfigured Contrast agent core services and models",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"test": "../scripts/test.sh"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@contrast/agentify": "1.
|
|
21
|
-
"@contrast/common": "1.
|
|
22
|
-
"@contrast/config": "1.
|
|
20
|
+
"@contrast/agentify": "1.5.0",
|
|
21
|
+
"@contrast/common": "1.5.0",
|
|
22
|
+
"@contrast/config": "1.7.0",
|
|
23
23
|
"@contrast/deadzones": "1.1.0",
|
|
24
24
|
"@contrast/dep-hooks": "1.1.0",
|
|
25
25
|
"@contrast/fn-inspect": "^3.2.0",
|
|
26
26
|
"@contrast/instrumentation": "1.1.0",
|
|
27
27
|
"@contrast/logger": "1.2.0",
|
|
28
28
|
"@contrast/patcher": "1.2.0",
|
|
29
|
-
"@contrast/reporter": "1.
|
|
30
|
-
"@contrast/rewriter": "1.
|
|
29
|
+
"@contrast/reporter": "1.10.0",
|
|
30
|
+
"@contrast/rewriter": "1.4.0",
|
|
31
31
|
"@contrast/scopes": "1.3.0"
|
|
32
32
|
}
|
|
33
33
|
}
|