@contrast/agent 4.27.0 → 4.27.2
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/config-diagnostics.js +82 -86
- package/lib/hooks/patcher.js +5 -3
- package/package.json +1 -1
package/config-diagnostics.js
CHANGED
|
@@ -16,88 +16,80 @@ Copyright: 2022 Contrast Security, Inc
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const { exec } = require('child_process');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
|
|
21
|
+
const HELP_MESSAGE = `
|
|
22
|
+
Description:
|
|
23
|
+
The read-contrast-config utility returns the current effective node agent configuration.
|
|
24
|
+
|
|
25
|
+
Usage:
|
|
26
|
+
npx -p @contrast/agent read-contrast-config <path/to/entry/script> [options]
|
|
27
|
+
npx -p @contrast/agent read-contrast-config --help
|
|
28
|
+
|
|
29
|
+
Options:
|
|
30
|
+
--quiet -q Prevents output of the report to the console.
|
|
31
|
+
--output -o The directory to write the report in. Defaults to the current directory.
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const diagnostics = {
|
|
35
|
+
parseArgv(argv) {
|
|
36
|
+
const args = {
|
|
37
|
+
help: false,
|
|
38
|
+
output: 'contrast_effective_config.json',
|
|
39
|
+
quiet: false,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < argv.length; i++) {
|
|
43
|
+
const arg = argv[i];
|
|
44
|
+
switch (arg) {
|
|
45
|
+
case '--help':
|
|
46
|
+
args.help = true;
|
|
47
|
+
return args;
|
|
48
|
+
case '-o':
|
|
49
|
+
case '--output': {
|
|
50
|
+
// grab the next value and skip in the next loop
|
|
51
|
+
const output = argv[++i];
|
|
52
|
+
if (!output) {
|
|
53
|
+
throw new Error('Expected a value to be provided after --output');
|
|
54
|
+
}
|
|
55
|
+
args.output = output;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case '-q':
|
|
59
|
+
case '--quiet':
|
|
60
|
+
args.quiet = true;
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
if (!arg.startsWith('-')) {
|
|
64
|
+
args.entry = arg;
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
19
69
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
case '-o':
|
|
24
|
-
args.output = nextParameter;
|
|
25
|
-
break;
|
|
26
|
-
default:
|
|
27
|
-
throw new Error(`Invalid parameter ${currParameter}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
70
|
+
if (!args.entry) {
|
|
71
|
+
throw new Error('No entry point provided');
|
|
72
|
+
}
|
|
30
73
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
case '--help':
|
|
34
|
-
args.help = true;
|
|
35
|
-
break;
|
|
36
|
-
case '--quiet':
|
|
37
|
-
case '-q':
|
|
38
|
-
args.quiet = true;
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
throw new Error(`Invalid parameter ${parameter}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
74
|
+
return args;
|
|
75
|
+
},
|
|
44
76
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
'The config-diagnostics utility returns the current effective node agent configuration\n' +
|
|
49
|
-
'\nUsage:\n' +
|
|
50
|
-
'npx -p @contrast/agent config-diagnostics <path/to/entry/script> [options]\n' +
|
|
51
|
-
'npx -p @contrast/agent config-diagnostics --help\n' +
|
|
52
|
-
'\nOptions:\n' +
|
|
53
|
-
'--quiet -q Prevents output of the report to the console.\n' +
|
|
54
|
-
'--output -o The directory to write the report in. Defaults to the current directory.\n'
|
|
55
|
-
);
|
|
56
|
-
}
|
|
77
|
+
executeNodeAgent(args) {
|
|
78
|
+
let agentEnvArgs =
|
|
79
|
+
'CONTRAST__SHOW__BANNER=false CONTRAST__AGENT__DIAGNOSTICS__ENABLE=true';
|
|
57
80
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const args = {
|
|
61
|
-
output: 'contrast_effective_config.json',
|
|
62
|
-
quiet: false,
|
|
63
|
-
help: false,
|
|
64
|
-
};
|
|
65
|
-
let currParameter = null;
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < argv.length; i++) {
|
|
68
|
-
if (!currParameter) {
|
|
69
|
-
currParameter = argv[i];
|
|
70
|
-
}
|
|
71
|
-
if (!(currParameter.startsWith('--') || currParameter.startsWith('-'))) {
|
|
72
|
-
currParameter = null;
|
|
73
|
-
continue;
|
|
81
|
+
if (!args.quiet) {
|
|
82
|
+
agentEnvArgs = `${agentEnvArgs} CONTRAST__AGENT__DIAGNOSTICS__QUIET=false`;
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
currParameter = null;
|
|
79
|
-
} else {
|
|
80
|
-
handleDependentParameter(args, currParameter, argv[i + 1]);
|
|
81
|
-
currParameter = null;
|
|
85
|
+
if (args.output) {
|
|
86
|
+
agentEnvArgs = `${agentEnvArgs} CONTRAST__AGENT__DIAGNOSTICS__REPORT_PATH=${args.output}`;
|
|
82
87
|
}
|
|
83
|
-
}
|
|
84
88
|
|
|
85
|
-
|
|
86
|
-
}
|
|
89
|
+
const bootstrap = path.join(__dirname, 'bootstrap.js');
|
|
90
|
+
const command = `${agentEnvArgs} node -r ${bootstrap} ${args.entry}`;
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
let agentEnvArgs = 'CONTRAST__SHOW__BANNER=false CONTRAST__AGENT__DIAGNOSTICS__ENABLE=true';
|
|
90
|
-
const entry = process.argv.slice(2).shift();
|
|
91
|
-
|
|
92
|
-
if (!args.quiet) {
|
|
93
|
-
agentEnvArgs = agentEnvArgs.concat(' CONTRAST__AGENT__DIAGNOSTICS__QUIET=false');
|
|
94
|
-
}
|
|
95
|
-
if (args.output) {
|
|
96
|
-
agentEnvArgs = agentEnvArgs.concat(` CONTRAST__AGENT__DIAGNOSTICS__REPORT_PATH=${args.output}`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
exec(`${agentEnvArgs} node -r ./node_modules/@contrast/agent/bootstrap.js ${entry}`,
|
|
100
|
-
(error, stdout, stderr) => {
|
|
92
|
+
exec(command, (error, stdout, stderr) => {
|
|
101
93
|
if (error && !args.quiet) {
|
|
102
94
|
console.log(`error: ${error.message}`);
|
|
103
95
|
return;
|
|
@@ -112,19 +104,23 @@ function executeNodeAgent(args) {
|
|
|
112
104
|
if (!args.quiet) {
|
|
113
105
|
console.log(stdout);
|
|
114
106
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
}
|
|
107
|
+
});
|
|
108
|
+
},
|
|
118
109
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
110
|
+
fetchAgentConfig(args) {
|
|
111
|
+
if (args.help) {
|
|
112
|
+
console.log(HELP_MESSAGE);
|
|
113
|
+
} else {
|
|
114
|
+
this.executeNodeAgent(args);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
};
|
|
126
118
|
|
|
119
|
+
module.exports = diagnostics;
|
|
127
120
|
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
121
|
+
// only run if this file is being executed as an entry script
|
|
122
|
+
// istanbul ignore next
|
|
123
|
+
if (require.main === module) {
|
|
124
|
+
const args = diagnostics.parseArgv(process.argv.slice(2));
|
|
125
|
+
diagnostics.fetchAgentConfig(args);
|
|
126
|
+
}
|
package/lib/hooks/patcher.js
CHANGED
|
@@ -93,9 +93,11 @@ Object.defineProperty(Function.prototype, '__isContrastHooked', {
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
Function.prototype
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
Object.defineProperty(Function.prototype, '_contrast_toString', {
|
|
97
|
+
value: function _contrast_toString() {
|
|
98
|
+
return Reflect.apply(functionToString, this, arguments);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
99
101
|
|
|
100
102
|
function runHooks(type, data, thisTarget, fnHooks) {
|
|
101
103
|
fnHooks.forEach((hook, key) => {
|