Skip to content

Commit 072ba5b

Browse files
authored
Fix Password reset function (hestiacp#3112)
* Fix Password reset function - Solve also: https://huntr.dev/bounties/db753013-8feb-4bc8-b053-6faa58058f43/ * Improve error message
1 parent 3813d17 commit 072ba5b

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

web/reset/index.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
unset($output);
3030
exec(HESTIA_CMD . "v-get-user-value " . $v_user . " RKEYEXP", $output, $return_var);
3131
$rkeyexp = json_decode(implode("", $output), true);
32-
if ($rkeyexp === null || $rkeyexp < time() - 900) {
32+
if ($rkeyexp === null || $rkeyexp < time() - 1) {
3333
if ($email == $data[$user]["CONTACT"]) {
3434
$rkey = substr(password_hash("", PASSWORD_DEFAULT), 8, 12);
3535
$hash = password_hash($rkey, PASSWORD_DEFAULT);
@@ -49,6 +49,16 @@
4949
$to = $data[$user]["CONTACT"];
5050
$subject = sprintf(_("MAIL_RESET_SUBJECT"), date("Y-m-d H:i:s"));
5151
$hostname = get_hostname();
52+
if ($hostname . ":" . $_SERVER["SERVER_PORT"] == $_SERVER["HTTP_HOST"]) {
53+
$check = true;
54+
$hostname_email = $hostname;
55+
} elseif ($hostname_full . ":" . $_SERVER["SERVER_PORT"] == $_SERVER["HTTP_HOST"]) {
56+
$check = true;
57+
$hostname_email = $hostname_full;
58+
} else {
59+
$check = false;
60+
$ERROR = "<p class=\"error\">" . _("Invalid host domain") . "</p>";
61+
}
5262
if ($check == true) {
5363
$from = "noreply@" . $hostname;
5464
$from_name = _("Hestia Control Panel");
@@ -76,16 +86,36 @@
7686
$data[$user]["NAME"],
7787
);
7888
}
79-
header("Location: /reset/?action=code&user=" . $_POST["user"]);
80-
exit();
89+
$ERROR =
90+
"<p class=\"error\">" .
91+
_(
92+
"Password reset instructions have been sent to the email address associated with this account.",
93+
) .
94+
"</p>";
8195
}
96+
} else {
97+
# Prevent user enumeration and let hackers guess username and working email
98+
$ERROR =
99+
"<p class=\"error\">" .
100+
_(
101+
"Password reset instructions have been sent to the email address associated with this account.",
102+
) .
103+
"</p>";
82104
}
83105
} else {
84106
$ERROR =
85107
"<p class=\"error\">" .
86108
_("Please wait 15 minutes before sending a new request") .
87109
"</p>";
88110
}
111+
} else {
112+
# Prevent user enumeration and let hackers guess username and working email
113+
$ERROR =
114+
"<p class=\"error\">" .
115+
_(
116+
"Password reset instructions have been sent to the email address associated with this account.",
117+
) .
118+
"</p>";
89119
}
90120
unset($output);
91121
}

0 commit comments

Comments
 (0)