Skip to content
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

Forwarded fix #7593

Merged
merged 5 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/api3/storageSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const apiConst = require('./const');
const forwarded = require('forwarded-for');

function getRemoteIP (req) {
const address = forwarded(req, req.headers);
return address.ip;
}

/**
* Socket.IO broadcaster of any storage change
*/
Expand All @@ -29,8 +34,7 @@ function StorageSocket (app, env, ctx) {
self.namespace = io.of(NAMESPACE);
self.namespace.on('connection', function onConnected (socket) {

const address = forwarded(socket.request, socket.request.headers);
const remoteIP = address.ip;
const remoteIP = getRemoteIP(socket.request);
console.log(LOG + 'Connection from client ID: ', socket.client.id, ' IP: ', remoteIP);

socket.on('disconnect', function onDisconnect () {
Expand Down
10 changes: 7 additions & 3 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ var calcData = require('../data/calcdelta');
var ObjectID = require('mongodb').ObjectID;
const forwarded = require('forwarded-for');

function getRemoteIP (req) {
const address = forwarded(req, req.headers);
return address.ip;
}

function init (env, ctx, server) {

function websocket () {
Expand Down Expand Up @@ -134,8 +139,7 @@ function init (env, ctx, server) {
var timeDiff;
var history;

const address = forwarded(socket.request, socket.request.headers);
const remoteIP = address.ip;
const remoteIP = getRemoteIP(socket.request);
console.log(LOG_WS + 'Connection from client ID: ', socket.client.id, ' IP: ', remoteIP);

io.emit('clients', ++watchers);
Expand Down Expand Up @@ -531,7 +535,7 @@ function init (env, ctx, server) {
// [, status : true ]
// }
socket.on('authorize', function authorize (message, callback) {
const remoteIP = socket.request.connection.remoteAddress;
const remoteIP = getRemoteIP(socket.request);
verifyAuthorization(message, remoteIP, function verified (err, authorization) {

if (err) {
Expand Down