fix: return client IPv6 address via cloudflared#757
Merged
sstidl merged 2 commits intolibrespeed:masterfrom Mar 5, 2026
Merged
fix: return client IPv6 address via cloudflared#757sstidl merged 2 commits intolibrespeed:masterfrom
sstidl merged 2 commits intolibrespeed:masterfrom
Conversation
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).
Contributor
Review Summary by QodoPrioritize Cf-Connecting-Ipv6 header for IPv6 detection
WalkthroughsDescription• Prioritize Cf-Connecting-Ipv6 header for IPv6 client detection • Cloudflared populates IPv6 in separate header, not X-Forwarded-For • Reorder IP detection logic to check IPv6 header first Diagramflowchart LR
A["Client Request"] -->|"Cloudflared Proxy"| B["Check Cf-Connecting-Ipv6"]
B -->|"IPv6 Found"| C["Return IPv6 Address"]
B -->|"Not Found"| D["Check HTTP_CLIENT_IP"]
D -->|"Not Found"| E["Check HTTP_X_REAL_IP"]
E -->|"Not Found"| F["Check HTTP_X_FORWARDED_FOR"]
File Changes1. backend/getIP_util.php
|
Contributor
Code Review by Qodo
1.
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
cloudflaredreverse proxy populates theX-Forwarded-Forheader for origin IPv4 addresses, however origin IPv6 addresses are added in a different header:Cf-Connecting-Ipv6. This updates thegetIP.phpmechanism to retrieve the value of this header and to prefer it over other client IP headers (in both cases only if theCf-Connecting-Ipv6header exists and is not empty).A (sanitised) example of request headers passed by
cloudflared:{ "headers": { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, br", "Accept-Language": "en-AU,en;q=0.9", "Cdn-Loop": "cloudflare; loops=1", "Cf-Connecting-Ip": "254.252.239.103", "Cf-Connecting-Ipv6": "2403:580c:<redacted>", "Cf-Ipcountry": "AU", "Cf-Pseudo-Ipv4": "254.252.239.103", "Cf-Ray": "9d754acd5f8bd71b-BNE", "Cf-Visitor": "{\"scheme\":\"https\"}", "Cf-Warp-Tag-Id": "<redacted>", "Connection": "keep-alive", "Host": "<redacted>", "Priority": "u=0, i", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15", "X-Forwarded-For": "254.252.239.103", "X-Forwarded-Proto": "https" } }