Creating thinking is our everything : Race condition and business logic
The application rounded small payment amounts up to a minimum credit without charging the card, but a minimum deposit rule limited repeated abuse. By sending many payment confirmation requests simultaneously, an attacker could bypass that rule and repeatedly credit the account.
Published on medium.com
So hello everyone! My name is Leks and this is the happy story of combining two vulnerabilities.
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.
So hello everyone! My name is Leks and this is the happy story of combining two vulnerabilities.

Context
The target was an application that lets a user make a payment and increase the balance on their account. The feature normally takes a sum, rounds it, and credits it to the balance after a bank card check. The report does not name the program, the host or the exact endpoints; the only asset detail given is that the write-up was published on medium.com.
Two separate weaknesses combined here: a business logic error in how the sum is rounded, and a race condition in how the minimum deposit limit is enforced.
Setup
The researcher worked with an account on the application and wrote his own tooling in Python, using the requests library. He also mentions a public tool, aaronhnatiw/race-the-web, which tests for race conditions in web applications by sending out a user-specified number of requests to a target URL. He says he did not try it himself, but that it may make the reader's life easier.
No versions, accounts, roles or other preconditions beyond a normal user account with the payment feature are described.
Finding it
While testing the payment and balance feature, the researcher noticed incorrect processing of zeros after the decimal point in the sum. Everywhere, the program rounds the numbers to a larger amount, and the same happens in the final price for billing.
But not everything was so simple with 0.009. It turned out that the service simply credited 0.01 to the price without checking a bank card, and therefore without withdrawing money. At that point he thought this was a P1: unlimited adding of money to the account.
After the second time he got a little upset. It turned out that the larger the amount put into the account, the more the minimum deposit to the account grows. After the second time, when he had 0.02 on the account, the trick with 0.009 did not work, and he could not replenish more. The rule was: you can make a payment only for a sum more than or equal to what you have on your account. That is why after the second time, with 0.02 on the account, he could not purchase 0.01, as it was too little.
After this unpleasant surprise he wrote the fact of such a vulnerability down in his ToDo list. He had already exploited a race condition before, so he wrote it down as an idea to use.
Exploitation
Step 1: understand the race condition
One month later he decided to return to the vulnerability and exploit it further, since there was the idea with race conditions.
When several threads are started at the same time, some of them catch old data on the server, which is used to the attacker's advantage.

He describes the model with two variables: balance (a=0) and minimum deposit replenishment (b=0), which increases after every purchase. When the balance is increased (a+1), the server looks at the minimum deposit (b) and checks that the number to which the balance is replenished is bigger than the balance (1≥b).
In the example of 8 requests: requests 1 to 4 caught the server limit b=0, so only the 4th request caught b=1. Requests 5 to 8 did the same thing. Because the server works with threads separately, the variables with which they begin to work do not change during that work. So in requests 5 to 8, b=1, and only on the 9th request is the data updated, and the request no longer passes by the rules of the limit.
This is important to understand: threads do not communicate with each other, like Hey dude, I have +1 here, you need to change limit, Oh ok, np bro. That is why a race condition can be created, during which threads use non-updated data.
Step 2: build the request
The researcher started writing scripts in Python. Race conditions are easy to exploit: create scripts with requests and send them simultaneously to the site, and the more the better. For a white hat, 20 requests will come down, only to show that the vulnerability exists, but to exploit the vulnerability with maximum benefit you need a lot of requests.
The request to purchase looked like:

He used the Python requests library:

Such a script makes a POST request with headers and tokens.
Step 3: handle the two-page flow and tokens
In his case there were two pages: on one he made a payment, on the second he confirmed it, so he had to get unique tokens that were stored in the HTML code. One script created requests and collected tokens in a separate file, and a second took these tokens, substituted them into forms and confirmed.
In reality it was a little hard to do in terms of sequence logic. The logic of his PoC was: the first file creates payments and collects tokens. At the same time, another accepts these tokens, creates a bunch of scripts (the script creates scripts, the future is near) and inserts tokens into their code so that each file carries a unique token.

After that, he creates a script like this: the operand & runs them at the same time, more precisely, runs the next line of the script without waiting for the end of the current line.
And everything worked, and he got the race condition.
It is sometimes difficult to exploit such a vulnerability because of tokens, but it is nevertheless possible: just write down what is going on and make a plan.
Root cause
Two mistakes combine here.
- Rounding of the sum. The application rounds numbers up, including the final price for billing, and a sum of 0.009 was credited as 0.01 without a bank card check and without withdrawing money. The report does not show the server-side code, so the exact rounding routine is not described.
- Non-atomic limit check. The minimum deposit limit is read and checked per thread, and the threads do not share the updated value while they work. Several simultaneous requests therefore all see the old limit and pass the check, even though only one of them should have. The report states plainly that threads do not communicate with each other, so they use non-updated data.
The rule that a payment must be for a sum more than or equal to the balance stopped the simple repeated 0.009 trick after the second attempt; the race condition let simultaneous requests use a non-updated limit.
Impact
The researcher showed that simultaneous purchase requests could get past the minimum deposit limit check, which the sequential 0.009 trick could not. The report frames the simple version as limited: after the second attempt the growing minimum deposit blocked further 0.009 payments. Combined with the race condition, several simultaneous requests could pass the limit check using old data. The researcher notes that 20 requests are enough to demonstrate the vulnerability, while maximum benefit requires a lot of requests. The report does not quantify the money obtained or the number of successful requests.
Fix
The owners of the program quickly confirmed the vulnerability and kept him up to date with all the updates, and the HackerOne support team quickly provided him with an account to test after a letter with a request. What should be done, based on the described behaviour: make the balance update and the minimum deposit check atomic, for example with a lock or a single conditional database update, and validate and round the payment sum on the server before any credit is made, so that a sum below the minimum unit cannot be credited without a card check.
Variants to test
- Sub-unit sums on payment forms. Submit a sum with more decimals than the currency allows, such as 0.009, and observe whether the credited amount is rounded up. A positive result is a balance increase without a corresponding card charge.
- Concurrent purchase requests against a per-user limit. Send many simultaneous requests that each pass a limit check based on the current balance. A positive result is more credits than the limit should allow, as in the 8-request example where requests 1 to 4 all saw b=0.
- Two-step flows with per-request tokens. Where payment and confirmation are separate pages with tokens in the HTML, collect tokens with one script and fire the confirmations simultaneously with
&. A positive result is several confirmations accepted against a state that should have changed after the first. - Growing minimum deposit rules. After each successful credit, check whether the minimum deposit rises and blocks the next small payment. A positive result is that the rule can be bypassed by sending the next batch concurrently rather than sequentially.
Many thanks to the HackerOne support team, as they quickly provided him with an account to test it after a letter with a request, and the owners of the program quickly confirmed the vulnerability and kept up to date with all the updates.
So just keep thinking how to hack, and you will make it. This is his first write-up, and you can follow him on Twitter to find out more; he will try to do it more often.
Have a nice day.
What happened, in plain words
A security researcher found a way to add money to his account on a payment application without actually paying for it. He did it by combining two separate mistakes in how the application works.
The first mistake was in how the application handled very small sums. When he asked to pay a sum like 0.009, the application rounded it up to 0.01 and credited that to his balance, without checking a bank card and without taking any money from him. On its own this looked like free money, but the application had a rule that stopped it from being repeated: you can only make a payment for a sum that is more than or equal to what you already have on your account. So after the first trick his balance was 0.02, and a 0.009 payment was no longer allowed.
The second mistake was a race condition. A race condition happens when a program checks something and then changes it, and two requests arrive so close together that both pass the check before either change is saved. Think of two people at a ticket counter with one seat left: the clerk looks at the screen, sees one seat, and sells it; the second clerk at the next window looked at the same screen a moment earlier and also sees one seat, and sells it too. Two tickets, one seat. The researcher sent many payment requests at the same moment, so several of them saw the old, low minimum deposit rather than the updated one.
By putting the two mistakes together, he could get several simultaneous payment requests past the minimum deposit limit check. He wrote Python scripts to do it, and the report describes the request, the scripts and the two-page flow with tokens that made it harder than it first looked.

The application and the feature
The target was an application that lets a user make a payment and increase the balance on their account. The feature normally takes a sum, rounds it, and credits it to the balance after a bank card check. The report does not name the program, the host or the exact endpoints; the only asset detail given is that the write-up was published on medium.com.
Two separate weaknesses combined here: a business logic error in how the sum is rounded, and a race condition in how the minimum deposit limit is enforced.
A business logic error is not a broken lock or a crashed program. It is a rule that the application follows exactly as written, but the rule itself is wrong or incomplete. The application does what it was told; it was just told the wrong thing. A race condition is a timing problem: two actions that should happen one after the other happen at the same time, and the program is not built to cope with that.
Setup
The researcher worked with an account on the application and wrote his own tooling in Python, using the requests library. Python is a programming language; the requests library is a ready-made set of code that lets a Python program send HTTP requests, the same kind of requests a browser sends when you click a button, but from a script instead of a browser window.
He also mentions a public tool, aaronhnatiw/race-the-web, which tests for race conditions in web applications by sending out a user-specified number of requests to a target URL. He says he did not try it himself, but that it may make the reader's life easier.
No versions, accounts, roles or other preconditions beyond a normal user account with the payment feature are described.
Finding it
While testing the payment and balance feature, the researcher noticed incorrect processing of zeros after the decimal point in the sum. Everywhere, the program rounds the numbers to a larger amount, and the same happens in the final price for billing.
But not everything was so simple with 0.009. It turned out that the service simply credited 0.01 to the price without checking a bank card, and therefore without withdrawing money. At that point he thought this was a P1: unlimited adding of money to the account. A P1 is the highest severity rating a bug bounty platform uses, meaning the most serious kind of finding.
After the second time he got a little upset. It turned out that the larger the amount put into the account, the more the minimum deposit to the account grows. After the second time, when he had 0.02 on the account, the trick with 0.009 did not work, and he could not replenish more. The rule was: you can make a payment only for a sum more than or equal to what you have on your account. That is why after the second time, with 0.02 on the account, he could not purchase 0.01, as it was too little.
After this unpleasant surprise he wrote the fact of such a vulnerability down in his ToDo list. He had already exploited a race condition before, so he wrote it down as an idea to use.
Exploitation
Step 1: understand the race condition
One month later he decided to return to the vulnerability and exploit it further, since there was the idea with race conditions.
When several threads are started at the same time, some of them catch old data on the server, which is used to the attacker's advantage. A thread is one line of work inside a program. A server that handles many requests at once gives each request its own thread, so several requests can be in progress at the same moment rather than one after another.

He describes the model with two variables: balance (a=0) and minimum deposit replenishment (b=0), which increases after every purchase. When the balance is increased (a+1), the server looks at the minimum deposit (b) and checks that the number to which the balance is replenished is bigger than the balance (1≥b).
In the example of 8 requests: requests 1 to 4 caught the server limit b=0, so only the 4th request caught b=1. Requests 5 to 8 did the same thing. Because the server works with threads separately, the variables with which they begin to work do not change during that work. So in requests 5 to 8, b=1, and only on the 9th request is the data updated, and the request no longer passes by the rules of the limit.
This is important to understand: threads do not communicate with each other, like Hey dude, I have +1 here, you need to change limit, Oh ok, np bro. That is why a race condition can be created, during which threads use non-updated data.
In everyday terms: each thread takes a photocopy of the account page when it starts, does its check against that photocopy, and only later writes the result back. If four threads take their photocopy before any of them writes back, all four see the old limit and all four are allowed through.
Step 2: build the request
The researcher started writing scripts in Python. Race conditions are easy to exploit: create scripts with requests and send them simultaneously to the site, and the more the better. For a white hat, 20 requests will come down, only to show that the vulnerability exists, but to exploit the vulnerability with maximum benefit you need a lot of requests. A white hat is someone who tests systems with permission and reports what they find instead of using it for harm.
The request to purchase looked like:

He used the Python requests library:

Such a script makes a POST request with headers and tokens. A POST request is the kind of HTTP request a browser sends when you submit a form, as opposed to a GET request, which is what it sends when you simply open a page. Headers are the extra lines of information sent along with a request, such as what kind of content it carries or who is asking. A token is a short, hard-to-guess string that the server gives you and expects back, so it can tell that the request really comes from your session and was not forged by someone else.
Step 3: handle the two-page flow and tokens
In his case there were two pages: on one he made a payment, on the second he confirmed it, so he had to get unique tokens that were stored in the HTML code. HTML is the language web pages are written in; a token sitting in the HTML means the server put it into the page it sent you, and your next request has to carry it back.
One script created requests and collected tokens in a separate file, and a second took these tokens, substituted them into forms and confirmed.
In reality it was a little hard to do in terms of sequence logic. The logic of his PoC was: the first file creates payments and collects tokens. At the same time, another accepts these tokens, creates a bunch of scripts (the script creates scripts, the future is near) and inserts tokens into their code so that each file carries a unique token. A PoC, proof of concept, is the smallest working demonstration that a vulnerability is real.

After that, he creates a script like this: the operand & runs them at the same time, more precisely, runs the next line of the script without waiting for the end of the current line. In a shell script, & at the end of a command means "start this and move on immediately", so the next command starts before the previous one has finished. That is exactly what makes the requests overlap in time.
And everything worked, and he got the race condition.
It is sometimes difficult to exploit such a vulnerability because of tokens, but it is nevertheless possible: just write down what is going on and make a plan.
Root cause
Two mistakes combine here.
- Rounding of the sum. The application rounds numbers up, including the final price for billing, and a sum of 0.009 was credited as 0.01 without a bank card check and without withdrawing money. The report does not show the server-side code, so the exact rounding routine is not described.
- Non-atomic limit check. The minimum deposit limit is read and checked per thread, and the threads do not share the updated value while they work. Several simultaneous requests therefore all see the old limit and pass the check, even though only one of them should have. The report states plainly that threads do not communicate with each other, so they use non-updated data. Atomic means all-or-nothing, done as a single indivisible step: if the check and the update happened as one atomic step, no second request could slip in between them.
The rule that a payment must be for a sum more than or equal to the balance stopped the simple repeated 0.009 trick after the second attempt; the race condition let simultaneous requests use a non-updated limit.
Impact
The researcher showed that simultaneous purchase requests could get past the minimum deposit limit check, which the sequential 0.009 trick could not. The report frames the simple version as limited: after the second attempt the growing minimum deposit blocked further 0.009 payments. Combined with the race condition, several simultaneous requests could pass the limit check using old data. The researcher notes that 20 requests are enough to demonstrate the vulnerability, while maximum benefit requires a lot of requests. The report does not quantify the money obtained or the number of successful requests.
Fix
The owners of the program quickly confirmed the vulnerability and kept him up to date with all the updates, and the HackerOne support team quickly provided him with an account to test after a letter with a request. What should be done, based on the described behaviour: make the balance update and the minimum deposit check atomic, for example with a lock or a single conditional database update, and validate and round the payment sum on the server before any credit is made, so that a sum below the minimum unit cannot be credited without a card check. A lock here means a mechanism that lets only one thread at a time go through a piece of code, so the second thread has to wait until the first has finished and saved its result.
Variants to test
- Sub-unit sums on payment forms. Submit a sum with more decimals than the currency allows, such as 0.009, and observe whether the credited amount is rounded up. A positive result is a balance increase without a corresponding card charge.
- Concurrent purchase requests against a per-user limit. Send many simultaneous requests that each pass a limit check based on the current balance. A positive result is more credits than the limit should allow, as in the 8-request example where requests 1 to 4 all saw b=0.
- Two-step flows with per-request tokens. Where payment and confirmation are separate pages with tokens in the HTML, collect tokens with one script and fire the confirmations simultaneously with
&. A positive result is several confirmations accepted against a state that should have changed after the first. - Growing minimum deposit rules. After each successful credit, check whether the minimum deposit rises and blocks the next small payment. A positive result is that the rule can be bypassed by sending the next batch concurrently rather than sequentially.
Many thanks to the HackerOne support team, as they quickly provided him with an account to test it after a letter with a request, and the owners of the program quickly confirmed the vulnerability and kept up to date with all the updates.
So just keep thinking how to hack, and you will make it. This is his first write-up, and you can follow him on Twitter to find out more; he will try to do it more often.
Have a nice day.
Glossary
- API: a way for one program to talk to another over the network, usually by sending requests to specific addresses and getting structured answers back.
- Atomic: done as a single indivisible step, all or nothing, so nothing else can happen in the middle of it.
- Business logic error: a flaw in the rules the application follows, where the code does exactly what it was written to do but the rule itself is wrong or incomplete.
- Cookie: a small piece of data a website stores in your browser and gets back on later requests, so it can recognise your session.
- GET request: an HTTP request that asks for a page or data, the kind your browser sends when you open a link.
- Header: an extra line of information sent with an HTTP request or response, such as the content type or who is asking.
- HTML: the language web pages are written in; it describes the text, links and forms you see in the browser.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
- Lock: a mechanism that lets only one thread at a time run a piece of code, making the others wait.
- P1: the highest severity rating on a bug bounty platform, meaning the most serious kind of finding.
- PoC (proof of concept): the smallest working demonstration that a vulnerability is real.
- POST request: an HTTP request that sends data to the server, the kind your browser sends when you submit a form.
- Python: a programming language often used for writing small scripts.
- Race condition: a flaw where two actions that should happen one after another happen at the same time, so both act on data that is already out of date.
requests: a Python library that lets a script send HTTP requests, the same kind a browser sends.- Session: the server's record of your logged-in visit, usually tied to a cookie or token so it knows which requests belong to you.
- Thread: one line of work inside a program; a server handling many requests at once gives each request its own thread.
- Token: a short, hard-to-guess string the server gives you and expects back, used to prove a request comes from your session and was not forged.
- White hat: someone who tests systems with permission and reports what they find instead of using it for harm.