Skip to content
This repository
Browse code

Merge pull request #298 from sveisvei/master

Report correct clientIp when using reverse/forward-proxies
  • Loading branch information...
commit 435f4725ac376f16ea923cd33447bdbb0d17ae7d 2 parents e6d4094 + 8a22f18
Owen Barnes authored September 23, 2012
3  lib/websocket/transports/socketio/index.js
@@ -30,6 +30,9 @@ module.exports = function(ss, emitter, httpServer, config) {
30 30
         try {
31 31
           _ref = utils.parseWsMessage(msg), responderId = _ref[0], content = _ref[1];
32 32
           clientIp = socket.manager.handshaken[socket.id].address.address;
  33
+          if (socket.manager.handshaken[socket.id].headers['x-forwarded-for']){ 
  34
+            clientIp = socket.manager.handshaken[socket.id].headers['x-forwarded-for'].split(',')[0]; 
  35
+          }
33 36
           meta = {
34 37
             socketId: socket.id,
35 38
             sessionId: socket.sessionId,
3  src/websocket/transports/socketio/index.coffee
@@ -35,6 +35,9 @@ module.exports = (ss, emitter, httpServer, config = {}) ->
35 35
         try
36 36
           [responderId, content] = utils.parseWsMessage(msg)
37 37
           clientIp = socket.manager.handshaken[socket.id].address.address
  38
+          if socket.manager.handshaken[socket.id].headers['x-forwarded-for']
  39
+            clientIp = socket.manager.handshaken[socket.id].headers['x-forwarded-for'].split(',')[0]
  40
+            
38 41
           meta = {socketId: socket.id, sessionId: socket.sessionId, clientIp: clientIp, transport: 'socketio'}
39 42
           emitter.emit responderId, content, meta, (data) ->
40 43
             socket.send(responderId + '|' + data)

0 notes on commit 435f472

Please sign in to comment.
Something went wrong with that request. Please try again.