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.
fix(auth): prevent email enumeration via resend-verification endpoint (#1414) #1742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(auth): prevent email enumeration via resend-verification endpoint (#1414) #1742
Changes from all commits
7a594aaFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the values persisted by
user.save.The test passes if the handler saves the existing
"old"token. Capture the token and expiry inside theuser.savemock. Assert that the saved token is a new 64-character hex value and that the saved expiry is in the future.Proposed test update
it("returns the SAME generic message for an unverified user but actually sends the email", async () => { const user = fakeUser({ isEmailVerified: false }); + let savedToken; + let savedExpiry; + user.save.mockImplementation(async () => { + savedToken = user.emailVerificationToken; + savedExpiry = user.emailVerificationExpires; + }); User.findOne.mockResolvedValue(user); const res = await request(buildApp()) .post("/api/auth/resend-verification") .send({ email: "Victim@Example.com" }); expect(res.status).toBe(200); expect(res.body.success).toBe(true); expect(res.body.message).toBe(GENERIC_MESSAGE); - // A fresh token must be issued and the verification email actually sent. expect(user.save).toHaveBeenCalled(); + expect(savedToken).not.toBe("old"); + expect(savedToken).toMatch(/^[0-9a-f]{64}$/); + expect(savedExpiry.getTime()).toBeGreaterThan(Date.now()); expect(sendMail).toHaveBeenCalledTimes(1); });📝 Committable suggestion
🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.