Skip to content

Commit dcbf871

Browse files
come-ncbackportbot[bot]
authored andcommitted
fix(2fa): Add missing BruteForceProtection attribute
fix(2fa): Add missing BruteForceProtection attribute Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> [skip ci]
1 parent df86f04 commit dcbf871

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
@@ -10,6 +10,7 @@
1010
use OC\Authentication\TwoFactorAuth\Manager;
1111
use OC_User;
1212
use OCP\AppFramework\Controller;
13+
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
1314
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
1415
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1516
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
@@ -189,10 +190,12 @@ public function solveChallenge($challengeProviderId, $challenge, $redirect_url =
189190
$uid = $user->getUID();
190191
$this->logger->warning("Two-factor challenge failed: $uid (Remote IP: $ip)");
191192
$this->session->set('two_factor_auth_error', true);
192-
return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
193+
$response = new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
193194
'challengeProviderId' => $provider->getId(),
194195
'redirect_url' => $redirect_url,
195196
]));
197+
$response->throttle(['user' => $uid, 'provider' => $challengeProviderId]);
198+
return $response;
196199
}
197200

198201
#[NoAdminRequired]

tests/Core/Controller/TwoFactorChallengeControllerTest.php

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

254254
public function testSolveInvalidChallenge(): void {
255255
$user = $this->createMock(IUser::class);
256+
$user->method('getUID')->willReturn('myuser');
256257
$provider = $this->createMock(IProvider::class);
257258

258259
$this->userSession->expects($this->once())
@@ -282,11 +283,13 @@ public function testSolveInvalidChallenge(): void {
282283
->willReturn('myprovider');
283284

284285
$expected = new RedirectResponse('files/index/url');
286+
$expected->throttle(['user' => 'myuser', 'provider' => 'myprovider']);
285287
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', '/url'));
286288
}
287289

288290
public function testSolveChallengeTwoFactorException(): void {
289291
$user = $this->createMock(IUser::class);
292+
$user->method('getUID')->willReturn('myuser');
290293
$provider = $this->createMock(IProvider::class);
291294
$exception = new TwoFactorException('2FA failed');
292295

@@ -324,6 +327,7 @@ public function testSolveChallengeTwoFactorException(): void {
324327
->willReturn('myprovider');
325328

326329
$expected = new RedirectResponse('files/index/url');
330+
$expected->throttle(['user' => 'myuser', 'provider' => 'myprovider']);
327331
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', '/url'));
328332
}
329333

0 commit comments

Comments
 (0)