how to get `CF-IPCountry` header info of `X-Forwarded-For` header if it's present?

We use cloudflare workers for analytics and things of that nature. Sometimes we recommend that people send us analytics data via reverse proxy. This means that the CF-Connecting-IP ip address becomes that of the proxy server and X-Forwarded-For is the ip of the end user. This all works great except CF-IPCountry becomes the geo location (Country, region, etc) of the reverse proxy and not the end user. So basically when we group our analytics data by country, it becomes incorrect. Is there a way to rewrite worker headers to (if there is a X-Forwarded-For address, to use that to generate CF-IPCountry ? I was looking for ways to modify request headers in docs here but not sure if what I am describing above is possible. Ref: https://developers.cloudflare.com/rules/transform/request-header-modification/
Cloudflare Docs
HTTP request header modification rules · Cloudflare Rules docs
Use HTTP request header modification rules to manipulate the headers of HTTP requests sent to your origin server.
4 Replies
Chaika
Chaika3mo ago
As far as I know, you'd have to use a third party database sadly. Cloudflare itself uses Maxmind, which you could as well.
andriy
andriy3mo ago
got it makes, sense. i noticed that cloudflare has a true IP address option, but that requires an enterprise plan
andriy
andriy3mo ago
i ended up going with https://ip-api.com/ because it's cheap
IP-API.com - Geolocation API
Free IP Geolocation API - lookup any IP address
Chaika
Chaika3mo ago
All True IP Address does is send another header down with the IP Address that was connected from
For all plans, Cloudflare always sends the original visitor IP using the CF-Connecting-IP and X-Forwarded-For headers. This feature adds a third header, True-Client-IP, for compatibility with another vendor.
(which you could do yourself with Transform Rules, it just wouldn't fix your issue)