The lab
here is how portswigger describes it
This lab's email change feature contains a race condition that enables you to associate an arbitrary email address with your account. Someone with the address
[email protected]has a pending invite to be an administrator for the site, but they have not yet created an account. Therefore, any user who successfully claims this address will automatically inherit admin privileges. To solve the lab: identify a race condition that lets you claim an arbitrary email address, change your email address to[email protected], access the admin panel, delete the user carlos. You can log in to your own account with the following credentials:wiener:peter. You also have access to an email client, where you can view all emails sent to@exploit-<YOUR-EXPLOIT-SERVER-ID>.exploit-server.netaddresses.
the new pieces in this lab#
this is a single-endpoint race, we hit one endpoint (POST /my-account/change-email) with concurrent requests, but the twist is subtle: two internal sub-operations of that one request disagree about which email they're handling, so a confirmation email ends up sent to one address while confirming a different one.
- the email-change flow has two parts that are not atomic:
- it kicks off a task that eventually sends a confirmation email to the address in this request.
- that task later reads the pending email from the database and uses it to render the email body (which address is being confirmed, and the unique confirmation token). the recipient comes from the request; the body/token comes from whatever the database holds at render time.
- the site stores only one pending email address at a time, submitting a new change overwrites that single database entry rather than appending. (we confirm this: an older confirmation link stops working once a newer change is submitted.) a single, overwritable slot shared across requests is exactly the shared, mutable state a race needs.
- the race window is between step 1 (task kicked off, recipient fixed to this request's address) and step 2 (task reads the DB to build the body). if a parallel request overwrites the pending-email slot during that window, the email goes to request A's recipient but its body confirms request B's address.
- why this matters for the goal: we cannot receive mail at
[email protected], so we can't normally confirm that address. but if we race a change to our readable exploit inbox against a change to[email protected], we can get the confirmation link for carlos's address delivered to our own inbox, click it, and claim the address, inheriting the pending admin invite. the method: confirm the single-slot pending-email behaviour, benchmark serial vs parallel to see that parallel requests cause recipient/body mismatches, then race one change to our exploit address against one to[email protected]until a confirmation email arrives in our inbox whose body confirms[email protected], click it, and take over as admin.
why the mismatch happens#
the email-change endpoint does two things that assume a stable pending-email value between them: it fixes the recipient of the confirmation mail to the address in the triggering request, and then, a moment later, the sending task reads the current pending email from the single database slot to render the body and token. the developer assumed that between kicking off the task and rendering it, the pending email can't change. but the slot is shared and overwritable, and the two sub-operations aren't atomic. so if a second change-email request overwrites the slot inside that window, the first task sends its mail to its own recipient while rendering a body for the second request's address. the recipient and the confirmed address, normally guaranteed to match, come unstuck. we weaponise that by making the recipient an inbox we control and the confirmed address the privileged [email protected] we can't otherwise receive mail for.
Step 1 - learn the confirmation flow#
we log in and change our email to anything@exploit-<ID>.exploit-server.net. a confirmation email is sent to the intended new address, and we're prompted to click a link containing a unique token to confirm the change.

Step 2 - complete a normal change#
we complete the process and confirm our email address has updated on the account page, the normal, single-request flow works as designed.

Step 3 - probe the pending-email storage#
we submit two different @exploit-<ID>.exploit-server.net addresses in succession and go to the email client.


we notice that the first confirmation link we received is no longer valid. so the website stores only one pending email at a time, submitting a new address edits that single database entry rather than appending a new one. that overwritable shared slot is our collision opportunity.
Step 4 - benchmark serially#
we send POST /my-account/change-email to Repeater, add the tab to a group, right-click Duplicate tab, and make 19 duplicates (auto-added to the group).

in each tab we make the local part of the email unique (test1@..., test2@..., test3@..., and so on). we send the group in sequence over separate connections.

back in the email client we see one confirmation email per request, each recipient matching its own address, serially, everything lines up.

Step 5 - probe with a parallel burst#
in Repeater we send the same group again, but this time in parallel, effectively trying to set the pending email to many different values at once. studying the new confirmation emails, the recipient address doesn't always match the pending new email address in the body. that's the tell: a parallel request overwrote the pending email in the database during the window between kicking off the send task and rendering the email template.

Step 6 - prove the concept with two requests#
in Repeater we create a new group with two copies of POST /my-account/change-email:
-
one with
email = anything@exploit-<ID>.exploit-server.net(an inbox we can read). -
one with
email = [email protected](the privileged address). we send the two in parallel and check our inbox: -
if the confirmation email's body shows our own address, we resend in parallel and try again.
-
if the body shows
[email protected], we click the confirmation link to update our address to it. our account page now shows a link for accessing the admin panel, we inherited the pending admin invite tied to[email protected].

Step 7 - delete carlos#
we visit the admin panel and delete the user carlos.

how the whole attack worked, in detail#

the intended (serial) flow. you submit a new email; the app stores it as the single "pending email", sends a confirmation link to that address, and only updates your account when you click the link (proving you control the inbox). the recipient of the mail and the address inside the mail are always the same, because between storing the pending email and sending the confirmation, nothing changes it. requiring you to click a link sent to the address is what stops you claiming an inbox you don't own.
the two sub-operations that race. sending the confirmation is not one atomic action. first, a task is kicked off whose recipient is fixed to the address in the request that triggered it. then, slightly later, that task reads the current pending email from the database to render the body (the address being confirmed and its token). the recipient is bound early, to the triggering request; the body is bound late, to whatever the database says when the template renders.
the single shared slot. the site keeps only one pending-email value, and each new change overwrites it (Step 3). so the pending email is shared, mutable state that any concurrent change-email request can clobber, the collision requirement.
the race window and the collision. the window is between "task kicked off (recipient fixed)" and "task reads DB to render body". we fire two change-email requests in parallel:
- request A sets the pending email to our exploit inbox and kicks off a send task with recipient = our inbox.
- request B overwrites the pending email to
[email protected]. if B's overwrite lands inside A's window, A's task sends mail to our inbox (recipient fixed early) but renders the body/token for[email protected](read late from the DB). the result is a valid confirmation link for[email protected]delivered to an inbox we can actually read. why that defeats the email-ownership check. normally you can only confirm an address you can receive mail at, that's the whole point of the emailed link. the race breaks the binding between "who the mail is sent to" and "which address it confirms", so we obtain a confirmation token for an address ([email protected]) we could never receive mail for. clicking it sets our account's email to that address.
the payoff. [email protected] has a pending admin invite, so claiming the address auto-grants admin. our account page gains the admin panel link; we open it and delete carlos. because the race is probabilistic, we just resend the parallel pair until the body shows [email protected].
the root cause in one line. a confirmation email's recipient was bound early (to the request) while its contents were bound late (to an overwritable shared pending-email slot), so a concurrent overwrite split the two, delivering a privileged address's confirmation link to an attacker-controlled inbox.
with this, the lab is solved!
