From fa80d33a33fba07546c6ee73b4a290daf54a2064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Mon, 22 Jul 2024 17:14:21 +0200 Subject: [PATCH] feat: json login rate limit --- config/packages/security.yaml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/config/packages/security.yaml b/config/packages/security.yaml index c9eb6c4..5a64a31 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,3 +1,27 @@ +framework: + rate_limiter: + # define 2 rate limiters (one for username+IP, the other for IP) + username_ip_login: + policy: token_bucket + limit: 5 + rate: { interval: '5 minutes' } + + ip_login: + policy: sliding_window + limit: 50 + interval: '15 minutes' + +services: + # our custom login rate limiter + app.login_rate_limiter: + class: Symfony\Component\Security\Http\RateLimiter\DefaultLoginRateLimiter + arguments: + # globalFactory is the limiter for IP + $globalFactory: '@limiter.ip_login' + # localFactory is the limiter for username+IP + $localFactory: '@limiter.username_ip_login' + $secret: '%kernel.secret%' + security: # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords password_hashers: @@ -21,6 +45,8 @@ security: check_path: api_login success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure + login_throttling: + limiter: app.login_rate_limiter api: pattern: ^/api