Skip to content

Commit 9dfbe3b

Browse files
committed
Use shell-quote.quote in testCdsCommand()
Attempts to resolve an "Indirect uncontrolled command line" code scanning alert from the recent additon of the `testCdsCommand` function. Uses the `quote` function from the `shell-quote` library to "quote" the offending CDS extractor script argument before using the arg / string within the `testCdsCommand` function.
1 parent efc989f commit 9dfbe3b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

extractors/cds/tools/src/cds/compiler/command.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { execFileSync } from 'child_process';
22
import { existsSync, readdirSync } from 'fs';
33
import { join } from 'path';
44

5+
import { quote } from 'shell-quote';
6+
57
import { fileExists } from '../../filesystem';
68
import { cdsExtractorLog } from '../../logging';
79

@@ -93,7 +95,9 @@ function testCdsCommand(
9395
env: cleanEnv,
9496
}).toString();
9597
} else {
96-
result = execFileSync('sh', ['-c', `${command} --version`], {
98+
// Use shell-quote to properly escape the command and prevent injection
99+
const escapedCommand = quote([command, '--version']);
100+
result = execFileSync('sh', ['-c', escapedCommand], {
97101
encoding: 'utf8',
98102
stdio: 'pipe',
99103
timeout: 5000, // Reduced timeout for faster failure

0 commit comments

Comments
 (0)