Skip to content

Commit

Permalink
fix: oauth vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Jan 8, 2025
1 parent aa9f079 commit 34a993f
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/lib/middleware/withOAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,7 @@ export const withOAuth =
},
});
} catch (e) {
logger.debug(`Failed to find existing oauth. Using fallback. ${e}`);
if (e.code === 'P2022' || e.code === 'P2025') {
const existing = await prisma.user.findFirst({
where: {
oauth: {
some: {
provider: provider.toUpperCase() as OauthProviders,
username: oauth_resp.username,
},
},
},
include: {
oauth: true,
},
});
existingOauth = existing?.oauth?.find((o) => o.provider === provider.toUpperCase());
if (existingOauth) existingOauth.fallback = true;
} else {
logger.error(`Failed to find existing oauth. ${e}`);
}
logger.error(`Failed to find existing oauth, this likely will result in a failure: ${e}`);
}

const existingUser = await prisma.user.findFirst({
Expand Down Expand Up @@ -157,7 +138,7 @@ export const withOAuth =
logger.info(`User ${user.username} (${user.id}) logged in via oauth(${provider})`);

return res.redirect('/dashboard');
} else if ((existingOauth && existingOauth.fallback) || existingOauth) {
} else if (existingOauth) {
await prisma.oAuth.update({
where: {
id: existingOauth?.id,
Expand Down

0 comments on commit 34a993f

Please sign in to comment.