Skip to content
Race condition Write-up Advanced

Race Condition Authentication Bypass leads to Full Account Takeover

The login flow allowed changing the email associated with a flowId after an OTP was sent, and a race condition between updating the email and validating the OTP let an attacker authenticate as any user by knowing their email address.

Keizo Follow

Published on medium.com

Bug bounty research was conducted to an large cap company with an eCommerce web application that facilitates purchasing and ordering of various products. The scope of this adventure focused on login functions.

Keizo, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

The research targeted a large cap company running an eCommerce web application for purchasing and ordering various products. The scope was deliberately narrow: the login functions. That login mechanism uses One-Time Passwords (OTPs) delivered by email or SMS, and it is implemented as a multi-step flow. A unique identifier, flowId, is carried through the steps and tells the backend which account the OTP token is being validated for.

The researcher flags the multi-step structure itself as a concern, because complex flows are prone to flow manipulation. The request flow is described as follows:

  • POST /init-email: initiates the login process with the user's email and associates it with the specified flowId.
  • POST /send-email: sends the OTP to the designated email linked to the flowId.
  • POST /check-otp: validates the OTP provided by the user.

Each request includes the flowId parameter, which points the request actions to the specific user attached to that flowId.

From the original on medium.com

Setup

The report does not describe the accounts used, the tool versions, or any other preconditions beyond the following. The decisive capability was Burp Suite's turbo-intruder tool, after its enhancements following James Kettle's publication of "Smashing the State Machine" and the later post on new techniques and tools for web race conditions. Before that publication the research had stalled, because there was no applicable method to bypass the authentication in use. After it, the research resumed with a focus on a race condition.

Finding it

The first observation was that the three requests can be sent in different orders. For example, the email step can be initiated before sending the OTP, but also after it. In theory this creates odd states. The researcher tried the obvious manipulation: initialise an email for one user, send the OTP, then initialise an email for another user and try to log in with the first user's OTP. That attempt was unsuccessful.

What made the flow interesting was the combination of two properties: the email attached to a flow can still be changed after the OTP has been generated for a different email, and the backend handles email initialisation and OTP validation in separate threads. If those two operations run at the same time, the validation can succeed against the state that existed before the email was swapped, while the token that is finally issued is looked up from the state after the swap.

Exploitation

Step 1: start a normal login for the attacker's own account

The attacker initiates the email and sends the OTP request as usual, for their own address. This produces a flowId and an OTP delivered to the attacker's mailbox.

Step 2: prepare two parallel requests

Upon receiving the OTP, the attacker configures Burp Suite Repeater to send two requests in parallel:

  1. init-email carrying the victim's email address, on the same flow.
  2. check-otp carrying the OTP the attacker received.

The report does not reproduce the raw HTTP requests, so the exact bodies, headers and parameter placement are not shown here.

Step 3: send them simultaneously

By sending these requests simultaneously, the attacker successfully logs in as the victim.

Blue and Red express simultaneous requests and threads From the original on medium.com

Blue and Red express simultaneous requests and threads

The "parallel" requests method, also called a single packet attack, means sending multiple HTTP/2 packets inside a single TCP packet. That makes it possible to send multiple requests to the server that all arrive at the same moment. The researcher recommends reading Kettle's research on the topic for the underlying detail.

What happens in the backend

The race plays out across two threads:

  1. [Thread A]: initiates the email initialisation for the victim's email, associated with the previously initialised flowId that belongs to the attacker. This succeeds.
  2. [Thread B]: concurrently checks the validity of the OTP for the specified flowId. This also succeeds, because the first thread has not yet changed the flowId email to match the victim's email.
  3. [Thread B]: having confirmed the OTP is valid, it proceeds to retrieve the token for the user specified in the flowId. Since the first thread has now updated the email value, the token retrieved belongs to the victim user.

Root cause

The vulnerability has two contributing causes, both stated in the report. First, business logic is violated: the email associated with the flow can be changed even after the OTP was generated for another email. Second, the backend uses multiple threads for email initialisation and OTP validation, so the check and the lookup of the account to issue a token for do not see a single consistent state. The validation thread confirms the OTP against the pre-swap state and then reads the post-swap email when it fetches the token.

The report does not describe any additional defence, such as per-flow locking or binding the OTP to the email it was issued for, that would have stopped the attack.

Impact

As a result of the vulnerability it was possible to authenticate as any user on the website solely by knowing their email address. The issue was reported to the company, which assigned it a critical severity status and paid a substantial bounty reward.

Fix

Variants to test

  1. Multi-step OTP logins with a flow identifier. Map every request that carries the flow identifier and try reordering them, as the researcher did first. A positive result is any order that produces a valid session or a token for an account other than the one the OTP was sent to.
  2. Mutable identity fields mid-flow. Look for any step that lets you change the email, phone number or user identifier attached to a flow after the OTP has been issued. A positive result is the change being accepted without invalidating the existing OTP.
  3. Single packet attacks on the swap and the check. Send the identity-changing request and the OTP validation request together as HTTP/2 packets in one TCP packet. A positive result is a session issued for the new identity while the OTP was delivered to the old one.
  4. The same pattern outside login. Anywhere a status check and a state change run in separate threads, such as redemption or limit checks, the same timing applies. A positive result is the operation succeeding more times, or for a different subject, than the business rules allow.
From the original on medium.com
By utilizing race condition it is possible to redeem the same gift card multiple times

By utilizing race condition it is possible to redeem the same gift card multiple times

The gift card example is the typical limit-overrun shape of a race condition: one thread verifies the status of the gift card while another marks it as utilised, so the card can be applied multiple times, a "free money glitch". The login case is the same race applied to identity instead of value.

A closing note from the report: write-ups make these findings look straightforward, but in practice it takes several iterations and trial and error before anything is found, and more often nothing is found at all. If it were easy, someone else would have discovered it first.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A security researcher tested the login page of a large company's online shop. The shop sells and orders various products. The researcher only looked at one thing: how you log in. This shop does not use a password. Instead, when you type your email address, it sends you a short code by email or text message. You type that code in and you are logged in. This kind of code is called a One-Time Password, or OTP. It is like a hotel key card that only works once and only for the room you booked.

The researcher found a way to log in as any user of the shop, just by knowing that person's email address. No password, no code from the victim's phone or mailbox. The trick relies on making two requests to the server at exactly the same moment, so that the server gets confused about whose account it is logging in. This kind of bug is called a race condition, and the result is called account takeover.

The company rated the issue critical and paid a substantial bounty reward. The report does not give the amount or a CVSS score.

The product and the login feature

The target is an eCommerce web application: a website where customers browse products, put them in a basket and order them. The scope of the research was deliberately narrow: the login functions only.

The login is a multi-step flow. "Multi-step" means the browser does not send one single request to log in; it sends several requests in a row, each doing one small job. The server needs to remember, between those steps, which login attempt is which. It does that with a unique identifier called flowId. You can think of flowId as a claim ticket at a cloakroom: you hand in your coat, you get a ticket with a number, and later you show the ticket to get your coat back. The server hands your browser a flowId and expects it back with every following request, so it knows which login attempt the request belongs to.

The researcher flagged this multi-step structure as a concern in itself, because complex flows are easy to manipulate. The more steps and the more state the server has to keep, the more chances there are to send steps in an order the developers did not expect.

The request flow is described as follows:

  • POST /init-email: initiates the login process with the user's email and associates it with the specified flowId.
  • POST /send-email: sends the OTP to the designated email linked to the flowId.
  • POST /check-otp: validates the OTP provided by the user.

Each request includes the flowId parameter, which points the request actions to the specific user attached to that flowId.

From the original on medium.com

What the three requests mean, in everyday terms:

  1. POST /init-email is the browser telling the server "I want to log in, here is my email address, please start a login attempt for me". The server creates a flowId and ties it to that email address. POST is simply the HTTP method used when you send data to a server, as opposed to GET, which is used when you just ask for a page. /init-email is the address of that particular action on the server, like a counter number in a large office building.
  2. POST /send-email is the browser saying "now please actually send the code to the email address on this ticket". The server generates the OTP and emails it.
  3. POST /check-otp is the browser saying "here is the code the user typed in, is it correct for this ticket?". If yes, the server logs the user in, typically by giving the browser a token.

A token, in this context, is a small piece of data the server gives your browser after a successful login. Your browser sends it back with every later request, and the server treats its presence as proof that you are logged in. It works like a wristband at a festival: once you have it, the staff at every stage let you through without asking for your ticket again. The report does not describe the exact form of the token.

Setting up the research

Burp Suite is a tool that sits between your browser and a website, so you can look at every request the browser sends and change it before it goes out. Think of it as an inspector standing between you and a counter, who lets you read and rewrite the forms before you hand them over.

The decisive capability was Burp Suite's turbo-intruder tool, after its enhancements following James Kettle's publication of "Smashing the State Machine" and the later post on new techniques and tools for web race conditions. Before that publication the research had stalled, because there was no applicable method to bypass the authentication in use. After it, the research resumed with a focus on a race condition.

A race condition is a bug that appears when two things happen at the same time and the result depends on which one finishes first. A simple everyday comparison: two people try to book the last seat on a plane at the same instant. Each one checks "is the seat free?", each one sees "yes", and each one books it. The seat is sold twice because the check and the booking were not done as one indivisible action. In software, the server handles each incoming request in a separate thread. A thread is one worker inside the program doing a job. If two workers read and write the same information without coordinating, they can step on each other.

Finding it

The first observation was that the three requests can be sent in different orders. For example, the email step can be initiated before sending the OTP, but also after it. In theory this creates odd states. The researcher tried the obvious manipulation: initialise an email for one user, send the OTP, then initialise an email for another user and try to log in with the first user's OTP. That attempt was unsuccessful.

Why try that? Because if the server lets you change the email address attached to a login attempt after the code has already been sent, you might be able to get a code sent to your own mailbox and then point the same attempt at someone else's account. The server refused to cooperate when the steps were done one after another.

What made the flow interesting was the combination of two properties: the email attached to a flow can still be changed after the OTP has been generated for a different email, and the backend handles email initialisation and OTP validation in separate threads. If those two operations run at the same time, the validation can succeed against the state that existed before the email was swapped, while the token that is finally issued is looked up from the state after the swap.

"Backend" means the part of the system you never see: the programs and databases behind the website that do the actual work. "State" means the current values the server is holding for your login attempt, in this case mainly which email address is attached to the flowId.

Exploitation

Step 1: start a normal login for the attacker's own account

The attacker initiates the email and sends the OTP request as usual, for their own address. This produces a flowId and an OTP delivered to the attacker's mailbox.

Why start with your own account? Because you need a valid flowId and a valid OTP that you can actually read. The attacker controls their own mailbox, so they can see the code. The plan is to later redirect that same login attempt at the victim's account.

Step 2: prepare two parallel requests

Upon receiving the OTP, the attacker configures Burp Suite Repeater to send two requests in parallel:

  1. init-email carrying the victim's email address, on the same flow.
  2. check-otp carrying the OTP the attacker received.

Repeater is the part of Burp Suite that lets you take a single captured request, edit it and send it again as many times as you like. "In parallel" means both requests are sent at the same moment rather than one after the other.

The report does not reproduce the raw HTTP requests, so the exact bodies, headers and parameter placement are not shown here.

Step 3: send them simultaneously

By sending these requests simultaneously, the attacker successfully logs in as the victim.

Blue and Red express simultaneous requests and threads From the original on medium.com

Blue and Red express simultaneous requests and threads

The "parallel" requests method, also called a single packet attack, means sending multiple HTTP/2 packets inside a single TCP packet. That makes it possible to send multiple requests to the server that all arrive at the same moment. The researcher recommends reading Kettle's research on the topic for the underlying detail.

A short explanation of those terms. HTTP is the language browsers and servers speak. HTTP/2 is a newer version of it that can carry several requests over one connection at once. TCP is the underlying transport that delivers bytes reliably between two machines, like a postal service that guarantees delivery and keeps things in order. A packet is one envelope of data. Normally, if you click send twice, the two requests travel as two separate envelopes and the server may finish the first long before the second arrives. A single packet attack puts both requests in the same envelope, so the server receives them together and starts working on them at effectively the same instant. That is what makes the timing reliable enough to exploit.

What happens in the backend

The race plays out across two threads:

  1. [Thread A]: initiates the email initialisation for the victim's email, associated with the previously initialised flowId that belongs to the attacker. This succeeds.
  2. [Thread B]: concurrently checks the validity of the OTP for the specified flowId. This also succeeds, because the first thread has not yet changed the flowId email to match the victim's email.
  3. [Thread B]: having confirmed the OTP is valid, it proceeds to retrieve the token for the user specified in the flowId. Since the first thread has now updated the email value, the token retrieved belongs to the victim user.

In plain words: worker A is busy changing the name on the claim ticket from the attacker to the victim. Worker B, at the same moment, checks the code against the ticket. When B looks, the name is still the attacker's, so the attacker's code is accepted. But then B goes to fetch the wristband, and by that time worker A has finished writing the victim's name on the ticket. So B hands out the victim's wristband. The check and the hand-out saw two different versions of the same ticket.

Root cause

The vulnerability has two contributing causes, both stated in the report. First, business logic is violated: the email associated with the flow can be changed even after the OTP was generated for another email. Second, the backend uses multiple threads for email initialisation and OTP validation, so the check and the lookup of the account to issue a token for do not see a single consistent state. The validation thread confirms the OTP against the pre-swap state and then reads the post-swap email when it fetches the token.

"Business logic" means the rules the site is supposed to follow, the ones a human would write down: a code sent to one address should only ever log in the owner of that address. The code did what it was told at each individual step, but the steps together broke the rule.

Impact

As a result of the vulnerability it was possible to authenticate as any user on the website solely by knowing their email address. The issue was reported to the company, which assigned it a critical severity status and paid a substantial bounty reward.

Email addresses are not secret. They appear on business cards, in newsletters, in old forum posts. So "any user, knowing only their email" means effectively any account on the shop could be taken over by someone who knew where to look.

Fix

In everyday terms: once the claim ticket has a name on it and a code has been sent, the name must be frozen. And the worker who checks the code and the worker who hands out the wristband must look at the same, single version of the ticket, not two versions that can change between glances.

Variants to test

  1. Multi-step OTP logins with a flow identifier. Map every request that carries the flow identifier and try reordering them, as the researcher did first. A positive result is any order that produces a valid session or a token for an account other than the one the OTP was sent to.
  2. Mutable identity fields mid-flow. Look for any step that lets you change the email, phone number or user identifier attached to a flow after the OTP has been issued. A positive result is the change being accepted without invalidating the existing OTP.
  3. Single packet attacks on the swap and the check. Send the identity-changing request and the OTP validation request together as HTTP/2 packets in one TCP packet. A positive result is a session issued for the new identity while the OTP was delivered to the old one.
  4. The same pattern outside login. Anywhere a status check and a state change run in separate threads, such as redemption or limit checks, the same timing applies. A positive result is the operation succeeding more times, or for a different subject, than the business rules allow.
From the original on medium.com
By utilizing race condition it is possible to redeem the same gift card multiple times

By utilizing race condition it is possible to redeem the same gift card multiple times

The gift card example is the typical limit-overrun shape of a race condition: one thread verifies the status of the gift card while another marks it as utilised, so the card can be applied multiple times, a "free money glitch". The login case is the same race applied to identity instead of value.

A closing note from the report: write-ups make these findings look straightforward, but in practice it takes several iterations and trial and error before anything is found, and more often nothing is found at all. If it were easy, someone else would have discovered it first.

Glossary

  • Account takeover: a situation where an attacker gains control of someone else's account, here by logging in as them.
  • API: a defined set of addresses and rules a program exposes so other programs can ask it to do things; the login endpoints in this report are the shop's API for logging in.
  • Authentication: the process of proving who you are, usually by logging in.
  • Backend: the programs and databases behind a website that do the actual work, which users never see directly.
  • Bounty: a reward a company pays to someone who reports a security problem to it.
  • Burp Suite: a tool that sits between a browser and a website so requests can be inspected, edited and resent.
  • Business logic: the rules a site is supposed to follow in its own domain, such as "a code sent to one address only logs in that address".
  • Critical severity: the highest level in the usual severity scale, meaning the issue is serious and should be fixed urgently.
  • CVSS: a standard scoring system for the severity of security issues; the report gives no score.
  • eCommerce web application: a website where customers browse, buy and order products.
  • Endpoint: one specific address on a server that performs one action, such as /check-otp.
  • flowId: a unique identifier the server gives to one login attempt so it can recognise the following requests as belonging to that attempt.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • HTTP/2: a newer version of HTTP that can carry several requests over one connection at the same time.
  • Limit-overrun: a bug where an action that should be allowed a limited number of times can be performed more often than intended, such as using a gift card repeatedly.
  • OTP (One-Time Password): a short code sent to you by email or text message that is valid once and only for a short time.
  • Packet: one unit of data sent across a network, like one envelope in the post.
  • Parallel requests: two or more requests sent at the same moment rather than one after another.
  • POST: the HTTP method used when a browser sends data to a server, as opposed to simply asking for a page.
  • Race condition: a bug that occurs when two operations run at the same time and the outcome depends on which one finishes first.
  • Repeater: the part of Burp Suite that lets you edit a captured request and send it again.
  • Single packet attack: sending several HTTP/2 requests inside one TCP packet so they all reach the server at the same instant.
  • State: the current values a server is holding for something, here mainly which email address is attached to a flowId.
  • TCP: the underlying network protocol that delivers data reliably between two machines.
  • Thread: one worker inside a program doing a job; a server can run many at once.
  • Token: a piece of data the server gives your browser after login, which the browser sends back to prove it is logged in.
  • Turbo-intruder: a Burp Suite extension for sending large numbers of requests, including in tightly synchronised bursts.
  • Vulnerability: a weakness in software that an attacker can use to make it behave in a way its owners did not intend.

More by Keizo

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.