Skip to content

Commit 1f47897

Browse files
committed
fix: prevent students from trying to join non-existing coalition
1 parent f7371c4 commit 1f47897

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/routes/quiz.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,18 @@ export const setupQuizRoutes = function(app: Express, prisma: PrismaClient): voi
361361
const coalitionId = parseInt(req.body.coalition_id);
362362
console.log(`User ${user.login} requested to join coalition ${coalitionId}`);
363363

364+
365+
// Check if coalitionId is actually in our database
366+
const coalition = await prisma.intraCoalition.findFirst({
367+
where: {
368+
id: coalitionId
369+
}
370+
});
371+
if (!coalition) {
372+
console.warn(`User ${user.login} tried to join a non-existing coalition ${coalitionId}`);
373+
return res.status(400).send({ error: 'Whatever you\'re trying to do, stop' });
374+
}
375+
364376
// Check if all questions have been answered
365377
if (! await areAllQuestionsAnswered(prisma, userSession)) {
366378
console.log(`User ${user.login} tried to join a coalition without answering all questions`);

0 commit comments

Comments
 (0)