mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-11-17 10:33:15 +01:00
implement rate limiting for authentication routes and add custom error handling page
This commit is contained in:
@@ -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