Skip to content

Commit

Permalink
Merge pull request #1650 from Automattic/GH-1649
Browse files Browse the repository at this point in the history
fix(dev-env): CWE-367 in `prepareLandoEnv()`
  • Loading branch information
sjinks authored Jan 18, 2024
2 parents 116dee2 + ce76687 commit 74d8efd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/dev-environment/dev-environment-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,14 @@ async function prepareLandoEnv(
await fs.promises.mkdir( instancePath, { recursive: true } );
await fs.promises.mkdir( nginxFolderPath, { recursive: true } );

const landoFileExists = await fs.promises.stat( landoFileTargetPath ).catch( () => false );
if ( landoFileExists ) {
await fs.promises.copyFile( landoFileTargetPath, landoBackupFileTargetPath );
try {
await fs.promises.rename( landoFileTargetPath, landoBackupFileTargetPath );
console.log( `Backup of ${ landoFileName } was created in ${ landoBackupFileTargetPath }` );
} catch ( err ) {
// If the file doesn't exist, that's fine. Otherwise, throw the error.
if ( 'ENOENT' !== ( err as NodeJS.ErrnoException ).code ) {
throw err;
}
}

await Promise.all( [
Expand Down

0 comments on commit 74d8efd

Please sign in to comment.