-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to retrieve a connection's remote IP address under IISNode #94
Comments
The reason for this behavior is that iisnode acts as a reverse proxy between the client and the node process. The req.connection represents the connection between iisnode and node.exe, not between the client's machine and iisnode. Furthermore, the connection between iisnode and node.exe is based on named pipes not TCP, and as such does not expose many of the concepts specific to TCP like the IP address. It would be possible to propagate selected properties describing the client connection using X-* headers of the HTTP request message. Would such mechanism satisfy your requirement? |
Aha, that makes complete sense now. Yes, I believe that a set of X-Headers would be helpful and could follow the standard type of X-headers from proxies such as X-Forwarded-For to cover the IP address info as well as X-Forwarded-Host to cover the original host the client requested. |
The fix for this issue is to add support for X-Forwarded-For request header to iisnode (http://en.wikipedia.org/wiki/X-Forwarded-For). A new configuration property iisnode@enableXFF controls whether iisnode adds or augments the X-Forwarded-For request header. By default the value is false. If set to true, iisnode will either append the IP address and port number of the next hop client to an X-Forwarded-For request header already existing on the HTTP request, or create a new X-Forwarded-For header in its absence. Both IPv4 and IPv6 addresses are supported. Each address will specify a port number as well. This is how to enable X-Forwarded-For support through web.config:
This is an example of the X-Forwarded-For HTTP request header iisnode will add to the request:
This is the code node.js application can use to read the value of the header:
|
Thank you. |
Can you put the port under X-Forwarded-Port to be inline with other implementations? Adding it to the Ip requires code forks for IISNode. |
I will look into this, reopening. |
Does this work in azure websites? I read somewhere that azure websites implement some kind of subset of iisnode. I have created a iisnode.yml file with enableXFF: true as only content, restarted the site like 5 time and still it wont show me the IPs.. |
the site is git deployed from OS X if that matters |
My problem was that i used "X-Forwarded-For", not "x-forwarded-for".. works now ;P |
while i am executing req.connection.socket.remoteAddress i am getting error below ..TypeError: Cannot read property 'remoteAddress' of undefined |
use "x-forwarded-for" as mentioned above. |
i want remote ip address like 220.226.23.254 but when i am executing x-forwarded-for i am getting local ip.. |
@jigneshnavsoft are you running on Windows using iisnode? The stack trace has file paths suggesting a non-Windows environment. |
i am using centos... On Fri, Jan 24, 2014 at 11:07 PM, Tomasz Janczuk
|
if you are directly running node.exe without iisnode (which you must be because you are on Linux/unix env) -- req.connection.socket.remoteAddress only works for HTTPS. |
i try also that .. On Fri, Jan 24, 2014 at 11:18 PM, Ranjith Ramachandra <
|
Broke since iisnode is not able to resolve remoteAddress. See tjanczuk/iisnode#94 for more information
I have try this in web.config
In node.js, I m trying get the ip using below code
xff is showing "undefined". I m using IIS version is 8.5 on windows 2012 r2 |
I vote for having enableXFF true as the default!! Any reason it isn't? |
enableXFF worked. Thanks |
enableXFF worked |
enableXFF worked. Tks |
I can not seem to retrieve the remote IPAddress of a request using node under IISNode. If I try req.connection.remoteAddress I get undefined. Same script run without IIS provides the remote address without a problem.
The text was updated successfully, but these errors were encountered: