Skip to content

Commit 708f97a

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

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
@@ -449,10 +449,8 @@ public function logClientIn($user,
449449
return false;
450450
}
451451

452-
if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
453-
throw new PasswordLoginForbiddenException();
454-
}
455-
if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
452+
if (!$isTokenPassword && ($this->isTokenAuthEnforced() || $this->isTwoFactorEnforced($user))) {
453+
$this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
456454
throw new PasswordLoginForbiddenException();
457455
}
458456

@@ -632,7 +630,8 @@ public function tryBasicAuthLogin(IRequest $request,
632630
// If credentials were provided, they need to be valid, otherwise we do boom
633631
throw new LoginException();
634632
} catch (PasswordLoginForbiddenException $ex) {
635-
// Nothing to do
633+
// If credentials were provided, they need to be valid, otherwise we do boom
634+
throw new LoginException(previous: $ex);
636635
}
637636
}
638637
return false;

tests/lib/User/SessionTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public function testLogClientInNoTokenPasswordWith2fa() {
361361
->method('getRemoteAddress')
362362
->willReturn('192.168.0.1');
363363
$this->throttler
364-
->expects($this->once())
364+
->expects($this->exactly(2))
365365
->method('sleepDelayOrThrowOnMax')
366366
->with('192.168.0.1');
367367
$this->throttler
@@ -370,6 +370,15 @@ public function testLogClientInNoTokenPasswordWith2fa() {
370370
->with('192.168.0.1')
371371
->willReturn(0);
372372

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

@@ -473,7 +482,7 @@ public function testLogClientInNoTokenPasswordNo2fa() {
473482
->method('getRemoteAddress')
474483
->willReturn('192.168.0.1');
475484
$this->throttler
476-
->expects($this->once())
485+
->expects($this->exactly(2))
477486
->method('sleepDelayOrThrowOnMax')
478487
->with('192.168.0.1');
479488
$this->throttler
@@ -482,6 +491,15 @@ public function testLogClientInNoTokenPasswordNo2fa() {
482491
->with('192.168.0.1')
483492
->willReturn(0);
484493

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

0 commit comments

Comments
 (0)