mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-17 12:03:03 +00:00
fix: do not serve data to an unauthenticated websocket client
This commit is contained in:
committed by
Carlos Valente
parent
319293ab4c
commit
1a9950d658
@@ -62,11 +62,22 @@ class SocketServer implements IAdapter {
|
||||
this.wss = new WebSocketServer({ path: `${prefix}/ws`, server, maxPayload: this.MAX_PAYLOAD });
|
||||
|
||||
this.wss.on('connection', (ws, req) => {
|
||||
// Rejected sockets can emit an error while their close handshake is in progress.
|
||||
ws.on('error', console.error);
|
||||
|
||||
let isAuthenticated = false;
|
||||
authenticateSocket(ws, req, (error) => {
|
||||
if (error) {
|
||||
ws.close(1008, 'Unauthorized');
|
||||
return;
|
||||
}
|
||||
isAuthenticated = true;
|
||||
});
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return;
|
||||
}
|
||||
|
||||
const clientId = generateId();
|
||||
const clientName = getRandomName();
|
||||
function sendPacket<T extends MessageTag>(
|
||||
@@ -94,8 +105,6 @@ class SocketServer implements IAdapter {
|
||||
// send store payload on connect
|
||||
sendPacket(MessageTag.RuntimeData, eventStore.poll());
|
||||
|
||||
ws.on('error', console.error);
|
||||
|
||||
ws.on('close', () => {
|
||||
this.clients.delete(clientId);
|
||||
logger.info(LogOrigin.Client, `${this.clients.size} Connections with disconnected: ${clientName}`);
|
||||
|
||||
Reference in New Issue
Block a user