Skip to content

Commit 59b6943

Browse files
mhassan1kobenguyent
andcommitted
fix(utils): resolve command injection vulnerability in emptyFolder (4.x) (#5191)
* fix(utils): remove incorrect `async` from `emptyFolder` * fix(utils): resolve command injection vulnerability in `emptyFolder` --------- Co-authored-by: kobenguyent <[email protected]>
1 parent 344b783 commit 59b6943

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
@@ -479,7 +479,11 @@ export const isNotSet = function (obj) {
479479
}
480480

481481
export const emptyFolder = async directoryPath => {
482-
childProcess.execSync(`rm -rf ${directoryPath}/*`)
482+
// Do not throw on non-existent directory, since it may be created later
483+
if (!fs.existsSync(directoryPath)) return
484+
for (const file of fs.readdirSync(directoryPath)) {
485+
fs.rmSync(path.join(directoryPath, file), { recursive: true, force: true })
486+
}
483487
}
484488

485489
export const printObjectProperties = obj => {

0 commit comments

Comments
 (0)