Spaces:
Sleeping
Sleeping
Remove temporary forwarding-chain diagnostic (per-IP limits verified: single hop, real client address)
Browse files- backend/security.py +0 -9
backend/security.py
CHANGED
|
@@ -105,15 +105,6 @@ async def security_guard(request: Request) -> None:
|
|
| 105 |
request.state.user_id = None
|
| 106 |
|
| 107 |
if (request.method, path) in PUBLIC_ROUTES:
|
| 108 |
-
if path != "/api/health": # TEMP diagnostic: forwarding-chain shape only, no addresses
|
| 109 |
-
import hashlib
|
| 110 |
-
_xff = [p.strip() for p in request.headers.get("x-forwarded-for", "").split(",") if p.strip()]
|
| 111 |
-
def _g(v):
|
| 112 |
-
try: return ipaddress.ip_address(v).is_global
|
| 113 |
-
except ValueError: return None
|
| 114 |
-
print(f"[IPDIAG] hops={len(_xff)} global={[_g(v) for v in _xff]} peer_global={_g(request.client.host if request.client else '')} "
|
| 115 |
-
f"chosen={hashlib.sha256(client_ip(request).encode()).hexdigest()[:6]} first={hashlib.sha256((_xff[0] if _xff else '').encode()).hexdigest()[:6]} "
|
| 116 |
-
f"xrealip={'yes' if request.headers.get('x-real-ip') else 'no'}")
|
| 117 |
if path != "/api/health" and (wait := limiter.retry_after(f"auth:{client_ip(request)}", AUTH_PER_MIN, 60)):
|
| 118 |
_too_many(wait)
|
| 119 |
if path == "/api/auth/signup" and (wait := limiter.retry_after(f"signup:{client_ip(request)}", SIGNUPS_PER_HOUR, 3600)):
|
|
|
|
| 105 |
request.state.user_id = None
|
| 106 |
|
| 107 |
if (request.method, path) in PUBLIC_ROUTES:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
if path != "/api/health" and (wait := limiter.retry_after(f"auth:{client_ip(request)}", AUTH_PER_MIN, 60)):
|
| 109 |
_too_many(wait)
|
| 110 |
if path == "/api/auth/signup" and (wait := limiter.retry_after(f"signup:{client_ip(request)}", SIGNUPS_PER_HOUR, 3600)):
|