backend: disconnect gateway clients if they send a ping packet before authenticaticating

This commit is contained in:
hippoz 2022-05-08 21:56:25 +03:00
parent 97d155667d
commit 261e041792
No known key found for this signature in database
GPG key ID: 7C52899193467641
2 changed files with 5 additions and 0 deletions

View file

@ -17,4 +17,5 @@ export const gatewayErrors = {
ALREADY_AUTHENTICATED: { code: 4006, message: "Already authenticated" }, ALREADY_AUTHENTICATED: { code: 4006, message: "Already authenticated" },
PAYLOAD_TOO_LARGE: { code: 4007, message: "Payload too large" }, PAYLOAD_TOO_LARGE: { code: 4007, message: "Payload too large" },
TOO_MANY_SESSIONS: { code: 4008, message: "Too many sessions" }, TOO_MANY_SESSIONS: { code: 4008, message: "Too many sessions" },
NOT_AUTHENTICATED: { code: 4009, message: "Not authenticated" },
}; };

View file

@ -245,6 +245,10 @@ export default function(server: Server) {
return closeWithBadPayload(ws, "d: expected numeric '0'"); return closeWithBadPayload(ws, "d: expected numeric '0'");
} }
if (!ws.state.ready) {
return closeWithError(ws, gatewayErrors.NOT_AUTHENTICATED);
}
// TODO: also check session here // TODO: also check session here
ws.state.alive = true; ws.state.alive = true;
break; break;