Fix vulnerability while deleting backup file

pull/755/head
johnniang 2019-12-13 00:28:51 +08:00
parent d59877a9ce
commit 2056f528fd
1 changed files with 6 additions and 1 deletions

View File

@ -214,8 +214,13 @@ public class BackupServiceImpl implements BackupService {
public void deleteHaloBackup(String fileName) {
Assert.hasText(fileName, "File name must not be blank");
Path backupRootPath = Paths.get(haloProperties.getBackupDir());
// Get backup path
Path backupPath = Paths.get(haloProperties.getBackupDir(), fileName);
Path backupPath = backupRootPath.resolve(fileName);
// Check directory traversal
run.halo.app.utils.FileUtils.checkDirectoryTraversal(backupRootPath, backupPath);
try {
// Delete backup file