From ef5ef2730c756d767f678527735340e7a73c82f8 Mon Sep 17 00:00:00 2001 From: shiyu Date: Thu, 1 Jan 2026 15:45:38 +0800 Subject: [PATCH] feat(audit): enhance client IP extraction logic in request handling --- domain/audit/decorator.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/domain/audit/decorator.py b/domain/audit/decorator.py index f8f7b19..5559b09 100644 --- a/domain/audit/decorator.py +++ b/domain/audit/decorator.py @@ -98,6 +98,11 @@ def _build_request_params(request: Request | None) -> Dict[str, Any] | None: def _get_client_ip(request: Request | None) -> str | None: if not request: return None + cf_connecting_ip = request.headers.get("cf-connecting-ip") or request.headers.get("CF-Connecting-IP") + if cf_connecting_ip: + ip = cf_connecting_ip.strip() + if ip: + return ip x_real_ip = request.headers.get("x-real-ip") or request.headers.get("X-Real-IP") if x_real_ip: ip = x_real_ip.strip()