You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
Use first address when x-forwarded-for contains more addresses
This commit is contained in:
@@ -325,9 +325,15 @@ app.use('/', endpoints);
|
||||
*/
|
||||
wss.on('connection', (ws, request) => {
|
||||
const output = serverConfig.xdrd.wirelessConnection ? client : serialport;
|
||||
const clientIp = request.headers['x-forwarded-for'] || request.connection.remoteAddress;
|
||||
let clientIp = request.headers['x-forwarded-for'] || request.connection.remoteAddress;
|
||||
|
||||
let clientIpTest = clientIp.split(',')[0].trim();
|
||||
if (clientIp.includes(',')) {
|
||||
/**
|
||||
* if x-forwarded-for contains ',' it means that connection is going through multiple proxies.
|
||||
* we want first address, which should be IP of the user.
|
||||
*/
|
||||
clientIp = clientIp.split(',')[0].trim();
|
||||
}
|
||||
|
||||
if (clientIp !== '::ffff:127.0.0.1' || (request.connection && request.connection.remoteAddress && request.connection.remoteAddress !== '::ffff:127.0.0.1') || (request.headers && request.headers['origin'] && request.headers['origin'].trim() !== '')) {
|
||||
currentUsers++;
|
||||
|
||||
Reference in New Issue
Block a user