Merge pull request #533 from notepid/ws-proxy-header-fix

Fix for x-forwarded-for not being applied
This commit is contained in:
Bryan Ashby
2024-08-31 11:28:30 -06:00
committed by GitHub

View File

@@ -71,6 +71,25 @@ class WebSocketClient extends TelnetClient {
})(ws);
super(wsDuplex);
Log.trace({ headers: req.headers }, 'WebSocket connection headers');
//
// If the config allows it, look for 'x-forwarded-proto' as "https"
// to override |isSecure|
//
if (
true === _.get(Config(), 'loginServers.webSocket.proxied') &&
'https' === req.headers['x-forwarded-proto']
) {
Log.debug(
`Assuming secure connection due to X-Forwarded-Proto of "${req.headers['x-forwarded-proto']}"`
);
this.proxied = true;
} else {
this.proxied = false;
}
wsDuplex.setClient(this, req);
// fudge remoteAddress on socket, which is now TelnetSocket
@@ -91,24 +110,6 @@ class WebSocketClient extends TelnetClient {
ws.isConnectionAlive = true;
});
Log.trace({ headers: req.headers }, 'WebSocket connection headers');
//
// If the config allows it, look for 'x-forwarded-proto' as "https"
// to override |isSecure|
//
if (
true === _.get(Config(), 'loginServers.webSocket.proxied') &&
'https' === req.headers['x-forwarded-proto']
) {
Log.debug(
`Assuming secure connection due to X-Forwarded-Proto of "${req.headers['x-forwarded-proto']}"`
);
this.proxied = true;
} else {
this.proxied = false;
}
// start handshake process
this.banner();
}