Skip to content

Commit ef87e8c

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

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
@@ -453,10 +453,8 @@ public function logClientIn($user,
453453
return false;
454454
}
455455

456-
if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
457-
throw new PasswordLoginForbiddenException();
458-
}
459-
if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
456+
if (!$isTokenPassword && ($this->isTokenAuthEnforced() || $this->isTwoFactorEnforced($user))) {
457+
$this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
460458
throw new PasswordLoginForbiddenException();
461459
}
462460

@@ -636,7 +634,8 @@ public function tryBasicAuthLogin(IRequest $request,
636634
// If credentials were provided, they need to be valid, otherwise we do boom
637635
throw new LoginException();
638636
} catch (PasswordLoginForbiddenException $ex) {
639-
// Nothing to do
637+
// If credentials were provided, they need to be valid, otherwise we do boom
638+
throw new LoginException(previous: $ex);
640639
}
641640
}
642641
return false;

tests/lib/User/SessionTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public function testLogClientInNoTokenPasswordWith2fa() {
363363
->method('getRemoteAddress')
364364
->willReturn('192.168.0.1');
365365
$this->throttler
366-
->expects($this->once())
366+
->expects($this->exactly(2))
367367
->method('sleepDelayOrThrowOnMax')
368368
->with('192.168.0.1');
369369
$this->throttler
@@ -372,6 +372,15 @@ public function testLogClientInNoTokenPasswordWith2fa() {
372372
->with('192.168.0.1')
373373
->willReturn(0);
374374

375+
$this->throttler
376+
->expects($this->once())
377+
->method('registerAttempt')
378+
->with('login', '192.168.0.1', ['user' => 'john']);
379+
$this->dispatcher
380+
->expects($this->once())
381+
->method('dispatchTyped')
382+
->with(new LoginFailed('john', 'doe'));
383+
375384
$userSession->logClientIn('john', 'doe', $request, $this->throttler);
376385
}
377386

@@ -475,7 +484,7 @@ public function testLogClientInNoTokenPasswordNo2fa() {
475484
->method('getRemoteAddress')
476485
->willReturn('192.168.0.1');
477486
$this->throttler
478-
->expects($this->once())
487+
->expects($this->exactly(2))
479488
->method('sleepDelayOrThrowOnMax')
480489
->with('192.168.0.1');
481490
$this->throttler
@@ -484,6 +493,15 @@ public function testLogClientInNoTokenPasswordNo2fa() {
484493
->with('192.168.0.1')
485494
->willReturn(0);
486495

496+
$this->throttler
497+
->expects($this->once())
498+
->method('registerAttempt')
499+
->with('login', '192.168.0.1', ['user' => 'john']);
500+
$this->dispatcher
501+
->expects($this->once())
502+
->method('dispatchTyped')
503+
->with(new LoginFailed('john', 'doe'));
504+
487505
$userSession->logClientIn('john', 'doe', $request, $this->throttler);
488506
}
489507

0 commit comments

Comments
 (0)