Skip to content

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

Closed

Description

@chauhan-varun

Describe the Issue

PUT /update-my-email writes the requested address to user.newEmail before checking whether an email confirmation was sent within the rate-limit window. If a user requests a change to address A and then requests address B within five minutes, the second request returns 429, but newEmail has already changed to B.

The confirmation link sent to A then fails because /confirm-email requires the link's email to equal the current targetUser.newEmail.

Affected Page

/update-my-email and /confirm-email endpoints (defined in settings.ts).

Steps to Reproduce

  1. Request an email change to address A (e.g., via PUT /update-my-email with { "email": "[email protected]" }).
  2. Before five minutes have passed, request an email change to address B (e.g., via PUT /update-my-email with { "email": "[email protected]" }).
  3. Observe that the second request returns 429 (Too Many Requests) and no message is sent to B.
  4. Open the confirmation link previously sent to A (which contains address A in the encoded email query param).
  5. The link is rejected because the stored newEmail in the database has already been updated to B.

Expected behavior

A rate-limited request should not modify the pending email address. The confirmation link already sent to A should remain valid.

System

  • Device: N/A (API Bug)
  • OS: Linux
  • Browser: N/A
  • Version: N/A

Additional context

Suggested Fix:
Check emailAuthLinkTTL before updating newEmail, emailVerified, or emailVerifyTTL in settings.ts. Ensure that if the rate-limit check fails, the request returns 429 without making any database changes to the user's pending email configuration.

Activity

  1. added
    platform: api
    status: waiting triage
    on Jul 11, 2026
  2. ManyaB2005 commented on Jul 12, 2026

    @ManyaB2005
    Contributor

    Hi! I investigated this issue and was able to identify the problematic flow in the "/update-my-email" handler. I'd like to work on fixing it. Could you please assign it to me? Thanks!

  3. added
    help wanted
    and removed
    status: waiting triage
    on Jul 14, 2026
  4. Sembauke commented on Jul 14, 2026

    @Sembauke
    Member

    Confirmed, thanks for the clear report.

    The current /update-my-email flow updates newEmail, emailVerified, and emailVerifyTTL before checking emailAuthLinkTTL for the general resend rate limit. So a second request to a different address within the five-minute window returns 429, but still changes user.newEmail. That then causes the original /confirm-email link to fail because it no longer matches the stored pending email.

    A fix should move the emailAuthLinkTTL rate-limit check ahead of the user update, so a rate-limited request exits without mutating the pending email state. Please include a regression test for the "request A, immediately request B, B returns 429 and newEmail remains A" case.

  5. saikiranrayabarapu commented on Jul 14, 2026

    @saikiranrayabarapu
    Contributor

    I'm looking into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedplatform: api

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions