summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorloovjo <jonathan.loov@gmail.com>2020-05-08 11:58:03 +0200
committerGitHub <noreply@github.com>2020-05-08 11:58:03 +0200
commit297db3fdbd9c9c818d1bf93dc92c7ec036c79e58 (patch)
tree2459874c95fc01316d3ef73e839545f3af4e5d70
parent67bb7d6a2c3eabf6b2995c7676ae14ddf169ee35 (diff)
JSON validation in WebSocket
-rw-r--r--routes/index.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/routes/index.js b/routes/index.js
index 27116d4..bc97e8b 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -369,7 +369,16 @@ router.get("/game", checkAuthentication(PAGE_ERROR_OUTPUT), function(req, res, n
router.ws("/gameUpdate", checkAuthentication(SOCKET_ERROR_OUTPUT), function(ws, req, next) {
console.log("Opening socket.");
ws.on("message", function(message) {
- var tempCommandList = JSON.parse(message);
+ try {
+ var tempCommandList = JSON.parse(message);
+ } catch (tempErr) {
+ var tempResult = {
+ success: false,
+ message: "Invalid JSON",
+ };
+ ws.send(JSON.stringify(tempResult));
+ return;
+ }
if (gameUtils.isInDevelopmentMode) {
setTimeout(function() {
performUpdate(tempCommandList);