browserstack-cypress-cli 1.36.5 → 1.36.6
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.
|
@@ -8,6 +8,26 @@ const constants = require("./constants");
|
|
|
8
8
|
const utils = require("./utils");
|
|
9
9
|
const logger = require('./logger').winstonLogger;
|
|
10
10
|
|
|
11
|
+
// Defense-in-depth: reject file paths containing shell metacharacters.
|
|
12
|
+
// This guards against command injection even if execFileSync is ever
|
|
13
|
+
// replaced with a shell-based exec in the future.
|
|
14
|
+
//
|
|
15
|
+
// Note: backslash (\) is intentionally NOT included here because it is a
|
|
16
|
+
// legitimate path separator on Windows (e.g. C:\Users\me\cypress.config.js).
|
|
17
|
+
// The actual security boundary is execFileSync (no shell), not this regex.
|
|
18
|
+
const DANGEROUS_PATH_CHARS = /[;"`$|&(){}]/;
|
|
19
|
+
|
|
20
|
+
function validateFilePath(filepath) {
|
|
21
|
+
if (DANGEROUS_PATH_CHARS.test(filepath)) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Invalid cypress config file path: "${filepath}" contains disallowed characters. ` +
|
|
24
|
+
'File paths must not include shell metacharacters such as ; " ` $ | & ( ) { }'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.validateFilePath = validateFilePath;
|
|
30
|
+
|
|
11
31
|
exports.detectLanguage = (cypress_config_filename) => {
|
|
12
32
|
const extension = cypress_config_filename.split('.').pop()
|
|
13
33
|
return constants.CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS.includes(extension) ? extension : 'js'
|
|
@@ -186,13 +206,29 @@ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_module
|
|
|
186
206
|
}
|
|
187
207
|
|
|
188
208
|
exports.loadJsFile = (cypress_config_filepath, bstack_node_modules_path) => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
209
|
+
// Security: validate file path to reject shell metacharacters (defense-in-depth)
|
|
210
|
+
validateFilePath(cypress_config_filepath);
|
|
211
|
+
|
|
212
|
+
// UX: surface a clear error if the cypress config file is missing.
|
|
213
|
+
// (This is purely a UX check — the security boundary is execFileSync above
|
|
214
|
+
// plus the metacharacter regex; existsSync alone would NOT prevent injection.)
|
|
215
|
+
if (!fs.existsSync(cypress_config_filepath)) {
|
|
216
|
+
throw new Error(`Cypress config file not found at: ${cypress_config_filepath}`);
|
|
193
217
|
}
|
|
194
|
-
|
|
195
|
-
|
|
218
|
+
|
|
219
|
+
const require_module_helper_path = path.join(__dirname, 'requireModule.js')
|
|
220
|
+
|
|
221
|
+
// Security fix: use execFileSync instead of execSync to avoid shell interpolation.
|
|
222
|
+
// execFileSync spawns the process directly without a shell, so user-controlled
|
|
223
|
+
// values in cypress_config_filepath cannot break out into shell commands.
|
|
224
|
+
const execOptions = {
|
|
225
|
+
env: Object.assign({}, process.env, { NODE_PATH: bstack_node_modules_path })
|
|
226
|
+
};
|
|
227
|
+
const args = [require_module_helper_path, cypress_config_filepath];
|
|
228
|
+
|
|
229
|
+
logger.debug(`Running: node ${args.map(a => '"' + a + '"').join(' ')} (via execFileSync, NODE_PATH=${bstack_node_modules_path})`);
|
|
230
|
+
cp.execFileSync('node', args, execOptions);
|
|
231
|
+
|
|
196
232
|
const cypress_config = JSON.parse(fs.readFileSync(config.configJsonFileName).toString())
|
|
197
233
|
if (fs.existsSync(config.configJsonFileName)) {
|
|
198
234
|
fs.unlinkSync(config.configJsonFileName)
|
|
@@ -201,24 +201,30 @@ Cypress.on('command:end', (command) => {
|
|
|
201
201
|
});
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
-
Cypress.
|
|
204
|
+
Cypress.on('command:enqueued', (attrs) => {
|
|
205
|
+
if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) return;
|
|
206
|
+
if (!attrs || attrs.name !== 'log') return;
|
|
207
|
+
const args = attrs.args || [];
|
|
205
208
|
if (args.includes('test_observability_log') || args.includes('test_observability_command')) return;
|
|
206
209
|
const message = args.reduce((result, logItem) => {
|
|
207
210
|
if (typeof logItem === 'object') {
|
|
208
211
|
return [result, JSON.stringify(logItem)].join(' ');
|
|
209
212
|
}
|
|
210
|
-
|
|
211
213
|
return [result, logItem ? logItem.toString() : ''].join(' ');
|
|
212
214
|
}, '');
|
|
213
215
|
eventsQueue.push({
|
|
214
216
|
task: 'test_observability_log',
|
|
215
217
|
data: {
|
|
216
|
-
|
|
218
|
+
level: 'info',
|
|
217
219
|
message,
|
|
218
220
|
timestamp: new Date().toISOString()
|
|
219
221
|
},
|
|
220
222
|
options: { log: false }
|
|
221
223
|
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
|
|
227
|
+
if (args.includes('test_observability_log') || args.includes('test_observability_command')) return;
|
|
222
228
|
originalFn(...args);
|
|
223
229
|
});
|
|
224
230
|
|
|
@@ -631,7 +631,9 @@ class MyReporter {
|
|
|
631
631
|
if(this.current_hook && ( this.current_hook.hookAnalyticsId && !this.runStatusMarkedHash[this.current_hook.hookAnalyticsId] )) {
|
|
632
632
|
log.hook_run_uuid = this.current_hook.hookAnalyticsId;
|
|
633
633
|
}
|
|
634
|
-
if(!log.hook_run_uuid && this.current_test &&
|
|
634
|
+
if(!log.hook_run_uuid && this.current_test && this.current_test.testAnalyticsId) {
|
|
635
|
+
log.test_run_uuid = this.current_test.testAnalyticsId;
|
|
636
|
+
}
|
|
635
637
|
if(log.hook_run_uuid || log.test_run_uuid) {
|
|
636
638
|
await uploadEventData({
|
|
637
639
|
event_type: 'LogCreated',
|