mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
Enforce TOTP policy for XML-RPC login (#1131)
if a user/mailbox has TOTP enabled, block access via XMLRPC (if it's enabled) as the two aren't compatible. Part of #1128. thanks @TrapoSAMA
This commit is contained in:
1 parent
54be5e3828
commit
2c8a8893e9
4 files changed
+34
-1
No files matched your search
@@ -790,6 +790,8 @@ $CONF['theme_custom_css'] = '';
|
||||
// XMLRPC Interface.
|
||||
// This should be only of use if you wish to use e.g the
|
||||
// Postfixadmin-Squirrelmail package
|
||||
// XML-RPC has no TOTP challenge flow. Mailbox accounts with a TOTP
|
||||
// secret cannot authenticate through this interface.
|
||||
// change to boolean true to enable xmlrpc
|
||||
$CONF['xmlrpc_enabled'] = false;
|
||||
|
||||
|
||||
@@ -133,6 +133,18 @@ class TotpPf
|
||||
return (is_array($result) && isset($result['totp_secret']) && !empty($result['totp_secret']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate an interface that cannot complete a TOTP challenge.
|
||||
*/
|
||||
public function passwordOnlyLogin(string $username, string $password): bool
|
||||
{
|
||||
if (!$this->login->login($username, $password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !$this->usesTOTP($username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a TOTP code is valid for a user
|
||||
*/
|
||||
|
||||
+2
-1
@@ -48,7 +48,8 @@ $server = new Zend_XmlRpc_Server();
|
||||
function login($username, $password)
|
||||
{
|
||||
$login = new Login('mailbox');
|
||||
if ($login->login($username, $password)) {
|
||||
$totp = new TotpPf('mailbox', $login);
|
||||
if ($totp->passwordOnlyLogin($username, $password)) {
|
||||
session_regenerate_id();
|
||||
$_SESSION['authenticated'] = true;
|
||||
$_SESSION['sessid'] = array();
|
||||
|
||||
@@ -76,6 +76,24 @@ class TotpPfTest extends TestCase
|
||||
$this->assertNotEmpty($currentCode);
|
||||
}
|
||||
|
||||
public function testPasswordOnlyLoginRejectsAccountsUsingTotp(): void
|
||||
{
|
||||
global $CONF;
|
||||
Config::write('totp', 'YES');
|
||||
$CONF['totp'] = 'YES';
|
||||
|
||||
$totp = new TotpPf('mailbox', new Login('mailbox'));
|
||||
$this->assertTrue($totp->passwordOnlyLogin('test@example.com', 'foobar'));
|
||||
|
||||
db_execute(
|
||||
'UPDATE mailbox SET totp_secret = :secret WHERE username = :username',
|
||||
['username' => 'test@example.com', 'secret' => 'existing-secret']
|
||||
);
|
||||
|
||||
$this->assertFalse($totp->passwordOnlyLogin('test@example.com', 'foobar'));
|
||||
$this->assertFalse($totp->passwordOnlyLogin('test@example.com', 'incorrect-password'));
|
||||
}
|
||||
|
||||
public function testDbOperations()
|
||||
{
|
||||
$x = new TotpPf('mailbox', new Login('mailbox'));
|
||||
|
||||
Reference in new issue
Block a user