Skip to content

Commit 6ff0dc6

Browse files
authored
fix(utils): resolve command injection vulnerability in emptyFolder (3.x) (#5190)
1 parent b004ca8 commit 6ff0dc6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,12 @@ module.exports.isNotSet = function (obj) {
476476
return false
477477
}
478478

479-
module.exports.emptyFolder = async directoryPath => {
480-
require('child_process').execSync(`rm -rf ${directoryPath}/*`)
479+
module.exports.emptyFolder = directoryPath => {
480+
// Do not throw on non-existent directory, since it may be created later
481+
if (!fs.existsSync(directoryPath)) return
482+
for (const file of fs.readdirSync(directoryPath)) {
483+
fs.rmSync(path.join(directoryPath, file), { recursive: true, force: true })
484+
}
481485
}
482486

483487
module.exports.printObjectProperties = obj => {

0 commit comments

Comments
 (0)