mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
Someone wishing to remain anonymous emailed @cboltz a number of security issues, summarised below. 1. fix sql injection bug in getPageBrowser - search keys bypass the field filter, due to2a6f27c3/ #1127 2. when performing a password change, do not start the session before the new password has been validated for compexity etc - as things stand someone with a recovery code gets logged in even if their password gets rejected. Also invalid recovery code on failure. 3. broadcast-message.php was using smtp_mail() with incorrect args, and passing the SMTP password in as the mail body. - probably related to commit7f1d78eand42a664e9c24. a regular (non-admin) user could submit an arbitrary username in the POST data and create/edit a TOTP exception for another user or entire domain PR includes refactoring of the password change code (into PasswordChangeAttempt) to make it easier to test/verify.
53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Attempts to change a user's/admin's forgotten password via a recovery code.
|
|
*
|
|
* Never wipes the recovery code unless the new password was actually validated
|
|
* and persisted - callers must only create a session (via init_session()) when
|
|
* $result['success'] is true.
|
|
*/
|
|
class PasswordChangeAttempt
|
|
{
|
|
/**
|
|
* @param MailboxHandler|AdminHandler $handler - the only two PFAHandler subclasses
|
|
* that represent an account with a login/recovery code; any other handler
|
|
* wouldn't have a meaningful checkPasswordRecoveryCode()/save() flow here.
|
|
* @return array{success: bool, errors: string[]}
|
|
*/
|
|
public static function run(
|
|
MailboxHandler|AdminHandler $handler,
|
|
TotpPf $totppf,
|
|
string $username,
|
|
string $code,
|
|
string $totpCode,
|
|
string $password,
|
|
string $password2
|
|
): array {
|
|
if (!$handler->checkPasswordRecoveryCode($username, $code)) {
|
|
return ['success' => false, 'errors' => [Config::lang('pPassword_code_text_error')]];
|
|
}
|
|
|
|
if ($totppf->usesTOTP($username) && !$totppf->checkUserTOTP($username, $totpCode)) {
|
|
return ['success' => false, 'errors' => [Config::lang('pTotp_failed')]];
|
|
}
|
|
|
|
if (!$handler->init($username)) {
|
|
return ['success' => false, 'errors' => $handler->errormsg];
|
|
}
|
|
|
|
$values = $handler->result;
|
|
$values['password'] = $password;
|
|
$values['password2'] = $password2;
|
|
|
|
if (!($handler->set($values) && $handler->save())) {
|
|
return ['success' => false, 'errors' => $handler->errormsg];
|
|
}
|
|
|
|
$handler->wipePasswordRecoveryCode($username);
|
|
|
|
// $handler->errormsg will most likely be an empty array
|
|
return ['success' => true, 'errors' => $handler->errormsg];
|
|
}
|
|
}
|