The art of Race Condition:how a simple race condition can leads to ATO!
The password reset flow allowed multiple OTPs to remain valid when resend requests were sent concurrently, because older tokens were not atomically invalidated. An attacker could accumulate a pool of valid codes and test them without hitting the five-attempt lockout, leading to account takeover.
Published on medium.com
Bug Bounty
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.
Context
The target was a web application the researcher was testing during bug bounty work. The feature in scope is the Password Reset / Forgot Password flow, specifically the OTP verification step. The application sends a 6-digit numeric OTP to the account email and requires it to be entered before the password can be reset. Standard controls were in place: rate limiting on the verification endpoint and a hard limit of 5 failed attempts per OTP.
The researcher's goal was to reach a full Account Takeover (ATO) by getting past the OTP check without access to the victim's mailbox.
Setup
The report does not describe the tooling, the number of accounts used, or any version information. The only precondition that matters is that the attacker can reach the forgot password endpoint and trigger OTP generation for the victim's email address, which is the normal starting point of any password reset flow. No prior session access to the victim account was needed.
Finding it
The researcher first mapped the flow as implemented by the application:
- Initiate Request: enter the account email into the forgot password endpoint.
- OTP Generation: a 6-digit numeric OTP is sent to the user.
- Validation Limits: the application strictly enforced a maximum of 5 failed attempts per OTP to prevent brute-forcing.
The usual vectors were tested first, and all of them held:
- Rate-Limiting: robustly implemented on the verification endpoint, blocking after multiple rapid requests.
- Response Manipulation: handled properly; the system validated the OTP correctly and did not accept a manipulated response.
- Old OTP Invalidation: previously generated OTPs were tested after requesting a new one, and they correctly expired individually.

With the standard paths closed, the researcher shifted focus to how the application handles multiple active OTP states concurrently. The observation that opened the finding was that triggering the Resend Code action multiple times caused the backend to generate new valid 6-digit codes, and the handling of session states or token bindings under concurrency looked wrong.

Exploitation
Step 1: Measure the generation endpoint limit
The application enforced a maximum threshold of 500 requests on the endpoint before triggering a block. This is a global endpoint rate limit, separate from the 5-attempt limit on verification, and it is what made the attack practical: the generation side allowed far more traffic than the verification side.
Step 2: Generate a pool of valid OTPs in parallel
By sending a parallel burst of requests to the resend/generate endpoint, staying under the allowed endpoint threshold, multiple valid OTPs were generated simultaneously for the same session. The report does not include the raw request used for this burst.
Step 3: Exploit the race condition
When the multiple valid OTPs were injected or tested within the same packet window, or mapped to concurrent states, all of the concurrently generated OTPs remained valid instead of the previous ones being invalidated immediately upon a new generation request. Old OTPs expired individually when tested, but concurrently generated OTPs all remained valid.
Step 4: Bypass the 5-attempt limit
Because a pool of valid OTPs could be accumulated through parallel generation without triggering the lockout too quickly, the researcher had a high probability matrix to test valid codes directly without hitting the 5-tries block on a single dead-end code. The report does not say how the failure counter is scoped, but recommends tying it globally to the session or identifier.
Root cause
The backend failed to atomically invalidate older active tokens upon generating a new one when requests were hurled concurrently, leading to a multi-token validity state tied loosely to the session/CSRF context. In other words, the invalidation of older tokens is not atomic when generation requests arrive concurrently.
The existing defences did not stop this: rate limiting and the 5-attempt cap protect the verification endpoint, and old-OTP invalidation did not hold under concurrency. Rate limiting and the 5-attempt cap protect the verification endpoint against sequential guessing, and old-OTP invalidation works when requests are serialised. Neither control accounts for several tokens being valid at the same time, and the generation endpoint allowed up to 500 requests before blocking.
Impact
- Full Account Takeover (ATO): an attacker can compromise any user account without needing prior session access, purely by manipulating the OTP generation state through a race condition and bypassing the brute-force restriction limits.
Fix
The report gives three recommendations:
- Atomic Token Invalidation: ensure that whenever a new OTP is requested, all previously active OTPs for that user/session are immediately and atomically invalidated.
- Strict Rate Limiting on Generation: implement tight rate-limiting not just on the verification endpoint, but also on the generation/resend endpoint, to prevent flooding the database with active tokens.
- Lockout Synchronization: tie the failure counter globally to the session/identifier rather than individual tokens, if multiple tokens are somehow allowed.
Variants to test
- Parallel resend on other OTP flows: send a burst of resend requests and then test each returned or generated code. A positive result is more than one code being accepted for the same session.
- Parallel verification: fire the same candidate code, or several candidates, in a single packet window against the verify endpoint. A positive result is the attempt counter not incrementing as it does for sequential requests.
- Email change and MFA enrolment flows: the same generate-then-verify pattern often appears there. A positive result is an old code still being accepted after a new one is issued.
- Password reset token links: request several reset links concurrently and check whether earlier links stay valid. A positive result is multiple live links for one account.
- Coupon, gift card and invite redemption: concurrent submission of the same value. A positive result is the value being consumed more than once.
- Withdrawal or balance operations: concurrent requests against a balance check. A positive result is a debit that does not match the number of successful operations.
The End
The researcher closes with a reminder that the comfort zone is always the most dangerous thing, and points readers to their LinkedIn profile for other write-ups.

What happened, in plain words
A security researcher was testing a website as part of a bug bounty programme. Bug bounty programmes invite people to look for security holes and report them, often for a reward. The researcher focused on the "Forgot Password" feature, the one you use when you cannot remember your password. That feature sends a short numeric code to your email address, and you type the code into the website to prove the email address is yours. The code is called an OTP, short for one-time password.
The website had several protections. It limited how many times you could try to verify a code, and it blocked you after five wrong guesses. It also had a limit on how many requests you could send to the endpoint that generates codes. Despite all that, the researcher found a way to make the website accept many different codes at the same time, which let them guess the right one without being locked out. The result was a full account takeover, often shortened to ATO: the researcher could get into someone else's account without ever seeing that person's email.
The trick is called a race condition. A race condition happens when a system does two things at once and the result depends on which one finishes first. Imagine two people trying to book the last seat on a train at the same moment. If the booking system checks availability for both before either one confirms, both may be told the seat is theirs. The website's code generation had a similar problem: when several requests arrived together, each one created a new valid code, and none of them cancelled the others.
This article walks through the whole story in the same order as the researcher's write-up. It explains every term from scratch, shows the exact steps and the exact code where the report gives it, and says why each step was taken. The report does not include the raw HTTP requests used for the attack, so you will not see them here either.
The target and the feature
The target was a web application the researcher was testing during bug bounty work. A web application is simply a website with which you interact: you fill in forms, click buttons, and the site responds. The feature in scope, meaning the part the researcher was allowed to test, was the Password Reset / Forgot Password flow. A flow is a sequence of screens and actions that together do one job, like resetting a password.
Here is how that flow normally works. You click "Forgot password", type your email address, and the website sends a message to that address. The message contains a short code, in this case six digits. You type the code into the website, and if it matches, the website lets you set a new password. The code is called an OTP because it is meant to be used once and then thrown away. It proves you can read the email, which is a common way to prove an account belongs to you.
The application had standard security controls in place. Rate limiting means limiting how many requests a client can make in a period of time, like a bouncer who only lets a certain number of people into a club per minute. There was rate limiting on the verification endpoint, the part of the website that checks whether the code you typed is correct. There was also a hard limit of five failed attempts per OTP. After five wrong guesses, that code would no longer be accepted, which stops someone from simply trying all one million possible six-digit combinations.
The researcher's goal was a full Account Takeover (ATO). That means getting into another person's account and controlling it, for example by changing its password. To do that without access to the victim's mailbox, the researcher had to get past the OTP check by some other means.
Setup
The report does not describe the tooling, the number of accounts used, or any version information. The only precondition that matters is that the attacker can reach the forgot password endpoint and trigger OTP generation for the victim's email address. That is the normal starting point of any password reset flow: anyone who knows your email address can ask the site to send you a code. No prior session access to the victim account was needed. In other words, the researcher did not need to be logged in as the victim or have stolen a cookie beforehand.
A cookie is a small piece of data a website stores in your browser so it can remember who you are between page loads. A session is the period during which the website treats you as the same visitor, and it is usually tracked with a cookie or a token. A token here is a value the server gives the client to identify a session or a one-time action. You will see these words again when the report talks about session states and token bindings.
Finding it
The researcher first mapped the flow as implemented by the application. Mapping a flow means writing down each step the website performs, so you know where the interesting decisions are made. The steps were:
- Initiate Request: enter the account email into the forgot password endpoint.
- OTP Generation: a 6-digit numeric OTP is sent to the user.
- Validation Limits: the application strictly enforced a maximum of 5 failed attempts per OTP to prevent brute-forcing.
Brute-forcing means trying many possibilities until one works, like trying every key on a key ring until the door opens. The five-attempt limit is designed to make brute-forcing a six-digit code impractical.
The usual vectors were tested first, and all of them held. A vector, in security testing, is a way of attacking a system. Testing the usual vectors first is what any careful tester does: you rule out the simple explanations before spending time on the complicated ones.
- Rate-Limiting: robustly implemented on the verification endpoint, blocking after multiple rapid requests. The researcher sent many requests quickly and the site stopped accepting them, so this path was closed.
- Response Manipulation: handled properly; the system validated the OTP correctly and did not accept a manipulated response. Response manipulation means changing what the server sends back to your browser, for example flipping a "false" to a "true" in the reply, to see whether the site trusts its own response too much. Here the site checked the code on the server side, so tampering with the response did not help.
- Old OTP Invalidation: previously generated OTPs were tested after requesting a new one, and they correctly expired individually. Invalidation means making something no longer valid. When you ask for a new code, the old one should stop working. The researcher checked this one request at a time, and it worked as intended.

The image sits right after the list of standard tests.
With the standard paths closed, the researcher shifted focus to how the application handles multiple active OTP states concurrently. Concurrently means at the same time. The question changed from "what happens when I ask for one code after another?" to "what happens when I ask for several codes at once?". The observation that opened the finding was that triggering the Resend Code action multiple times caused the backend to generate new valid 6-digit codes, and the handling of session states or token bindings under concurrency looked wrong. The backend is the part of the website that runs on the server, as opposed to the frontend that runs in your browser. Session states and token bindings are the server's records of which codes belong to which session; if those records get confused when requests overlap, more than one code can stay valid.

The image appears just after the observation about repeated Resend Code requests.
Exploitation
Step 1: Measure the generation endpoint limit
The application enforced a maximum threshold of 500 requests on the endpoint before triggering a block. This is a global endpoint rate limit, separate from the five-attempt limit on verification. Global here means it applies to the endpoint as a whole rather than to a single code. It is what made the attack practical: the generation side allowed far more traffic than the verification side. The verification endpoint stopped you after five wrong guesses, but the generation endpoint let you ask for hundreds of codes before it stopped you.
Step 2: Generate a pool of valid OTPs in parallel
By sending a parallel burst of requests to the resend/generate endpoint, staying under the allowed endpoint threshold, multiple valid OTPs were generated simultaneously for the same session. A parallel burst means firing many requests at the same moment instead of waiting for each one to finish. The report does not include the raw request used for this burst, so there is no code block to show for this step.
The reason for doing this is to build a pool of codes that are all valid at once. If the site behaved correctly, asking for a new code would cancel the previous one, so the pool would always contain exactly one live code. The researcher was testing whether that rule survived a burst of simultaneous requests.
Step 3: Exploit the race condition
When the multiple valid OTPs were injected or tested within the same packet window, or mapped to concurrent states, all of the concurrently generated OTPs remained valid instead of the previous ones being invalidated immediately upon a new generation request. A packet window is a very short slice of time in which several network packets arrive close together. Old OTPs expired individually when tested, but concurrently generated OTPs all remained valid.
This is the heart of the race condition. Because the requests overlapped, the older codes were not invalidated when new ones were generated, so several codes stayed live for one session. The result is several live codes for one session.
Step 4: Bypass the 5-attempt limit
Because a pool of valid OTPs could be accumulated through parallel generation without triggering the lockout too quickly, the researcher had a high probability matrix to test valid codes directly without hitting the five-tries block on a single dead-end code. A probability matrix here just means a set of candidate codes with a good chance that one of them is correct. The report does not say how the failure counter is scoped, but recommends tying it globally to the session or identifier. If you have many live codes and each one allows five guesses, the total number of guesses you can make before being locked out grows with the size of the pool.
Root cause
The backend failed to atomically invalidate older active tokens upon generating a new one when requests were hurled concurrently, leading to a multi-token validity state tied loosely to the session/CSRF context. Atomic means all-or-nothing: an operation either completes fully or has no effect, with no moment in between where another request can slip in. CSRF stands for Cross-Site Request Forgery, a class of attack where another site makes your browser send a request you did not intend; the CSRF context is the set of values the site uses to tie a request to your session and protect against that. In other words, the check-and-invalidate sequence is not atomic: several generation requests can each read the same pre-invalidation state, each write a new token, and none of them remove the others.
The existing defences did not stop this: rate limiting and the five-attempt cap protect the verification endpoint, and old-OTP invalidation did not hold under concurrency. Rate limiting and the five-attempt cap protect the verification endpoint against sequential guessing, and old-OTP invalidation works when requests are serialised. Serialised means one after another, in order. Neither control accounts for several tokens being valid at the same time, and the generation endpoint allowed up to 500 requests before blocking.
Impact
- Full Account Takeover (ATO): an attacker can compromise any user account without needing prior session access, purely by manipulating the OTP generation state through a race condition and bypassing the brute-force restriction limits.
CVSS is a standard scoring system for the severity of a vulnerability; the report simply does not give one.
Fix
The report gives three recommendations:
- Atomic Token Invalidation: ensure that whenever a new OTP is requested, all previously active OTPs for that user/session are immediately and atomically invalidated. In everyday terms, when a new key is cut, every old key for that door stops working at the same instant, even if several people ask for keys at once.
- Strict Rate Limiting on Generation: implement tight rate-limiting not just on the verification endpoint, but also on the generation/resend endpoint, to prevent flooding the database with active tokens. The database is where the server stores its records, including the live codes.
- Lockout Synchronization: tie the failure counter globally to the session/identifier rather than individual tokens, if multiple tokens are somehow allowed. Synchronization here means making sure all parts of the system share one counter, so five wrong guesses in total lock the session, not five per code.
Variants to test
These are other places where the same pattern might appear. They are written as ideas to try, not as confirmed findings.
- Parallel resend on other OTP flows: send a burst of resend requests and then test each returned or generated code. A positive result is more than one code being accepted for the same session.
- Parallel verification: fire the same candidate code, or several candidates, in a single packet window against the verify endpoint. A positive result is the attempt counter not incrementing as it does for sequential requests.
- Email change and MFA enrolment flows: the same generate-then-verify pattern often appears there. MFA means multi-factor authentication, an extra proof of identity beyond a password. A positive result is an old code still being accepted after a new one is issued.
- Password reset token links: request several reset links concurrently and check whether earlier links stay valid. A positive result is multiple live links for one account.
- Coupon, gift card and invite redemption: concurrent submission of the same value. A positive result is the value being consumed more than once.
- Withdrawal or balance operations: concurrent requests against a balance check. A positive result is a debit that does not match the number of successful operations.
The End
The researcher closes with a reminder that the comfort zone is always the most dangerous thing, and points readers to their LinkedIn profile for other write-ups.

The final image sits at the end of the article, next to the closing note and the pointer to the researcher's LinkedIn profile.
Glossary
- Account Takeover (ATO): gaining control of someone else's account, for example by changing its password.
- Atomic: all-or-nothing; an operation that either completes fully or has no effect, with no in-between moment another request can exploit.
- Backend: the part of a website that runs on the server, as opposed to the frontend in your browser.
- Brute-forcing: trying many possibilities until one works.
- Bug bounty: a programme that invites people to find and report security holes, often for a reward.
- Concurrently: at the same time.
- Cookie: a small piece of data a website stores in your browser to remember who you are between page loads.
- CSRF (Cross-Site Request Forgery): an attack where another site makes your browser send a request you did not intend; the CSRF context is the set of values used to tie a request to your session and defend against that.
- CVSS: a standard scoring system for the severity of a vulnerability.
- Database: where the server stores its records, including live codes.
- Endpoint: a specific address on a server that performs a particular action, such as verifying a code.
- Flow: a sequence of screens and actions that together do one job, like resetting a password.
- Global endpoint rate limit: a limit that applies to the endpoint as a whole rather than to a single code.
- Invalidation: making something no longer valid, such as cancelling an old code.
- MFA (multi-factor authentication): an extra proof of identity beyond a password.
- OTP (one-time password): a short code meant to be used once, often sent by email or text message.
- Packet window: a very short slice of time in which several network packets arrive close together.
- Parallel burst: firing many requests at the same moment instead of waiting for each one to finish.
- Probability matrix: here, a set of candidate codes with a good chance that one of them is correct.
- Race condition: a flaw where a system does two things at once and the result depends on which one finishes first.
- Rate limiting: limiting how many requests a client can make in a period of time.
- Response manipulation: changing what the server sends back to your browser to see whether the site trusts its own response too much.
- Serialised: one after another, in order.
- Session: the period during which a website treats you as the same visitor, usually tracked with a cookie or token.
- Synchronization: making sure all parts of a system share one counter or state.
- Token: a value the server gives the client to identify a session or a one-time action.
- Vector: a way of attacking a system.