feat: json login rate limit

This commit is contained in:
Maël Gangloff
2024-07-22 17:14:21 +02:00
parent ec1bbf3b05
commit fa80d33a33

View File

@@ -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