From fec30b7ec94a689ccc6899427a1da430e365d28e Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Thu, 14 Apr 2022 21:10:05 +0300 Subject: [PATCH] backend: disallow gateway clients from authenticating if they're already authenticated --- src/errors.ts | 1 + src/gateway/index.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/errors.ts b/src/errors.ts index 1769d5b..1e7e259 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -13,4 +13,5 @@ export const gatewayErrors = { AUTHENTICATION_TIMEOUT: { code: 4003, message: "Authentication timeout" }, NO_PING: { code: 4004, message: "No ping" }, FLOODING: { code: 4005, message: "Flooding (exceeded maximum messages per batch)" }, + ALREADY_AUTHENTICATED: { code: 4006, message: "Already authenticated" }, }; diff --git a/src/gateway/index.ts b/src/gateway/index.ts index 8337dcc..a2eb33e 100644 --- a/src/gateway/index.ts +++ b/src/gateway/index.ts @@ -178,6 +178,10 @@ export default function(server: Server) { switch (payload.t) { case GatewayPayloadType.Authenticate: { + if (ws.state.ready) { + return closeWithError(ws, gatewayErrors.ALREADY_AUTHENTICATED); + } + const token = payload.d; if (typeof token !== "string") { return closeWithBadPayload(ws, "d: expected string");