Skip to content

Commit 352d0b3

Browse files
authored
fix buggy traversion detection code (hestiacp#2762)
* fix buggy traversion detection code ref hestiacp#2760 * same bug here, HESTIA_CMD is not a filepath/command its 2, sudo AND something else
1 parent befb6c8 commit 352d0b3

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

web/api/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
//die("Error: Disabled");
3+
define('HESTIA_DIR_BIN', '/usr/local/hestia/bin/');
34
define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
45

56
include($_SERVER['DOCUMENT_ROOT']."/inc/helpers.php");

web/download/web-log/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
$type = 'error';
2727
}
2828
$cmd = implode(" ", array(
29-
escapeshellarg(HESTIA_CMD . "v-list-web-domain-" . $type . "log"),
29+
'/usr/bin/sudo ' . escapeshellarg(HESTIA_DIR_BIN . "v-list-web-domain-" . $type . "log"),
3030
// $user is already shell-escaped
3131
$user,
3232
escapeshellarg($v_domain),
3333
"5000",
3434
));
35+
3536
passthru($cmd, $return_var);
3637
if ($return_var != 0) {
3738
$errstr = "Internal server error: command returned non-zero: {$return_var}: {$cmd}";

web/inc/main.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
require 'vendor/autoload.php';
1717

18+
define('HESTIA_DIR_BIN', '/usr/local/hestia/bin/');
1819
define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
1920
define('DEFAULT_PHP_VERSION', 'php-' . exec('php -r "echo substr(phpversion(),0,3);"'));
2021

web/src/app/System/HestiaApp.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public function __construct()
1616

1717
public function run(string $cmd, $args, &$cmd_result=null): bool
1818
{
19-
$cli_script = realpath(HESTIA_CMD . '/' . $cmd);
20-
if(!str_starts_with((string)$cli_script, HESTIA_CMD."/" )){
21-
$errstr = "$cmd is trying to traverse outside of " .HESTIA_CMD;
19+
$cli_script = realpath(HESTIA_DIR_BIN . $cmd);
20+
if (!str_starts_with((string) $cli_script, HESTIA_DIR_BIN)) {
21+
$errstr = "$cmd is trying to traverse outside of " . HESTIA_DIR_BIN;
2222
trigger_error($errstr);
23-
throw new \Exception($errstr);
23+
throw new \Exception($errstr);
2424
}
25-
$cli_script = escapeshellarg($cli_script);
25+
$cli_script = '/usr/bin/sudo ' . escapeshellarg($cli_script);
2626

2727
if (!empty($args) && is_array($args)) {
2828
foreach ($args as $arg) {

0 commit comments

Comments
 (0)