Skip to content

Commit f58de8d

Browse files
committed
fix(utils): resolve command injection vulnerability in emptyFolder
1 parent 53a5a97 commit f58de8d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ module.exports.isNotSet = function (obj) {
457457
};
458458

459459
module.exports.emptyFolder = (directoryPath) => {
460-
require('child_process').execSync(`rm -rf ${directoryPath}/*`);
460+
// Do not throw on non-existent directory, since it may be created later
461+
if (!fs.existsSync(directoryPath)) return;
462+
for (const file of fs.readdirSync(directoryPath)) {
463+
fs.rmSync(path.join(directoryPath, file), { recursive: true, force: true });
464+
}
461465
};
462466

463467
module.exports.printObjectProperties = (obj) => {

0 commit comments

Comments
 (0)