From 86b87c7f4f4bbb52aa89d2b8dc33ef404fe200b6 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 15 May 2020 20:50:24 -0700 Subject: safer sockets --- lib/sockets.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/sockets.js b/lib/sockets.js index ee453ce7..adea1fa3 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -37,6 +37,7 @@ const names = {}; wss.on("connection", function (ws) { const id = uuidv4(); + setTimeout(() => ws.ok || ws.close(), 2000); ws.on("message", async (token) => { if (!token || token === "null") return; @@ -46,11 +47,13 @@ wss.on("connection", function (ws) { sockets[username][id] = ws; names[id] = username; + ws.ok = true; ws.send(JSON.stringify({ type: "networks", data: networks })); ws.send(JSON.stringify({ type: "rates", data: app.get("rates") })); ws.send(JSON.stringify({ type: "login", data: await getUser(username) })); l.info("socket open", username, id); } catch (e) { + ws.close(); l.error("problem opening socket", token, e.message, id); } }); -- cgit v1.2.3