Skip to content

Commit 974b646

Browse files
authored
swith fopen with tmpfile (hestiacp#2958)
* swith fopen with tmpfile as pointed out by knurry81, using fopen here might be a bad idea, fopen defaults to chmod 0644, which is world-readable, while tmpfile defaults to 0600, only hestiacp user can read tmpfile * tmpfile + quoteshellarg
1 parent 8ba8ece commit 974b646

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

web/api/index.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ function api_legacy(array $request_data) {
9595
$hash = str_replace('$rounds=5000', '', $hash);
9696
}
9797
if ($method == 'yescrypt') {
98-
$v_password = tempnam("/tmp", "vst");
99-
$fp = fopen($v_password, "w");
98+
$fp = tmpfile();
99+
$v_password = stream_get_meta_data($fp)['uri'];
100100
fwrite($fp, $password."\n");
101-
fclose($fp);
102101
unset($output);
103-
exec(HESTIA_CMD . 'v-check-user-password "admin" '. $password. ' '.$v_ip.' yes', $output, $return_var);
102+
exec(HESTIA_CMD . 'v-check-user-password "admin" '. quoteshellarg($v_password). ' '.$v_ip.' yes', $output, $return_var);
104103
$hash = $output[0];
105-
unset($output);
104+
fclose($fp);
105+
unset($output, $fp, $v_password);
106106
}
107107
if ($method == 'des') {
108108
$hash = crypt($password, $salt);

web/login/index.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ function authenticate_user($user, $password, $twofa = '')
130130
$hash = str_replace('$rounds=5000', '', $hash);
131131
}
132132
if ($method == 'yescrypt') {
133-
$v_password = tempnam("/tmp", "vst");
134-
$fp = fopen($v_password, "w");
133+
$fp = tmpfile();
134+
$v_password = stream_get_meta_data($fp)['uri'];
135135
fwrite($fp, $password."\n");
136-
fclose($fp);
137-
exec(HESTIA_CMD . 'v-check-user-password '. $v_user.' '. $v_password. ' '.$v_ip.' yes', $output, $return_var);
136+
exec(HESTIA_CMD . 'v-check-user-password '. $v_user.' '. quoteshellarg($v_password). ' '.$v_ip.' yes', $output, $return_var);
138137
$hash = $output[0];
139-
unset($output);
138+
fclose($fp);
139+
unset($output,$fp, $v_password);
140140
}
141141
if ($method == 'des') {
142142
$hash = crypt($password, $salt);

0 commit comments

Comments
 (0)