mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-03-18 06:46:17 +00:00
implement rate limiting for authentication routes and add custom error handling page
This commit is contained in:
14
containers/auth-gateway/auth_gateway/limiter.py
Normal file
14
containers/auth-gateway/auth_gateway/limiter.py
Normal 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)
|
||||
Reference in New Issue
Block a user