Skip to content

Replace shell exec with execFile in CLI tests to eliminate shell injection risk#171

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/apply-autofixes-381
Draft

Replace shell exec with execFile in CLI tests to eliminate shell injection risk#171
Copilot wants to merge 2 commits into
masterfrom
copilot/apply-autofixes-381

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Tests were using exec with template-literal shell commands (cat ${tempFilePath} | ${cliPath} --delim ...), flagged by CodeQL as "Shell command built from environment values."

Potential fix for alerts

Changes

  • execexecFile: Replaced shell-spawning exec/execAsync with execFile/execFileAsync throughout the test file; no shell is invoked, so variable interpolation into shell strings is eliminated
  • execFileWithInput helper: Promisified execFile has no input option (unlike sync variants), so a small helper wraps the callback form and writes directly to child.stdin:
const execFileWithInput = (file: string, args: string[], input: string): Promise<{ stdout: string; stderr: string }> => {
    return new Promise((resolve, reject) => {
        const child = execFile(file, args, (error, stdout, stderr) => { ... });
        if (child.stdin) {
            child.stdin.write(input);
            child.stdin.end();
        }
    });
};
  • Pipe-based tests refactored: All cat file | cmd invocations replaced with fs.readFileSync + execFileWithInput, passing CSV content directly as stdin
  • Simple tests (--help, --invalid-arg, --delim edge cases) use execFileAsync with an explicit args array

Copilot AI changed the title [WIP] Autofix Code Scanning Alert Replace shell exec with execFile in CLI tests to eliminate shell injection risk Apr 3, 2026
Copilot AI requested a review from donatj April 3, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants