INNER CODE UNIT · Python
_client_ip
canarybyte/veridrop · web/server.py:260
def _client_ip(request: Request) -> str:
"""Resolve the originating client IP.
uvicorn is started with --proxy-headers --forwarded-allow-ips=* so by the
time FastAPI sees the request, request.client.host is already the leftmost
X-Forwarded-For value (the real client). Fall back to "unknown" if the
request somehow lacks a client (shouldn't happen behind Caddy).
"""
return request.client.host if request.client else "unknown"
# Probe is cheap (one upstream GET) but accepts arbitrary base_url + api_key,
# making it a tempting key-scanning oracle. 15/min/IP is generous enough for
# a real user editing/correcting fields and tight enough to slow scanners.
# Preflight (per-model alive check) shares the same bucket — both are "fan
# one cheap upstream call out from this proxy" operations.
_PROBE_RATE_LIMIT = 15
_PROBE_RATE_WINDOW_S = 60.0