Skip to content

Commit 07e353d

Browse files
committed
feat: don't count failed CSRF as failed login attempt
Signed-off-by: Benjamin Gaussorgues <[email protected]>
1 parent e31f474 commit 07e353d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

core/Controller/LoginController.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private function setPasswordResetInitialState(?string $username): void {
207207
$this->canResetPassword($passwordLink, $user)
208208
);
209209
}
210-
210+
211211
/**
212212
* Sets the initial state of whether or not a user is allowed to login with their email
213213
* initial state is passed in the array of 1 for email allowed and 0 for not allowed
@@ -299,7 +299,8 @@ public function tryLogin(Chain $loginChain,
299299
$user,
300300
$user,
301301
$redirect_url,
302-
self::LOGIN_MSG_CSRFCHECKFAILED
302+
self::LOGIN_MSG_CSRFCHECKFAILED,
303+
false,
303304
);
304305
}
305306

@@ -349,7 +350,12 @@ public function tryLogin(Chain $loginChain,
349350
* @return RedirectResponse
350351
*/
351352
private function createLoginFailedResponse(
352-
$user, $originalUser, $redirect_url, string $loginMessage) {
353+
$user,
354+
$originalUser,
355+
$redirect_url,
356+
string $loginMessage,
357+
bool $throttle = true,
358+
) {
353359
// Read current user and append if possible we need to
354360
// return the unmodified user otherwise we will leak the login name
355361
$args = $user !== null ? ['user' => $originalUser, 'direct' => 1] : [];
@@ -359,7 +365,9 @@ private function createLoginFailedResponse(
359365
$response = new RedirectResponse(
360366
$this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)
361367
);
362-
$response->throttle(['user' => substr($user, 0, 64)]);
368+
if ($throttle) {
369+
$response->throttle(['user' => substr($user, 0, 64)]);
370+
}
363371
$this->session->set('loginMessages', [
364372
[$loginMessage], []
365373
]);

0 commit comments

Comments
 (0)