implement rate limiting for authentication routes and add custom error handling page

This commit is contained in:
Eduardo Silva
2026-03-16 13:42:20 -03:00
parent 685b4eb971
commit e1f128f217
6 changed files with 61 additions and 2 deletions

View File

@@ -0,0 +1,14 @@
from fastapi import Request
from slowapi import Limiter
AUTH_RATE_LIMIT = "5/minute"
def get_real_client_ip(request: Request) -> str:
forwarded_for = request.headers.get("x-forwarded-for", "")
if forwarded_for:
return forwarded_for.split(",")[0].strip()
return request.client.host if request.client else "unknown"
limiter = Limiter(key_func=get_real_client_ip)