Skip to content

Commit

Permalink
fix(util): tune npm to escape injection on shell commands
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Dec 5, 2024
1 parent 5070fbb commit ad3cde2
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/if-check/util/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,25 @@ export const executeCommands = async (manifest: string, cwd: boolean) => {
sanitizedManifest,
];

const fullCommand = [
...ifEnvCommand,
'&&',
...ifRunCommand,
'&&',
...ttyCommand,
'|',
...ifDiffCommand,
].join(' ');
// Execute ifEnvCommand
await execPromise(ifEnvCommand.join(' '), {
cwd: process.env.CURRENT_DIR || process.cwd(),
});

// Execute ifRunCommand
await execPromise(ifRunCommand.join(' '), {
cwd: process.env.CURRENT_DIR || process.cwd(),
});

// Execute ttyCommand and capture its output
const ttyResult = await execPromise(ttyCommand.join(' '), {
cwd: process.env.CURRENT_DIR || process.cwd(),
});

// Execute the full command
await execPromise(fullCommand, {
// Pipe ttyResult into ifDiffCommand
const diffCommand = ifDiffCommand.join(' ');
const tty = ttyResult && ttyResult.stdout.trim();
await execPromise(`${tty ? `${tty} | ` : ''}${diffCommand}`, {
cwd: process.env.CURRENT_DIR || process.cwd(),
});

Expand Down

0 comments on commit ad3cde2

Please sign in to comment.