From dd4c73efbcc0ad473af66a176d62c139684c20bf Mon Sep 17 00:00:00 2001 From: Ian Goldstein Date: Fri, 27 Jan 2017 20:00:53 -0800 Subject: [PATCH] =?UTF-8?q?Use=20x-forwarded-for=20header=20to=20get=20the?= =?UTF-8?q?=20caller=E2=80=99s=20IP=20address=20for=20realtime=20activity?= =?UTF-8?q?=20logging,=20if=20available?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- realtime/setupSocketIO.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/realtime/setupSocketIO.js b/realtime/setupSocketIO.js index d52c0d4f5b..04c6def53f 100644 --- a/realtime/setupSocketIO.js +++ b/realtime/setupSocketIO.js @@ -92,18 +92,21 @@ function setupNamespace(io) { */ function init(io) { io.sockets.on('connection', (socket) => { - console.log(socket); // eslint-disable-line no-console - console.log(socket.handshake); // eslint-disable-line no-console if (logEnabled) { const toLog = { starttime: Date.now(), }; - if (socket.handshake.address) { - toLog.ipAddress = socket.handshake.address; - } + if (socket.handshake) { + if (socket.handshake.headers && + socket.handshake.headers['x-forwarded-for']) { + toLog.ipAddress = socket.handshake.headers['x-forwarded-for']; + } else if (socket.handshake.address) { + toLog.ipAddress = socket.handshake.address; + } - if (socket.handshake.query && socket.handshake.query.p) { - toLog.perspective = socket.handshake.query.p; + if (socket.handshake.query && socket.handshake.query.p) { + toLog.perspective = socket.handshake.query.p; + } } extractTokenInfo(socket)