mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
FIX: Restrict administrator TOTP self-exceptions to managed domains (#1201)
A domain administrator managing foo.com/bar.com could create a TOTP exception for their own login at example.com without managing example.com. see also discussion on https://github.com/postfixadmin/postfixadmin/pull/1188
This commit is contained in:
1 parent
bff07294dd
commit
fda66026ca
4 files changed
+46
-10
No files matched your search
@@ -8,6 +8,7 @@
|
||||
|
||||
Changes in 'master' (not in a release yet) (20XX/XX/XX)
|
||||
--------------------------
|
||||
- Enforce managed-domain authorization for administrator TOTP self-exceptions, including partial edits.
|
||||
- Follow up security search filtering, password-recovery messages and password confirmation for TOTP exception forms.
|
||||
- Populate TOTP actions for each returned administrator or mailbox and handle empty account lists.
|
||||
- Open expanded navigation dropdowns on mouse hover while retaining click, touch and keyboard controls.
|
||||
|
||||
+1
-1
@@ -317,7 +317,7 @@ class TotpPf
|
||||
}
|
||||
|
||||
// Ensure admin has access to the domain of the exception
|
||||
if ($exception_username != $username && !in_array($Exception_domain, $domains)) {
|
||||
if (!in_array($Exception_domain, $domains)) {
|
||||
throw new \Exception(Config::Lang('pException_user_entire_domain_error'));
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -110,6 +110,10 @@ class TotpexceptionHandler extends PFAHandler
|
||||
$password = '';
|
||||
}
|
||||
$this->checkCurrentPassword($password);
|
||||
// Partial edits must authorize the stored target as well as submitted targets.
|
||||
if ($this->is_admin && !$this->new && !isset($values['username'])) {
|
||||
$this->_validate_username('username', (string)($this->result['username'] ?? ''));
|
||||
}
|
||||
if (!$this->is_admin) {
|
||||
$this->values['username'] = $this->username;
|
||||
}
|
||||
@@ -186,11 +190,6 @@ class TotpexceptionHandler extends PFAHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
// Match TotpPf::addException(): an administrator may exempt their own login.
|
||||
if ($value === $this->admin_username) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Admins can set for users/domains they manage
|
||||
if (strpos($value, '@')) {
|
||||
list($_, $exception_domain) = explode('@', $value);
|
||||
|
||||
@@ -211,7 +211,7 @@ class TotpexceptionHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertSame([], $this->storedUsernames());
|
||||
}
|
||||
|
||||
public function testAdminSelfExceptionDoesNotAuthorizeItsUnmanagedDomain(): void
|
||||
public function testAdminCannotExemptSelfOutsideManagedDomains(): void
|
||||
{
|
||||
foreach (['foo.com', 'bar.com'] as $domain) {
|
||||
db_insert('domain', ['domain' => $domain, 'description' => 'managed',
|
||||
@@ -220,7 +220,7 @@ class TotpexceptionHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
'domain' => $domain, 'active' => true], ['created'], true);
|
||||
}
|
||||
$this->asAdmin();
|
||||
$targets = ['admin@example.com' => true, 'foo.com' => true, 'user@foo.com' => true,
|
||||
$targets = ['admin@example.com' => false, 'foo.com' => true, 'user@foo.com' => true,
|
||||
'user@bar.com' => true, 'example.com' => false, 'other@example.com' => false];
|
||||
foreach ($targets as $target => $allowed) {
|
||||
$handler = new TotpexceptionHandler(1, 'admin@example.com', 1);
|
||||
@@ -229,9 +229,45 @@ class TotpexceptionHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
'username' => $target, 'ip' => '192.0.2.20', 'description' => 'scope check']), $target);
|
||||
}
|
||||
$totp = new TotpPf('admin', new Login('admin'));
|
||||
try {
|
||||
$totp->addException('admin@example.com', 'admin-password',
|
||||
'192.0.2.21', 'admin@example.com', 'unmanaged self exception');
|
||||
$this->fail('An administrator must not exempt an unmanaged own login');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertSame(Config::lang('pException_user_entire_domain_error'), $e->getMessage());
|
||||
}
|
||||
$this->assertSame([], $this->storedUsernames());
|
||||
}
|
||||
|
||||
public function testAdminCanExemptSelfInManagedDomain(): void
|
||||
{
|
||||
db_insert('domain_admins', ['username' => 'admin@example.com',
|
||||
'domain' => 'example.com', 'active' => true], ['created'], true);
|
||||
$this->asAdmin();
|
||||
$handler = new TotpexceptionHandler(1, 'admin@example.com', 1);
|
||||
$this->assertTrue($handler->init(''));
|
||||
$this->assertTrue($handler->set(['password_current' => 'admin-password',
|
||||
'username' => 'admin@example.com', 'ip' => '192.0.2.22', 'description' => 'managed self']));
|
||||
$this->assertTrue($handler->save());
|
||||
$totp = new TotpPf('admin', new Login('admin'));
|
||||
$this->assertTrue($totp->addException('admin@example.com', 'admin-password',
|
||||
'192.0.2.21', 'admin@example.com', 'existing dedicated-page contract'));
|
||||
$this->assertSame(['admin@example.com'], $this->storedUsernames());
|
||||
'192.0.2.23', 'admin@example.com', 'managed self via dedicated page'));
|
||||
$this->assertSame(['admin@example.com', 'admin@example.com'], $this->storedUsernames());
|
||||
}
|
||||
|
||||
public function testAdminCannotEditUnmanagedSelfExceptionByOmittingTarget(): void
|
||||
{
|
||||
db_insert('totp_exception_address', ['username' => 'admin@example.com',
|
||||
'ip' => '192.0.2.24', 'description' => 'existing exception'], ['created', 'modified'], true);
|
||||
$row = db_query_one('SELECT id FROM totp_exception_address');
|
||||
$this->asAdmin();
|
||||
$handler = new TotpexceptionHandler(0, 'admin@example.com', 1);
|
||||
$this->assertTrue($handler->init((string)$row['id']));
|
||||
foreach ([[], ['username' => null]] as $target) {
|
||||
$this->assertFalse($handler->set($target + ['password_current' => 'admin-password', 'ip' => '192.0.2.25']));
|
||||
$this->assertFalse($handler->save());
|
||||
}
|
||||
$this->assertSame('192.0.2.24', db_query_one('SELECT ip FROM totp_exception_address')['ip']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user