fix(auth): fix invite code bypass vulnerability

This commit is contained in:
yiling
2026-06-03 10:33:14 +08:00
parent 5ae7e408ec
commit 6e933a9970
2 changed files with 28 additions and 0 deletions
+12
View File
@@ -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,
},
)
}
}
}
}),
+16
View File
@@ -61,6 +61,22 @@ export class InviteService {
return inv
}
async validateInvite(code: string): Promise<boolean> {
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<void> {
await prisma.$transaction(async (tx) => {
const inv = await tx.invite.findUniqueOrThrow({