Skip to content

Commit 126cc0c

Browse files
nickvergessenbackportbot[bot]
authored andcommitted
fix: Handle 2fa enforcement earlier
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent e0281be commit 126cc0c

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

lib/private/User/Session.php

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

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

@@ -586,7 +584,8 @@ public function tryBasicAuthLogin(IRequest $request,
586584
// If credentials were provided, they need to be valid, otherwise we do boom
587585
throw new LoginException();
588586
} catch (PasswordLoginForbiddenException $ex) {
589-
// Nothing to do
587+
// If credentials were provided, they need to be valid, otherwise we do boom
588+
throw new LoginException(previous: $ex);
590589
}
591590
}
592591
return false;

tests/lib/User/SessionTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public function testLogClientInNoTokenPasswordWith2fa() {
441441
->method('getRemoteAddress')
442442
->willReturn('192.168.0.1');
443443
$this->throttler
444-
->expects($this->once())
444+
->expects($this->exactly(2))
445445
->method('sleepDelayOrThrowOnMax')
446446
->with('192.168.0.1');
447447
$this->throttler
@@ -450,6 +450,15 @@ public function testLogClientInNoTokenPasswordWith2fa() {
450450
->with('192.168.0.1')
451451
->willReturn(0);
452452

453+
$this->throttler
454+
->expects($this->once())
455+
->method('registerAttempt')
456+
->with('login', '192.168.0.1', ['user' => 'john']);
457+
$this->dispatcher
458+
->expects($this->once())
459+
->method('dispatchTyped')
460+
->with(new LoginFailed('john', 'doe'));
461+
453462
$userSession->logClientIn('john', 'doe', $request, $this->throttler);
454463
}
455464

@@ -553,7 +562,7 @@ public function testLogClientInNoTokenPasswordNo2fa() {
553562
->method('getRemoteAddress')
554563
->willReturn('192.168.0.1');
555564
$this->throttler
556-
->expects($this->once())
565+
->expects($this->exactly(2))
557566
->method('sleepDelayOrThrowOnMax')
558567
->with('192.168.0.1');
559568
$this->throttler
@@ -562,6 +571,15 @@ public function testLogClientInNoTokenPasswordNo2fa() {
562571
->with('192.168.0.1')
563572
->willReturn(0);
564573

574+
$this->throttler
575+
->expects($this->once())
576+
->method('registerAttempt')
577+
->with('login', '192.168.0.1', ['user' => 'john']);
578+
$this->dispatcher
579+
->expects($this->once())
580+
->method('dispatchTyped')
581+
->with(new LoginFailed('john', 'doe'));
582+
565583
$userSession->logClientIn('john', 'doe', $request, $this->throttler);
566584
}
567585

0 commit comments

Comments
 (0)