xmppo / node-xmpp-bosh

An XMPP BOSH & WebSocket server (connection manager) written on node.js using Javascript
https://github.com/xmppo/node-xmpp-bosh
263 stars 85 forks source link

Chances of retrieving the actual client IP from the XMPP server side #109

Closed ebarbeito closed 2 years ago

ebarbeito commented 10 years ago

Hi,

I think here is not the best place to post this issue but I haven't found a better place to do it, so sorry if I end in an off-topic issue.

I'm using NXB within a webchat project I'm writing that connects to IRC servers thought a XMPP server (ejabberd 2.1.10) with a irc_transport module (mod_irc) enabled which allows to handle IRC stuff. Everything goes well and when a new client connection arrives from the webchat, the websocket between him and node-bosh-xmpp is established and managed fine (for this I'm using the library Strophe.js).

The problem I have in the node-xmpp-bosh side is that I need to know all the client IPs that opens every websocket. For example, If a webchat with IP 84.1.1.1 connects, the ejabberd (listening on 5222 with ip 195.9.9.9) log shows the next:

I(<0.629.0>:ejabberd_listener:281) : (#Port<0.3825>) Accepted connection {{195,9,9,9},60897} -> {{195,9,9,9},5222}

Where {195,9,9,9},60897} is the client connection (that opens a new local comunication in port 60897) and {195,9,9,9},5222} is the ejabberd server.

.----------.                                  .-----.                                         .----------------------.
|  webchat |                                  |     |                                         |                      |
|  client  | <------------------------------> | XNB | <-------------------------------------> | ejabberd <-> mod_irc |
| 84.1.1.1 |  ws://195.9.9.9:5280/http-bind/  |_____|  {195.9.9.9,60897} -> {195.9.9.9,5222}  |______________________|
|__________|

This is a problem for me because I loose the current client IP. I'm wondering if there is any way to know the actual IP from {195,9,9,9},60897}, so I can retrieve it from the ejabberd source code.

I know this sounds a bit offtopic but may be there is some way from NXB to "send/propagate" the client IP that open a new connection to the XMPP server.

Thanks in advance

dhruvbird commented 10 years ago

HTTP uses the http://en.wikipedia.org/wiki/X-Forwarded-For header for such purposes. Do you know if there is an XMPP standard for such forwarding? It could be fairly easily added in as an XML attribute if there is a way that the upstream XMPP server can make sense of it.

ebarbeito commented 10 years ago

May be the XEP-0131 is the best protocol that fits in here, I think X-Forwarded-For header could be available in the XMPP server side if NXB modifies the incoming stanzas to add something like this:

<headers xmlns='http://jabber.org/protocol/shim'>
  <header name='X-Forwarded-For'>client_ip</header>
</headers>

What do you think about? It's possible to NXB to modify the stanzas and add

information with the headers added in http_headers: { } configuration object? (or adding a fixed <header name='X-Forwarded-For'>client_ip</header> in all stanzas. I think it would be always cool to have that information, wouldn't it?)

If it's possible, could you do that or can point me in the right direction please?

Thanks for your support

dhruvbird commented 10 years ago

I think having the client ip always available in every stanza (using the headers tag) would be fine, and totally worth it. I'm happy to accept patches for the same.

ebarbeito commented 10 years ago

Glad to know that <headers/> with a <header name='X-Forwarded-For'> included in all (send) stanzas has sense. The affected stanzas will be only those sent to the server.

In order to send you a patch can you show me what involved files should I look into?

Thanks in advance

dhruvbird commented 10 years ago

@ebarbeito You would probably have to add the XML stanza as child nodes somewhere here:

https://github.com/dhruvbird/node-xmpp-bosh/blob/master/src/http-server.js#L139 https://github.com/dhruvbird/node-xmpp-bosh/blob/master/src/http-server.js#L114

You can get the IP from req (and if this request has been forwarded by a reverse proxy, then the x-forwarded-for header from req.headers, etc...