From 9ee51f797ea6a464af9ac4518088fe75aa8c6e1e Mon Sep 17 00:00:00 2001 From: caelum0x Date: Mon, 2 Nov 2026 23:06:24 +0300 Subject: [PATCH] fix(gitgram): close block-bypass via group chat creation sendMessage only checked hasBlockRelationship on the receiverId (DM) branch; the chatId (group chat) branch skipped it entirely. A user blocked by someone could route around the block by creating a "group chat" whose only other member is the blocker and sending through that chatId instead of receiverId. createGroupChat now rejects chat creation if the creator has a block relationship (either direction) with any proposed member. Repro'd live against a disposable local Postgres+Redis: B blocks A, A's direct message to B correctly 403s, but A's POST /messages/chats + /messages{chatId} both succeeded (201) before this fix. After the fix, chat creation 403s with "Cannot create a chat with a blocked user"; unblocked group chat creation still works (201). tsc --noEmit clean; full jest suite unchanged at the two pre-existing failing files (messages.test.ts, messageService.test.ts, identical 17/15 split confirmed via git stash against plain main). --- .../backend/src/controllers/messageController.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gitgram/backend/src/controllers/messageController.ts b/gitgram/backend/src/controllers/messageController.ts index b963b1f0..895305cd 100644 --- a/gitgram/backend/src/controllers/messageController.ts +++ b/gitgram/backend/src/controllers/messageController.ts @@ -295,6 +295,19 @@ export const createGroupChat = asyncHandler(async (req: AuthRequest, res: Respon const userId = req.userId!; const { name, memberIds } = req.body; + // Block enforcement gap: sendMessage only checks hasBlockRelationship on the + // receiverId (DM) branch, never on the chatId (group chat) branch. Without a + // check here, a blocked user could route around a block entirely by creating + // a "group chat" whose only other member is the user who blocked them, then + // messaging through that chatId instead of receiverId. Reject chat creation + // up front so that vector doesn't exist. + const blockChecks = await Promise.all( + memberIds.map((memberId: string) => blockService.hasBlockRelationship(userId, memberId)) + ); + if (blockChecks.some(Boolean)) { + throw Errors.forbidden('Cannot create a chat with a blocked user'); + } + const chat = await prisma.chat.create({ data: { name,