fix: invalidate old password reset tokens when new one is requested (#24607)
* fix: invalidate old password reset tokens when new one is requested Security fix: Previously, old password reset tokens remained valid even after requesting a new one, creating a potential account takeover vulnerability. This change ensures that when a user requests a new password reset link, all previous valid tokens for that email are immediately invalidated. Changes: - Expire all existing valid tokens before creating new one - Add E2E test to verify old tokens are invalidated - Prevent potential account takeover scenario Co-Authored-By: [email protected] <[email protected]> * Clean up code by removing blank line Removed unnecessary blank line in forgot-password.e2e.ts. * test: fix strict mode violation in password reset test Use getByRole to specifically target the heading element instead of text locator which was matching both the heading and button. Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
2 files changed
+79
-1
No files matched your search
@@ -10,6 +10,19 @@ const RECENT_PERIOD_IN_MINUTES = 5;
|
||||
|
||||
const createPasswordReset = async (email: string): Promise<string> => {
|
||||
const expiry = dayjs().add(PASSWORD_RESET_EXPIRY_HOURS, "hours").toDate();
|
||||
|
||||
await prisma.resetPasswordRequest.updateMany({
|
||||
where: {
|
||||
email,
|
||||
expires: {
|
||||
gt: new Date(),
|
||||
},
|
||||
},
|
||||
data: {
|
||||
expires: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
const createdResetPasswordRequest = await prisma.resetPasswordRequest.create({
|
||||
data: {
|
||||
email,
|
||||
|
||||
Reference in new issue
Block a user