Skip to content

fix(api): check email rate limit before updating newEmail - #68837

Closed
manduinca wants to merge 1 commit into
freeCodeCamp:mainfrom
manduinca:fix/update-email-rate-limit-order
Closed

manduinca wants to merge 1 commit into
freeCodeCamp:mainfrom
manduinca:fix/update-email-rate-limit-order

Conversation

@manduinca

Copy link
Copy Markdown

Checklist:

Closes #68738

The rate limit check on /update-my-email ran after the user.update, so a second request within the 5 minute window returned 429 but had already overwritten newEmail. That left the confirmation link sent to the first address broken, since /confirm-email checks it against the stored newEmail.

I moved the check before the update, next to the other early returns (own email, email already taken, etc.). Same message and status code as before, and it reuses the user we already loaded so there's no extra query.

I also extended the existing "second request returns 429" test to assert that newEmail still holds the first email after the rejected request. Confirmed it fails on main without the change and passes with it.

Followed the approach @Sembauke suggested in the issue.

@manduinca
manduinca requested review from a team as code owners July 15, 2026 05:08
@github-actions github-actions Bot added the platform: api Server application that needs familiarity with Express, Fastify, MongoDB etc. label Jul 15, 2026
@majestic-owl448 majestic-owl448 added the MERGE CONFLICT! To be applied to PR's that have a merge conflict and need updating label Jul 24, 2026
@Sembauke

Copy link
Copy Markdown
Member

Hey @manduinca,

Thanks for the pr, unfortunately we have chosen the other pull-request. Thanks for trying to contribute, have a nice day and happy coding!

@Sembauke Sembauke closed this Jul 24, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

MERGE CONFLICT! To be applied to PR's that have a merge conflict and need updating platform: api Server application that needs familiarity with Express, Fastify, MongoDB etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate-limited email changes overwrite user's pending email address (invalidating existing confirmation links)

3 participants