Skip to content

Commit a91677b

Browse files
committed
build: avoid command injection when creating package archives
Reworks the package archive script to avoid command injection by going through `exec` instead of constructing the command using string concatenation. (cherry picked from commit 078fe3e)
1 parent 5628d0c commit a91677b

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

scripts/create-package-archives.mjs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import {join} from 'path';
13+
import {execFileSync} from 'child_process';
1314
import sh from 'shelljs';
1415
import chalk from 'chalk';
1516
import yargs from 'yargs';
@@ -40,16 +41,38 @@ const builtPackages = sh
4041
// If multiple packages should be archived, we also generate a single archive that
4142
// contains all packages. This makes it easier to transfer the release packages.
4243
if (builtPackages.length > 1) {
43-
console.info('Creating archive with all packages..');
44-
sh.exec(
45-
`tar --create --gzip --directory ${releasesDir} --file ${archivesDir}/all-${suffix}.tgz .`,
44+
console.info('Creating archive with all packages...');
45+
execFileSync(
46+
'tar',
47+
[
48+
'--create',
49+
'--gzip',
50+
'--directory',
51+
releasesDir,
52+
'--file',
53+
`${archivesDir}/all-${suffix}.tgz`,
54+
'.',
55+
],
56+
{stdio: 'inherit'},
4657
);
4758
}
4859

60+
// Note that we're using `exec` here, rather than interpolating the arguments into `sh.exec`,
61+
// to avoid a potential command injection through the `suffix` which is user-provided.
4962
for (const pkg of builtPackages) {
5063
console.info(`Creating archive for package: ${pkg.name}`);
51-
sh.exec(
52-
`tar --create --gzip --directory ${pkg.path} --file ${archivesDir}/${pkg.name}-${suffix}.tgz .`,
64+
execFileSync(
65+
'tar',
66+
[
67+
'--create',
68+
'--gzip',
69+
'--directory',
70+
pkg.path,
71+
'--file',
72+
`${archivesDir}/${pkg.name}-${suffix}.tgz`,
73+
'.',
74+
],
75+
{stdio: 'inherit'},
5376
);
5477
}
5578

0 commit comments

Comments
 (0)