feat: implement secure forgot password flow with hashed tokens (#1426) - #1467
Open
jayshreerathoreai32-hue wants to merge 1 commit into
Open
Conversation
|
@jayshreerathoreai32-hue is attempting to deploy a commit to the jiya's projects Team on Vercel. A member of the Team first needs to authorize it. |
✅ Deploy Preview for codevibeforyou ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1426
Description
This PR finalizes and secures the backend Forgot Password / Password Reset workflow.
Previously, password reset tokens were generated and stored directly in the database as plain-text values. This created a potential security vulnerability because anyone who gained unauthorized access to the database could potentially use active reset tokens to reset user passwords.
This PR addresses the issue by introducing one-way SHA-256 hashing for reset tokens before database storage, securely validating tokens during password reset, and adding comprehensive automated tests for the complete password recovery flow.
Problem Statement
The application previously lacked a fully secure and tested password reset flow.
The main security concern was that generated password reset tokens were stored directly in the database without hashing. Since reset tokens function as temporary credentials, storing them in plain text increases the impact of a potential database compromise.
The implementation also required additional test coverage to ensure that reset emails, token validation, token invalidation, and invalid reset requests behave correctly.
Changes Included
1. Secure Password Reset Token Hashing
forgotPassword.jsto hash generated reset tokens using SHA-256 before storing them in the database.2. Secure Token Validation
resetPassword.jsto securely validate incoming reset tokens.3. Password Reset Token Invalidation
4. Comprehensive Automated Testing
Added
passwordReset.test.jswith isolated tests covering the password reset workflow.The tests mock:
The test coverage verifies that:
5. Additional Routing Fix
rateLimiter.jsthat was identified while running the password reset tests.Security Improvements
This PR significantly improves the security of the password recovery system.
The reset token now follows the same general security principle used for passwords and other sensitive credentials: the database never needs to store the usable plain-text token.
The updated flow is: