add missing XFF warning, remove ipdata check from WSServer because CollabVMServer already does that

This commit is contained in:
Elijah R
2024-06-23 02:23:50 -04:00
parent 286f3eec62
commit 85a86327f4

View File

@@ -94,6 +94,7 @@ export default class WSServer extends EventEmitter implements NetworkServer {
// Make sure x-forwarded-for is set // Make sure x-forwarded-for is set
if (req.headers['x-forwarded-for'] === undefined) { if (req.headers['x-forwarded-for'] === undefined) {
killConnection(); killConnection();
this.logger.Error('X-Forwarded-For header not set. This is most likely a misconfiguration of your reverse proxy.');
return; return;
} }
try { try {
@@ -101,6 +102,7 @@ export default class WSServer extends EventEmitter implements NetworkServer {
ip = req.headers['x-forwarded-for']?.toString().replace(/\ /g, '').split(',')[0]; ip = req.headers['x-forwarded-for']?.toString().replace(/\ /g, '').split(',')[0];
} catch { } catch {
// If we can't get the IP, kill the connection // If we can't get the IP, kill the connection
this.logger.Error('Invalid X-Forwarded-For header. This is most likely a misconfiguration of your reverse proxy.');
killConnection(); killConnection();
return; return;
} }
@@ -119,16 +121,6 @@ export default class WSServer extends EventEmitter implements NetworkServer {
ip = req.socket.remoteAddress; ip = req.socket.remoteAddress;
} }
let ipdata = IPDataManager.GetIPDataMaybe(ip);
if (ipdata != null) {
let connections = ipdata.refCount;
if (connections + 1 > this.Config.collabvm.maxConnections) {
socket.write('HTTP/1.1 429 Too Many Requests\n\n429 Too Many Requests');
socket.destroy();
}
}
this.wsServer.handleUpgrade(req, socket, head, (ws: WebSocket) => { this.wsServer.handleUpgrade(req, socket, head, (ws: WebSocket) => {
this.wsServer.emit('connection', ws, req); this.wsServer.emit('connection', ws, req);
this.onConnection(ws, req, ip); this.onConnection(ws, req, ip);