Skip to content

Commit 441c1d9

Browse files
committed
fix(@angular-devkit/schematics): remove shell usage in git spawn to prevent command injection
Git is a native executable on Windows and does not require shell: true. Switch to array-based spawn and separate the -m flag from the commit message to prevent command injection via crafted commit messages.
1 parent 0f8a712 commit 441c1d9

File tree

1 file changed

+2
-3
lines changed
  • packages/angular_devkit/schematics/tasks/repo-init

1 file changed

+2
-3
lines changed

packages/angular_devkit/schematics/tasks/repo-init/executor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default function (
2929
const errorStream = ignoreErrorStream ? 'ignore' : process.stderr;
3030
const spawnOptions: SpawnOptions = {
3131
stdio: [process.stdin, outputStream, errorStream],
32-
shell: true,
3332
cwd: path.join(rootDirectory, options.workingDirectory || ''),
3433
env: {
3534
...process.env,
@@ -41,7 +40,7 @@ export default function (
4140
};
4241

4342
return new Promise<void>((resolve, reject) => {
44-
spawn(`git ${args.join(' ')}`, spawnOptions).on('close', (code: number) => {
43+
spawn('git', args, spawnOptions).on('close', (code: number) => {
4544
if (code === 0) {
4645
resolve();
4746
} else {
@@ -82,7 +81,7 @@ export default function (
8281
if (options.commit) {
8382
const message = options.message || 'initial commit';
8483

85-
await execute(['commit', `-m "${message}"`]);
84+
await execute(['commit', '-m', message]);
8685
}
8786

8887
context.logger.info('Successfully initialized git.');

0 commit comments

Comments
 (0)