mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 08:19:06 +00:00
fix(auth): fix invite code bypass vulnerability
This commit is contained in:
@@ -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,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user