Fly-Client-IP and Fly-Forwarded-Port returning 'CacheFly' and 'Fly.io Inc' IPs, not user's IP

I finally ended the last feature of my system, but I noticed I am not able to get the user’s IP.
It’s essential that I get the user’s IP for my system.

The only thing I’m getting are IPv6 from fly proxies/company.

Here’s an excerpt from my code (Javascript)

import { headers } from "next/headers";

const headersList = request ? request.headers : headers();
const forwardedFor = headersList.get("x-forwarded-for");
const flyClientIp = headersList.get("fly-client-ip");
console.log(`Fly Client IP: ${flyClientIp}`);
console.log(`X-Forwarded-For: ${forwardedFor}`);

The result is this (in Console):

2023-12-26T19:33:19.650 app[91857792f1d958] gig [info] Fly Client IP: 2605:4c40:52:d205:0:f0a8:8a0b:1

2023-12-26T19:33:19.650 app[91857792f1d958] gig [info] X-Forwarded-For: 2605:4c40:52:d205:0:f0a8:8a0b:1, 2a09:8280:1::2d:b9d3

Both IPs from X-Forwarded-For belongs to Fly.io:

Host Info for 2605:4c40:52:d205:0:f0a8:8a0b:1
ISP: CacheFly
Domain: cachefly.com

Host Info for 2a09:8280:1::2d:b9d3
ISP: Fly.io Inc
Domain: fly.io

Can anyone help me with this?

Hey Joao,

CacheFly is not Fly.io - it’s a CDN/hosting provider :slight_smile: Are you using CacheFly as a CDN?

Thanks for replying.

Fly.io relies on CacheFly to support running full stack apps close to users globally, so I guess I don’t have a choice not to use it. I haven’t changed any settings as far as I remember.

That’s true, but CacheFly operates here as a hosting provider, not a CDN. If you’re not using them as a CDN, there may be an issue to look into here.

Any ideas on how solve this? I didn’t setup any CDNs. What other info I can provide that would be useful to discover the problem?

It seems that CacheFly is not passing forward the information on the client IP, from where the request originated. If I am right, the client IP should be passed along in the first position of “x-forwarded-for”, shouldn’t it?

Or, perhaps fly.io is indeed receiving this information but deleting and keeping only the CacheFly IP in x-forwarded-for.

I’m just “thinking out loud” here, I’m not an expert in this.
So, maybe it’s a misconfiguration.

I think it would be useful first to be able to reproduce. I haven’t been able to do so yet.

Can you try making the request from a Fly VM using curl or from another region? You can also check curl debug.fly.dev to see if the headers look similar to the results you get.

I’ve tried what you suggested and I ended up isolating the problem.
The request was being made inside a server function. In short, the client side was making the request to a function that gets the Fly-Client-IP, but this function was being executed in the server, not in the client’s device, so it’s obvious it would return the Fly.io machine’s IP.

Thank you very much for your help. It helped me think outside of the box. :grin:

Have great new year!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.