Skip to content

Commit 4df2132

Browse files
committed
webui add missing token validation
(cherry picked from commit 0879588)
1 parent db2e842 commit 4df2132

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

web/upload/UploadHandler.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ function __construct($options = null, $initialize = true, $error_messages = null
9292
'Content-Range',
9393
'Content-Disposition'
9494
),
95+
// By default, allow redirects to the referer protocol+host:
96+
'redirect_allow_target' => '/^'.preg_quote(
97+
parse_url($_SERVER['HTTP_REFERER'], PHP_URL_SCHEME)
98+
.'://'
99+
.parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)
100+
.'/', // Trailing slash to not match subdomains by mistake
101+
'/' // preg_quote delimiter param
102+
).'/',
95103
// Enable to provide file downloads via GET requests to the PHP script:
96104
// 1. Set to 1 to download files via readfile method through PHP
97105
// 2. Set to 2 to send a X-Sendfile header for lighttpd/Apache
@@ -1118,7 +1126,7 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
11181126
$file->size > $this->get_file_size($file_path);
11191127
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
11201128
chmod($uploaded_file, 0644);
1121-
exec (HESTIA_CMD . "v-copy-fs-file ". USERNAME ." {$uploaded_file} '{$file_path}'", $output, $return_var);
1129+
exec (HESTIA_CMD . "v-copy-fs-file ".escapeshellarg(USERNAME)." ".escapeshellarg($uploaded_file)." ".escapeshellarg($file_path), $output, $return_var);
11221130
$error = check_return_code($return_var, $output);
11231131
if ($return_var != 0) {
11241132
$file->error = 'Error while saving file ';
@@ -1177,7 +1185,7 @@ protected function generate_response($content, $print_response = true) {
11771185
$json = json_encode($content);
11781186
$redirect = isset($_REQUEST['redirect']) ?
11791187
stripslashes($_REQUEST['redirect']) : null;
1180-
if ($redirect) {
1188+
if ($redirect && preg_match($this->options['redirect_allow_target'], $redirect)) {
11811189
$this->header('Location: '.sprintf($redirect, rawurlencode($json)));
11821190
return;
11831191
}
@@ -1377,6 +1385,14 @@ public function post($print_response = true) {
13771385
);
13781386
}
13791387

1388+
private function _cmd_v_delete_fs_file($file) {
1389+
if (empty($file)) {
1390+
return false;
1391+
}
1392+
exec (HESTIA_CMD . "v-delete-fs-file ".escapeshellarg(USERNAME)." ".escapeshellarg($file), $output, $return_var);
1393+
return ($return_var === 0);
1394+
}
1395+
13801396
public function delete($print_response = true) {
13811397
$file_names = $this->get_file_names_params();
13821398
if (empty($file_names)) {
@@ -1385,13 +1401,13 @@ public function delete($print_response = true) {
13851401
$response = array();
13861402
foreach($file_names as $file_name) {
13871403
$file_path = $this->get_upload_path($file_name);
1388-
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
1404+
$success = is_file($file_path) && $file_name[0] !== '.' && $this->_cmd_v_delete_fs_file($file_path);
13891405
if ($success) {
13901406
foreach($this->options['image_versions'] as $version => $options) {
13911407
if (!empty($version)) {
13921408
$file = $this->get_upload_path($file_name, $version);
13931409
if (is_file($file)) {
1394-
unlink($file);
1410+
$this->_cmd_v_delete_fs_file($file);
13951411
}
13961412
}
13971413
}

0 commit comments

Comments
 (0)