Skip to content

Commit 7291670

Browse files
authored
Merge pull request #533 from notepid/ws-proxy-header-fix
Fix for x-forwarded-for not being applied
2 parents 02111d0 + 2042fe2 commit 7291670

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

core/servers/login/websocket.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ class WebSocketClient extends TelnetClient {
7171
})(ws);
7272

7373
super(wsDuplex);
74+
75+
Log.trace({ headers: req.headers }, 'WebSocket connection headers');
76+
77+
//
78+
// If the config allows it, look for 'x-forwarded-proto' as "https"
79+
// to override |isSecure|
80+
//
81+
if (
82+
true === _.get(Config(), 'loginServers.webSocket.proxied') &&
83+
'https' === req.headers['x-forwarded-proto']
84+
) {
85+
Log.debug(
86+
`Assuming secure connection due to X-Forwarded-Proto of "${req.headers['x-forwarded-proto']}"`
87+
);
88+
this.proxied = true;
89+
} else {
90+
this.proxied = false;
91+
}
92+
7493
wsDuplex.setClient(this, req);
7594

7695
// fudge remoteAddress on socket, which is now TelnetSocket
@@ -91,24 +110,6 @@ class WebSocketClient extends TelnetClient {
91110
ws.isConnectionAlive = true;
92111
});
93112

94-
Log.trace({ headers: req.headers }, 'WebSocket connection headers');
95-
96-
//
97-
// If the config allows it, look for 'x-forwarded-proto' as "https"
98-
// to override |isSecure|
99-
//
100-
if (
101-
true === _.get(Config(), 'loginServers.webSocket.proxied') &&
102-
'https' === req.headers['x-forwarded-proto']
103-
) {
104-
Log.debug(
105-
`Assuming secure connection due to X-Forwarded-Proto of "${req.headers['x-forwarded-proto']}"`
106-
);
107-
this.proxied = true;
108-
} else {
109-
this.proxied = false;
110-
}
111-
112113
// start handshake process
113114
this.banner();
114115
}

0 commit comments

Comments
 (0)