Skip to content

Commit

Permalink
Merge pull request #533 from notepid/ws-proxy-header-fix
Browse files Browse the repository at this point in the history
Fix for x-forwarded-for not being applied
  • Loading branch information
NuSkooler authored Aug 31, 2024
2 parents 02111d0 + 2042fe2 commit 7291670
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions core/servers/login/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down

0 comments on commit 7291670

Please sign in to comment.