Skip to content

Commit 6d4424a

Browse files
committed
fix: Handle 2fa enforcement earlier
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 1040591 commit 6d4424a

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

lib/private/User/Session.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,8 @@ public function logClientIn($user,
403403
return false;
404404
}
405405

406-
if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
407-
throw new PasswordLoginForbiddenException();
408-
}
409-
if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
406+
if (!$isTokenPassword && ($this->isTokenAuthEnforced() || $this->isTwoFactorEnforced($user))) {
407+
$this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
410408
throw new PasswordLoginForbiddenException();
411409
}
412410

@@ -576,7 +574,8 @@ public function tryBasicAuthLogin(IRequest $request,
576574
// If credentials were provided, they need to be valid, otherwise we do boom
577575
throw new LoginException();
578576
} catch (PasswordLoginForbiddenException $ex) {
579-
// Nothing to do
577+
// If credentials were provided, they need to be valid, otherwise we do boom
578+
throw new LoginException(previous: $ex);
580579
}
581580
}
582581
return false;

tests/lib/User/SessionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public function testLogClientInNoTokenPasswordWith2fa(): void {
439439
->method('getRemoteAddress')
440440
->willReturn('192.168.0.1');
441441
$this->throttler
442-
->expects($this->once())
442+
->expects($this->exactly(2))
443443
->method('sleepDelayOrThrowOnMax')
444444
->with('192.168.0.1');
445445
$this->throttler
@@ -550,7 +550,7 @@ public function testLogClientInNoTokenPasswordNo2fa(): void {
550550
->method('getRemoteAddress')
551551
->willReturn('192.168.0.1');
552552
$this->throttler
553-
->expects($this->once())
553+
->expects($this->exactly(2))
554554
->method('sleepDelayOrThrowOnMax')
555555
->with('192.168.0.1');
556556
$this->throttler

0 commit comments

Comments
 (0)