Skip to content

Commit 47bb827

Browse files
authored
Merge pull request #63830 from nextcloud/backport/63825/stable24
[stable24] fix(2fa): Add missing BruteForceProtection attribute
2 parents ab55fcc + 5b086c2 commit 47bb827

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

core/Controller/TwoFactorChallengeController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public function showChallenge($challengeProviderId, $redirect_url) {
184184
* @TwoFactorSetUpDoneRequired
185185
*
186186
* @UserRateThrottle(limit=5, period=100)
187+
* @BruteForceProtection(action=solveChallenge)
187188
*
188189
* @param string $challengeProviderId
189190
* @param string $challenge
@@ -217,10 +218,12 @@ public function solveChallenge($challengeProviderId, $challenge, $redirect_url =
217218
$uid = $user->getUID();
218219
$this->logger->warning("Two-factor challenge failed: $uid (Remote IP: $ip)");
219220
$this->session->set('two_factor_auth_error', true);
220-
return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
221+
$response = new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
221222
'challengeProviderId' => $provider->getId(),
222223
'redirect_url' => $redirect_url,
223224
]));
225+
$response->throttle(['user' => $uid, 'provider' => $challengeProviderId]);
226+
return $response;
224227
}
225228

226229
/**

tests/Core/Controller/TwoFactorChallengeControllerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ public function testSolveChallengeInvalidProvider() {
268268

269269
public function testSolveInvalidChallenge() {
270270
$user = $this->createMock(IUser::class);
271+
$user->method('getUID')->willReturn('myuser');
271272
$provider = $this->createMock(IProvider::class);
272273

273274
$this->userSession->expects($this->once())
@@ -297,11 +298,13 @@ public function testSolveInvalidChallenge() {
297298
->willReturn('myprovider');
298299

299300
$expected = new RedirectResponse('files/index/url');
301+
$expected->throttle(['user' => 'myuser', 'provider' => 'myprovider']);
300302
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', '/url'));
301303
}
302304

303305
public function testSolveChallengeTwoFactorException() {
304306
$user = $this->createMock(IUser::class);
307+
$user->method('getUID')->willReturn('myuser');
305308
$provider = $this->createMock(IProvider::class);
306309
$exception = new TwoFactorException("2FA failed");
307310

@@ -335,6 +338,7 @@ public function testSolveChallengeTwoFactorException() {
335338
->willReturn('myprovider');
336339

337340
$expected = new RedirectResponse('files/index/url');
341+
$expected->throttle(['user' => 'myuser', 'provider' => 'myprovider']);
338342
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', '/url'));
339343
}
340344

0 commit comments

Comments
 (0)