X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Froutes%2Fgames.js;h=423258564b7b8b19fe5ecf5a529c8b4325a40a7f;hp=bef8bf5ed86f78d5f66deda0a1d43f9349a60269;hb=99b7a14c6e01c53a49459c8d4681acf6abe635d8;hpb=fcd299a3531de30be3b1f90ac8a2dc8cb363f039 diff --git a/server/routes/games.js b/server/routes/games.js index bef8bf5e..42325856 100644 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -10,7 +10,7 @@ const params = require("../config/parameters"); router.post("/games", access.logged, access.ajax, (req,res) => { const gameInfo = req.body.gameInfo; if (!Array.isArray(gameInfo.players) || - !gameInfo.players.some(p => p.id == req.userId)) + gameInfo.players.every(p => p.id != req.userId)) { return res.json({errmsg: "Cannot start someone else's game"}); } @@ -43,6 +43,8 @@ router.get("/games", access.ajax, (req,res) => { const gameId = req.query["gid"]; if (!!gameId) { + if (!gameId.match(/^[0-9]+$/)) + return res.json({errmsg: "Wrong game ID"}); GameModel.getOne(gameId, (err,game) => { access.checkRequest(res, err, game, "Game not found", () => { res.json({game: game}); @@ -53,6 +55,8 @@ router.get("/games", access.ajax, (req,res) => { { // Get by (non-)user ID: const userId = req.query["uid"]; + if (!userId.match(/^[0-9]+$/)) + return res.json({errmsg: "Wrong user ID"}); const excluded = !!req.query["excluded"]; GameModel.getByUser(userId, excluded, (err,games) => { if (!!err)