Question

In node.js + socket.io I use this code to get user's IP address:

var clientIP = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address.address;

But the result is wrong. I console.log'd these values and got the following results:

socket.handshake.address.address is obviously internal IP (127.x.x.x)

x-forwarded-for is one of the cloud9's proxies (107.23.232.64, 54.236.78.114, 107.23.123.140).

So apparently double proxying is used and one of the proxy layers does not provie 'x-forwarded-for' header, right? Is getting real IP of the user absolutely impossible with cloud9? It is essential for my project.

Was it helpful?

Solution

Cloud9 is indeed using a two layer proxy to give access to applications running in workspaces. The first proxy is checking access rights and the second one is tunneling requests to the workspaces. The second proxy is hosted by our infrastructure provider OpenShift and that one overwrites the x-forwarded-for header set by the first one. Unfortunately we have no means to fix this at the moment. As mentioned in the comment try to avoid relying on the remote's IP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top