← Blog
November 27, 202610 min readMethodologyAppSecAuthentication

How to test a password reset flow for account takeover

GitLab's CVE-2023-7028 sent password reset emails to unverified addresses and landed on CISA's exploited-vulnerabilities list at CVSS 10.0. A reset is a second way into an account, and it breaks in four predictable places. A stage-by-stage review plan: where the email goes, where the link points, what one token unlocks, and what survives the reset.

By The Xalgorix Team

On 11 January 2024 GitLab shipped a critical security release for CVE-2023-7028. On self-managed instances running 16.1 through 16.7, a password reset could deliver the reset email to an address the account owner had never verified, with no action required from the victim. GitLab rated it CVSS 10.0, traced it to a change in 16.1.0 (1 May 2023) that let users reset through a secondary email address, and credited a researcher who reported it through its HackerOne program. Its published indicator of compromise is the tell: requests to /users/password where the email field was a JSON array of several addresses. On 1 May 2024 CISA added the CVE to its Known Exploited Vulnerabilities catalog.

A password reset is a second way into an account, one that bypasses the password entirely. That makes it among the highest-value features to review and among the easiest to review badly: request a link, click it, set a password, call it tested. This is a review plan for the whole flow, written for engineers hardening their own reset path and for testers working with authorization. It moves stage by stage, naming what each control should do and how to tell from the outside whether it does.

A reset flow touches live mailboxes and can lock people out. Exercise it only against accounts and systems you own or are explicitly authorized to test, on staging where you can.

Split the flow into four stages

Every reset flow, whether it sends a link, a numeric code or a magic login, does the same four things. Each has its own failure modes, and a weakness in one stage is usually independent of the others, so it pays to reason about them separately.

Request
who is the account, where does mail go
Delivery
what the link points at
Redemption
what the token unlocks
Aftermath
what survives the reset
GitLab's CVE-2023-7028 broke stage 1; Host-header poisoning breaks stage 2; weak or reusable tokens break stage 3; surviving sessions break stage 4.

Stage 1: the request decides where the email goes

The reset endpoint does two jobs with one input: it finds the account, and it addresses the email. The bug class behind CVE-2023-7028 lives in the gap between them. If the account lookup and the mailer interpret the same submitted value differently, an input the lookup reads as “this one user” can be one the mailer reads as “this user and an extra recipient”.

The shape is easiest to see in code. This is an illustration of the anti-pattern, not any real product's source:

// Anti-pattern: the recipient is taken from the request, not from the stored record.
app.post("/password/forgot", async (req, res) => {
  const email = req.body.email;              // may arrive as a string OR an array
  const user = await User.findOne({ where: { email } });
  if (user) {
    const token = await issueResetToken(user);
    await mailer.sendMail({ to: email, text: resetLink(token) }); // <-- trusts input
  }
  res.send("If that account exists, we sent an email.");
});

When body parsing coerces a repeated or bracketed field into an array, the ORM can match the victim by one element while the mailer sends to every element, including the tester's own address. The defensive fix is one line and worth stating plainly: address the email to user.email — the stored, verified address — and never to a value echoed from the request. A good review here submits the endpoint a value that is unambiguous (a single string), and confirms the handler rejects or ignores anything that arrives as a collection of addresses rather than one.

Accounts that can hold more than one email, as GitLab's could after 16.1, deserve explicit attention. The question to answer for your own system: when a reset is requested via a secondary address, does the code confirm that address was verified before it becomes a valid destination for a reset link? An unverified secondary address that can receive resets is the exact condition GitLab patched.

Enumeration and throttling belong to this stage too

OWASP's Forgot Password Cheat Sheet asks for a consistent message for existing and non-existing accounts and a uniform response time. A handler that only mints a token and sends mail for real users is a classic source of a measurable timing difference, so compare status code, body, headers and latency for a registered versus an unregistered address across many samples. Separately, confirm the endpoint is rate-limited per account: an inbox buried in reset mail is a nuisance, but an unthrottled numeric code at stage 3 is a takeover.

Stage 2: where does the link actually point?

Many frameworks build the reset URL from the incoming request's host. PortSwigger documents the consequence as password reset poisoning: if the application derives the link's domain from the Host header (or a forwarded-host header a proxy trusts), that domain can be steered away from the real site, so a genuine token travels in a link that points elsewhere. PortSwigger also notes the token can leak without the victim clicking, because an automated link scanner may fetch it first.

The control to verify is that the reset URL's origin is fixed server-side — hard-coded or checked against an allowlist of canonical hostnames — and not reflected from request headers. A useful external check is to compare, for the same reset request, the host in the delivered link against the host the application is canonically served on; a mismatch, or any host that tracks the request's own headers, is the finding. Account for the front end and the application disagreeing about the host (duplicate headers, an absolute URL in the request line, an appended port), since a parser gap between them is where this slips through. Our OAST explainer covers reading a callback that arrives from a mail scanner rather than a person.

Two quieter leaks live in this stage. If the reset page loads any third-party script, image or analytics, a token in the URL can escape in the Referer header, which is why OWASP recommends Referrer-Policy: no-referrer on that page. And confirm the token is not returned in the reset endpoint's own HTTP response, a redirect, or a JSON field a mobile client ignores — if it is, the mailbox stops being a barrier at all.

Stage 3: what a token is allowed to unlock

Collect several tokens issued for an account you control and treat the OWASP token requirements as a checklist. A reset token should be:

  • Unpredictable and long. Generated with a cryptographically secure RNG and wide enough to defeat brute force. Compare a handful of tokens: structure, an embedded counter, a timestamp or anything short enough to guess is a problem.
  • Single-use. Redeeming it once must invalidate it. Confirm a used token cannot be replayed.
  • Short-lived. It should expire on a sensible timeout. Confirm an old token is refused rather than silently accepted.
  • Bound to one account. A token for one user must never set another user's password. Where the account id travels separately from the token, confirm swapping it is rejected.

Django's PasswordResetTokenGenerator is a good model of how to get single-use for free without server-side token storage. Its documented hash mixes the user's primary key, the current password hash, the last_login timestamp, a timestamp, and the email into a salted HMAC. Because the password hash and last_login both change at reset, the same token stops verifying afterwards, and PASSWORD_RESET_TIMEOUT expires it regardless. That is the property to design toward, by whatever mechanism: a token tied to state that a reset necessarily changes.

Numeric codes are the sharp edge of this stage. A six-digit code is only a million values, so without strict per-account attempt limits and a tight expiry it is guessable. Confirm the code is invalidated after a small number of wrong guesses, and that requesting a fresh code retires the previous one rather than widening the pool of valid answers.

Stage 4: what survives the reset

The job is not finished when the new password is set. Changing a password is the standard response to a suspected compromise, so a reset must cut off whatever an intruder might already hold.

After a successful reset: invalidate the user's other active sessions, invalidate any still-outstanding reset tokens for that account, and email the user that their password changed (without including the password).

Verify each of those as an outsider to the reset:

  • Sign in as the account in a second browser, reset the password in the first, then act in the second. A still-live session there means an attacker who had a foothold keeps it.
  • Request two tokens, redeem one, then try the other. A second token that still works after the password changed is a reusable key left on the mat.
  • Confirm the reset does not silently log the visitor straight in. OWASP advises against auto-login after reset; the user should authenticate through the normal path.
  • Confirm the change notification actually arrives, so a reset the real owner did not request is visible to them.

Where automated checks stop

Most of stage 2 and parts of stage 3 are within reach of scanners: a reflected host in a reset link, a token in a Referer, a missing expiry are all patterns a tool can flag. The stage-1 bugs, and the account-binding checks, are mostly not. Whether a reset reaches an unverified secondary address, or whether a token minted for one account can set another's password, depends on application state a scanner has no model of: which addresses are verified, which account a token belongs to, what “the victim” even means across two linked records. CVE-2023-7028 was a single mis-handled parameter, invisible to anything that did not reason about the relationship between the lookup and the mailer.

This is the seam Xalgorix works in: confirming a reported reset weakness by driving the actual multi-step flow against accounts under test, rather than inferring it from a response pattern. It does not remove the engineering judgment this article is about — deciding which addresses are trusted destinations, and which state a token must be bound to, is a design decision no tool makes for you. The checklist across the four stages is what turns a reset flow from a second front door into a locked one.

Ready to see it prove a bug?

Start scanning on Cloud →