Check that backup file ends with .zip in case if there are other files in the backup folder

This commit is contained in:
Matias Griese
2020-12-01 09:01:41 +02:00
parent 24e7d154f1
commit 9483b98be8

View File

@@ -1327,7 +1327,7 @@ class AdminController extends AdminBaseController
if ($download) { if ($download) {
$filename = basename(base64_decode(urldecode($download))); $filename = basename(base64_decode(urldecode($download)));
$file = $this->grav['locator']->findResource("backup://{$filename}", true); $file = $this->grav['locator']->findResource("backup://{$filename}", true);
if (!$file) { if (!$file || !Utils::endsWith($filename, '.zip', false)) {
header('HTTP/1.1 401 Unauthorized'); header('HTTP/1.1 401 Unauthorized');
exit(); exit();
} }
@@ -1350,8 +1350,6 @@ class AdminController extends AdminBaseController
$url = rtrim($this->grav['uri']->rootUrl(false), '/') . '/' . trim($this->admin->base, $url = rtrim($this->grav['uri']->rootUrl(false), '/') . '/' . trim($this->admin->base,
'/') . '/task' . $param_sep . 'backup/download' . $param_sep . $download . '/admin-nonce' . $param_sep . Utils::getNonce('admin-form'); '/') . '/task' . $param_sep . 'backup/download' . $param_sep . $download . '/admin-nonce' . $param_sep . Utils::getNonce('admin-form');
$this->admin->json_response = [ $this->admin->json_response = [
'status' => 'success', 'status' => 'success',
'message' => $this->admin::translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' . $this->admin::translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>', 'message' => $this->admin::translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' . $this->admin::translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>',
@@ -1382,7 +1380,7 @@ class AdminController extends AdminBaseController
$filename = basename(base64_decode(urldecode($backup))); $filename = basename(base64_decode(urldecode($backup)));
$file = $this->grav['locator']->findResource("backup://{$filename}", true); $file = $this->grav['locator']->findResource("backup://{$filename}", true);
if ($file) { if ($file && Utils::endsWith($filename, '.zip', false)) {
unlink($file); unlink($file);
$this->admin->json_response = [ $this->admin->json_response = [
@@ -1392,13 +1390,16 @@ class AdminController extends AdminBaseController
'closeButton' => true 'closeButton' => true
] ]
]; ];
} else {
$this->admin->json_response = [ return true;
'status' => 'error',
'message' => $this->admin::translate('PLUGIN_ADMIN.BACKUP_NOT_FOUND'),
];
} }
} }
$this->admin->json_response = [
'status' => 'error',
'message' => $this->admin::translate('PLUGIN_ADMIN.BACKUP_NOT_FOUND'),
];
return true; return true;
} }