From f1f48ae53ef999cfc3252e564b994028cedfb24e Mon Sep 17 00:00:00 2001 From: Matthew Kobayashi <1856537+MattKobayashi@users.noreply.github.com> Date: Fri, 6 Mar 2026 08:52:59 +1000 Subject: [PATCH] fix: return client IPv6 address via cloudflared (#757) * fix: return client IPv6 address via cloudflared The cloudflared reverse proxy populates the X-Forwarded-For header for origin IPv4 addresses, however origin IPv6 addresses are added in a different header: Cf-Connecting-Ipv6. This updates the getIP.php mechanism to retrieve the value of this header and to prefer it over other client IP headers (in both cases only if the Cf-Connecting-Ipv6 header exists and is not empty). * fix: Validate and normalise IP addresses from request headers getClientIp() used HTTP_CF_CONNECTING_IPV6 and other headers verbatim, allowing malformed values to reach ISP lookups and the offline DB. Add normalizeCandidateIp() helper that trims whitespace, extracts the first comma-separated token, and validates via filter_var(). Require FILTER_FLAG_IPV6 for the CF header and fall through to the next source on failure. Written with assistance from OpenCode using Claude Opus 4.6. --- backend/getIP_util.php | 60 +++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/backend/getIP_util.php b/backend/getIP_util.php index 7aeaae1..23268ea 100755 --- a/backend/getIP_util.php +++ b/backend/getIP_util.php @@ -1,19 +1,55 @@