From 6e933a9970b86a84245d9fbe98a6bed747e3fce3 Mon Sep 17 00:00:00 2001 From: yiling Date: Wed, 3 Jun 2026 10:33:14 +0800 Subject: [PATCH] fix(auth): fix invite code bypass vulnerability --- packages/core/src/auth/auth.ts | 12 ++++++++++++ packages/core/src/invite/invite.ts | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/core/src/auth/auth.ts b/packages/core/src/auth/auth.ts index 71519f54..b3966f6c 100644 --- a/packages/core/src/auth/auth.ts +++ b/packages/core/src/auth/auth.ts @@ -42,6 +42,18 @@ export const auth = betterAuth({ }, ) } + + const isValid = await inviteService.validateInvite(inviteCode) + if (!isValid) { + return ctx.json( + { + error: 'Invalid or expired invite code', + }, + { + status: 400, + }, + ) + } } } }), diff --git a/packages/core/src/invite/invite.ts b/packages/core/src/invite/invite.ts index 8f8f8289..140a43b0 100644 --- a/packages/core/src/invite/invite.ts +++ b/packages/core/src/invite/invite.ts @@ -61,6 +61,22 @@ export class InviteService { return inv } + async validateInvite(code: string): Promise { + const inv = await prisma.invite.findUnique({ + where: { code }, + }) + + if (!inv) { + return false + } + + if (inv.used) { + return false + } + + return true + } + async consumeInvite(code: string, userId: string): Promise { await prisma.$transaction(async (tx) => { const inv = await tx.invite.findUniqueOrThrow({