Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sécurité - Audit] Modifier la protection anti-brute force #3675

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ security:
custom_authenticators:
- App\Security\JsonLoginAuthenticator
- App\Security\TokenAuthenticator
login_throttling:
max_attempts: 5 # '%env(int:FORMS_SUBMIT_LIMITER_LIMIT)%' doesnt work here: fails to cast str to int
interval: '%env(FORMS_SUBMIT_LIMITER_INTERVAL)%'
main:
lazy: true
stateless: false
Expand All @@ -39,7 +42,7 @@ security:
auth_form_path: 2fa_login
check_path: 2fa_login_check
login_throttling:
max_attempts: 10 # '%env(int:FORMS_SUBMIT_LIMITER_LIMIT)%' doesnt work here: fails to cast str to int
max_attempts: 5 # '%env(int:FORMS_SUBMIT_LIMITER_LIMIT)%' doesnt work here: fails to cast str to int
interval: '%env(FORMS_SUBMIT_LIMITER_INTERVAL)%'
logout:
path: app_logout
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Security/UserAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function requestLoginLink(
RateLimiterFactory $loginActivationFormLimiter,
): Response {
if ($request->isMethod('POST') && $email = $request->request->get('email')) {
$limiter = $loginActivationFormLimiter->create($request->getClientIp());
$limiter = $loginActivationFormLimiter->create($email);
if (false === $limiter->consume(1)->isAccepted()) {
return $this->render('security/login_link_sent.html.twig', [
'title' => 'Lien d\'activation',
Expand Down Expand Up @@ -77,7 +77,7 @@ public function requestNewPass(
): Response {
$title = 'Récupération de votre mot de passe';
if ($request->isMethod('POST') && $email = $request->request->get('email')) {
$limiter = $loginPasswordFormLimiter->create($request->getClientIp());
$limiter = $loginPasswordFormLimiter->create($email);
if (false === $limiter->consume(1)->isAccepted()) {
return $this->render('security/login_link_sent.html.twig', [
'title' => 'Lien de récupération',
Expand Down
4 changes: 2 additions & 2 deletions src/Security/JsonLoginAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
return new JsonResponse([
'error' => $this->translator->trans($exception->getMessageKey(), [], 'security'),
'message' => $this->translator->trans($exception->getMessage(), [], 'security'),
'error' => $this->translator->trans($exception->getMessageKey(), $exception->getMessageData(), 'security'),
'message' => $this->translator->trans($exception->getMessage(), $exception->getMessageData(), 'security'),
], Response::HTTP_UNAUTHORIZED);
}
}
4 changes: 2 additions & 2 deletions src/Security/TokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
return new JsonResponse([
'error' => $this->translator->trans($exception->getMessageKey(), [], 'security'),
'message' => $this->translator->trans($exception->getMessage(), [], 'security'),
'error' => $this->translator->trans($exception->getMessageKey(), $exception->getMessageData(), 'security'),
'message' => $this->translator->trans($exception->getMessage(), $exception->getMessageData(), 'security'),
], Response::HTTP_UNAUTHORIZED);
}
}
Loading