Skip to content

Commit 11c511c

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

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
@@ -459,10 +459,8 @@ public function logClientIn($user,
459459
return false;
460460
}
461461

462-
if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
463-
throw new PasswordLoginForbiddenException();
464-
}
465-
if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
462+
if (!$isTokenPassword && ($this->isTokenAuthEnforced() || $this->isTwoFactorEnforced($user))) {
463+
$this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
466464
throw new PasswordLoginForbiddenException();
467465
}
468466

@@ -634,7 +632,8 @@ public function tryBasicAuthLogin(IRequest $request,
634632
// If credentials were provided, they need to be valid, otherwise we do boom
635633
throw new LoginException();
636634
} catch (PasswordLoginForbiddenException $ex) {
637-
// Nothing to do
635+
// If credentials were provided, they need to be valid, otherwise we do boom
636+
throw new LoginException(previous: $ex);
638637
}
639638
}
640639
return false;

tests/lib/User/SessionTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public function testLogClientInNoTokenPasswordWith2fa() {
449449
->method('getRemoteAddress')
450450
->willReturn('192.168.0.1');
451451
$this->throttler
452-
->expects($this->once())
452+
->expects($this->exactly(2))
453453
->method('sleepDelayOrThrowOnMax')
454454
->with('192.168.0.1');
455455
$this->throttler
@@ -458,6 +458,15 @@ public function testLogClientInNoTokenPasswordWith2fa() {
458458
->with('192.168.0.1')
459459
->willReturn(0);
460460

461+
$this->throttler
462+
->expects($this->once())
463+
->method('registerAttempt')
464+
->with('login', '192.168.0.1', ['user' => 'john']);
465+
$this->dispatcher
466+
->expects($this->once())
467+
->method('dispatchTyped')
468+
->with(new LoginFailed('john', 'doe'));
469+
461470
$userSession->logClientIn('john', 'doe', $request, $this->throttler);
462471
}
463472

@@ -561,7 +570,7 @@ public function testLogClientInNoTokenPasswordNo2fa() {
561570
->method('getRemoteAddress')
562571
->willReturn('192.168.0.1');
563572
$this->throttler
564-
->expects($this->once())
573+
->expects($this->exactly(2))
565574
->method('sleepDelayOrThrowOnMax')
566575
->with('192.168.0.1');
567576
$this->throttler
@@ -570,6 +579,15 @@ public function testLogClientInNoTokenPasswordNo2fa() {
570579
->with('192.168.0.1')
571580
->willReturn(0);
572581

582+
$this->throttler
583+
->expects($this->once())
584+
->method('registerAttempt')
585+
->with('login', '192.168.0.1', ['user' => 'john']);
586+
$this->dispatcher
587+
->expects($this->once())
588+
->method('dispatchTyped')
589+
->with(new LoginFailed('john', 'doe'));
590+
573591
$userSession->logClientIn('john', 'doe', $request, $this->throttler);
574592
}
575593

0 commit comments

Comments
 (0)