fix(gitgram): close block-bypass via group chat creation
Some checks failed
CI / Test: Gitgram Web (push) Has been cancelled
CI / Test: AITM API Server (push) Has been cancelled
CI / Typecheck: Backend + Web (push) Has been cancelled
CI / Lint: Backend + Web (push) Has been cancelled
Integration Tests / Gitgram: API Integration Tests (push) Has been cancelled
Integration Tests / AITM: API Integration Tests (push) Has been cancelled
Integration Tests / AITM: Core E2E Tests (push) Has been cancelled
Integration Tests / Integration Test Gate (push) Has been cancelled
License Check / Block GPL / noncommercial imports in product trees (push) Has been cancelled
Test Gate / Gitgram: Backend Tests (Jest) (push) Has been cancelled
Test Gate / AITM: Core Tests (Vitest) (push) Has been cancelled
Test Gate / AITM: API Server Tests (Vitest) (push) Has been cancelled
Test Gate / Test Gate (all products) (push) Has been cancelled
CI / Test: Gitgram Backend (push) Has been cancelled
Gitgram Tests / Test: Gitgram Backend (Jest) (push) Failing after 1m5s
Gitgram Tests / E2E: Gitgram Backend (Jest + supertest) (push) Failing after 32s
Gitgram Tests / Typecheck: Gitgram Web (push) Failing after 41s
Gitgram Tests / E2E Smoke: Gitgram Web (Playwright) (push) Failing after 41s
Some checks failed
CI / Test: Gitgram Web (push) Has been cancelled
CI / Test: AITM API Server (push) Has been cancelled
CI / Typecheck: Backend + Web (push) Has been cancelled
CI / Lint: Backend + Web (push) Has been cancelled
Integration Tests / Gitgram: API Integration Tests (push) Has been cancelled
Integration Tests / AITM: API Integration Tests (push) Has been cancelled
Integration Tests / AITM: Core E2E Tests (push) Has been cancelled
Integration Tests / Integration Test Gate (push) Has been cancelled
License Check / Block GPL / noncommercial imports in product trees (push) Has been cancelled
Test Gate / Gitgram: Backend Tests (Jest) (push) Has been cancelled
Test Gate / AITM: Core Tests (Vitest) (push) Has been cancelled
Test Gate / AITM: API Server Tests (Vitest) (push) Has been cancelled
Test Gate / Test Gate (all products) (push) Has been cancelled
CI / Test: Gitgram Backend (push) Has been cancelled
Gitgram Tests / Test: Gitgram Backend (Jest) (push) Failing after 1m5s
Gitgram Tests / E2E: Gitgram Backend (Jest + supertest) (push) Failing after 32s
Gitgram Tests / Typecheck: Gitgram Web (push) Failing after 41s
Gitgram Tests / E2E Smoke: Gitgram Web (Playwright) (push) Failing after 41s
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).
This commit is contained in:
parent
1dbb156695
commit
9ee51f797e
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user