Skip to content

Commit 07b538d

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

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

core/Controller/TwoFactorChallengeController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OC\Authentication\TwoFactorAuth\Manager;
1313
use OC_User;
1414
use OCP\AppFramework\Controller;
15+
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
1516
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
1617
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1718
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
@@ -145,6 +146,7 @@ public function showChallenge(string $challengeProviderId, ?string $redirect_url
145146
#[FrontpageRoute(verb: 'POST', url: '/login/challenge/{challengeProviderId}')]
146147
#[TwoFactorSetUpDoneRequired]
147148
#[UserRateLimit(limit: 5, period: 100)]
149+
#[BruteForceProtection(action: 'solveChallenge')]
148150
public function solveChallenge(string $challengeProviderId, string $challenge, ?string $redirect_url = null): RedirectResponse {
149151
$user = $this->userSession->getUser();
150152
$provider = $this->twoFactorManager->getProvider($user, $challengeProviderId);
@@ -172,10 +174,12 @@ public function solveChallenge(string $challengeProviderId, string $challenge, ?
172174
$uid = $user->getUID();
173175
$this->logger->warning("Two-factor challenge failed: $uid (Remote IP: $ip)");
174176
$this->session->set('two_factor_auth_error', true);
175-
return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
177+
$response = new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
176178
'challengeProviderId' => $provider->getId(),
177179
'redirect_url' => $redirect_url,
178180
]));
181+
$response->throttle(['user' => $uid, 'provider' => $challengeProviderId]);
182+
return $response;
179183
}
180184

181185
#[NoAdminRequired]

tests/Core/Controller/TwoFactorChallengeControllerTest.php

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

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

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

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

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

@@ -325,6 +328,7 @@ public function testSolveChallengeTwoFactorException(): void {
325328
->willReturn('myprovider');
326329

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

0 commit comments

Comments
 (0)