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