Skip to content

Commit

Permalink
fix: email enumeration vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Jan 24, 2024
1 parent 0413c42 commit f099ccf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
43 changes: 21 additions & 22 deletions backend/src/api/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,30 @@ export async function sendForgotPasswordEmail(
): Promise<MonkeyResponse> {
const { email } = req.body;

let auth;
try {
auth = await FirebaseAdmin().auth().getUserByEmail(email);
} catch (e) {
if (e.code === "auth/user-not-found") {
throw new MonkeyError(404, "User not found");
}
throw e;
}

const userInfo = await UserDAL.getUser(
auth.uid,
"request forgot password email"
);
const uid = (await FirebaseAdmin().auth().getUserByEmail(email)).uid;
const userInfo = await UserDAL.getUser(
uid,
"request forgot password email"
);

const link = await FirebaseAdmin()
.auth()
.generatePasswordResetLink(email, {
url: isDevEnvironment()
? "http://localhost:3000"
: "https://monkeytype.com",
});
await emailQueue.sendForgotPasswordEmail(email, userInfo.name, link);
const link = await FirebaseAdmin()
.auth()
.generatePasswordResetLink(email, {
url: isDevEnvironment()
? "http://localhost:3000"
: "https://monkeytype.com",
});

return new MonkeyResponse("Email sent if user was found");
await emailQueue.sendForgotPasswordEmail(email, userInfo.name, link);
} catch {
return new MonkeyResponse(
"Password reset request received. If the email is valid, you will receive an email shortly."
);
}
return new MonkeyResponse(
"Password reset request received. If the email is valid, you will receive an email shortly."
);
}

export async function deleteUser(
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/ts/popups/simple-popups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,10 @@ list["forgotPassword"] = new SimplePopup(

return {
status: 1,
message: "Password reset email sent",
message: result.message,
notificationOptions: {
duration: 8,
},
};
},
(thisPopup) => {
Expand Down

0 comments on commit f099ccf

Please sign in to comment.