Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ public function checkPassword($loginName, $password) {
* @return IUser|false the User object on success, false otherwise
*/
public function checkPasswordNoLogging($loginName, $password) {
$loginName = str_replace("\0", '', $loginName);
// A NUL byte in the login name must not turn it into a second name for an
// account: the checks done before the password check (e.g. 2FA enforcement
// in Session::logClientIn()) see the name as sent, so the name has to stay the same
if (str_contains($loginName, "\0")) {
return false;
}
$password = str_replace("\0", '', $password);

$cachedBackend = $this->cache->get($loginName);
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ public function testCheckPasswordNotSupported(): void {
$this->assertFalse($this->manager->checkPassword('foo', 'bar'));
}

public function testCheckPasswordNullByteInLoginName(): void {
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('checkPassword');

$backend->expects($this->any())
->method('implementsActions')
->willReturnCallback(function ($actions) {
if ($actions === BACKEND::CHECK_PASSWORD) {
return true;
} else {
return false;
}
});

$this->manager->registerBackend($backend);

$this->assertFalse($this->manager->checkPassword("foo\0", 'bar'));
}

public function testGetOneBackendExists(): void {
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
Expand Down
Loading