Skip to content

Commit 8613f15

Browse files
authored
Limit path to HESTIA_CMD dir only (hestiacp#2742)
* Limit path to HESTIA_CMD dir only * Make suggested changes
1 parent fc10af5 commit 8613f15

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

web/src/app/System/HestiaApp.php

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

1717
public function run(string $cmd, $args, &$cmd_result=null): bool
1818
{
19-
$cli_script = HESTIA_CMD . '/' . basename($cmd);
20-
$cli_arguments = '';
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;
22+
trigger_error($errstr);
23+
throw new \Exception($errstr);
24+
}
25+
$cli_script = escapeshellarg($cli_script);
2126

2227
if (!empty($args) && is_array($args)) {
2328
foreach ($args as $arg) {

0 commit comments

Comments
 (0)