Skip to content
Race condition Write-up Intermediate

Race Condition About The User Version and Ignored

r0b0ts Follow

Published on r0b0ts.medium.com

In this story, I am going to talk about success story with race condition and ignored about it. I was so puzzled.

r0b0ts, on r0b0ts.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. 4 min read.

Context

The target is a web application that offers three subscription tiers: normal, premium and professional. The premium and professional versions require an additional payment. The feature in question is workspace creation: a user on the normal version can create at most three workspaces, and creating more requires paying for a higher tier.

The researcher's question was whether a race condition could let a normal user bypass the payment step and obtain more workspaces than the plan allows.

Setup

  • A normal (free) account with three workspaces already created, so that further creation attempts are refused.
  • Burp Suite with the Turbo Intruder extension to send concurrent requests.
  • A Python proof-of-concept script using threading and requests to reproduce the same concurrency.
  • The workspace creation request, which is a POST to the workspace endpoint with a JSON body and a session cookie.

Finding it

While reviewing version authorisation, the researcher noticed the three tiers and the payment requirement attached to two of them. The limit of three workspaces for normal users is enforced at creation time: once the account already holds three workspaces, a further creation attempt is rejected with 403 Forbidden.

From the original on r0b0ts.medium.com

The screenshot shows the request and response for a normal user who already has three workspaces: the creation request is refused with 403.

From the original on r0b0ts.medium.com

The refusal is what stops a free account from creating more workspaces, and the researcher suspected it could be raced. If several creation requests arrive close enough together, each may pass the check before any of them has recorded a new workspace, which is the classic shape of a race condition.

Exploitation

Step 1: Confirm the limit

With three workspaces already present, a normal creation request returns 403 Forbidden. This establishes the baseline: sequentially, the limit holds.

Step 2: Fire the requests concurrently with Turbo Intruder

The researcher triggered the race condition with the Burp Suite extension Turbo Intruder and obtained a lot of workspaces. A response status of 201 means the workspace was created successfully.

Step 3: Reproduce with a Python script

The researcher also wrote a proof-of-concept script that sends the same request from multiple threads:

Python
import threadingimport requests, jsonimport timetry_making = 30data = {"[request body]"}headers = {'Content-Type': 'application/json; charset=utf-8'}cookies = {'_dct': '[JWT token]'}#request with credentialdef making_workspace():    global try_making, data, headers, cookies    if try_making > 0:        response = requests.post('https://vulnerable_host/workspace', data=json.dumps(data), headers=headers, cookies=cookies)        print(response.text)        try_making -= 1        #request with multithread            def current_execution():    for i in range(3):        making_workspace()        #threadingthread1 = threading.Thread(target=current_execution)thread2 = threading.Thread(target=current_execution)thread3 = threading.Thread(target=current_execution)thread4 = threading.Thread(target=current_execution)thread5 = threading.Thread(target=current_execution)thread6 = threading.Thread(target=current_execution)thread7 = threading.Thread(target=current_execution)thread8 = threading.Thread(target=current_execution)thread9 = threading.Thread(target=current_execution)#thread startthread1.start()thread2.start()thread3.start()thread4.start()thread5.start()thread6.start()thread7.start()thread8.start()thread9.start()#thread endthread1.join()thread2.join()thread3.join()thread4.join()thread5.join()thread6.join()thread7.join()thread8.join()thread9.join()print("Final remain trying: %d" % try_making)

The script keeps a shared counter, try_making, set to 30, and decrements it after each request. Nine threads each call making_workspace() three times, so the total number of attempts is bounded by the counter. The request is a POST to https://vulnerable_host/workspace with a JSON body, a Content-Type: application/json; charset=utf-8 header and a _dct cookie carrying a JWT. The request body and the token are redacted in the published code.

From the original on r0b0ts.medium.com

The researcher notes that the thread count and the try_making value had to be adjusted to trigger the issue successfully, and that the request payload was removed from the published code.

Step 4: Tune the race window

The race window changed with each execution, so the number of threads had to be adjusted each time to land the requests inside it.

From the original on r0b0ts.medium.com

A diagram accompanies the code to make the threading easier to follow.

Step 5: Result

Running the script produced many workspaces, each created with a 201 response.

From the original on r0b0ts.medium.com

The screenshot shows the result of the proof-of-concept run, with a lot of workspaces created.

Root cause

The report does not describe the server-side implementation; the likely cause is a non-atomic count-then-insert. Concurrent creation requests can all pass the limit check before any of them records a new workspace. The report does not describe the server-side implementation.

Impact

A normal user can create more workspaces than the plan allows. The report does not quantify the number of extra workspaces beyond saying it was a lot, and does not describe any other effect on the application.

After submitting the report, the researcher received a response that left them sad and upset, and they note that the program had not given advance notice. The report does not include the content of that response.

Fix

Variants to test

  1. Other plan-limited resources. Try concurrent creation of any resource capped by subscription tier, such as projects, API keys or seats. A positive result is more resources than the plan allows, with 201 responses for requests that should have been refused.
  2. Coupon and discount redemption. Send the same redemption request many times in parallel. A positive result is the discount applied more than once or a balance credited multiple times.
  3. Referral or signup bonuses. Fire concurrent requests that each grant a bonus. A positive result is multiple credits for a single eligible action.
  4. Withdrawal or transfer endpoints. Send parallel requests that each check a balance before debiting. A positive result is a total debited or transferred exceeding the balance.
  5. Varying the concurrency. As the researcher found, the race window shifts between runs, so sweep thread counts and request counts rather than relying on a single configuration, and look for any response that should have been a 403 but came back as a success.

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. 13 min read.

What happened, in plain words

A security researcher was using a website that sells subscriptions in three tiers: normal, premium and professional. The normal tier is free, and the other two cost extra money. One of the things the paid tiers give you is more workspaces. A workspace is something a user creates inside the application, and the free plan allows three. On the free plan you can have at most three of them. If you want a fourth, you are supposed to pay.

The researcher asked a simple question: what if the website checks the limit in a way that can be fooled by sending several requests at exactly the same moment? That kind of flaw is called a race condition, and the everyday comparison is two people reaching for the last seat on a train at the same instant: each one looks, each one sees the seat free, and both sit down. The check and the action happen so close together that the system never notices the conflict.

To test the idea, the researcher first confirmed that a normal account with three workspaces is refused when it tries to make a fourth. Then they sent the same creation request many times in parallel, using a tool built for that purpose and then a small Python script. The result was a large number of workspaces on a free account.

The researcher submitted a report about it. The response they received left them sad and upset, and they note that the program had not given any advance notice. The report does not include the content of that response.

Background you need first

What an API request is

When you click a button in a web application, your browser usually does not reload a whole page. It sends a small message to the server behind the scenes and gets a short answer back. That message is an API request, and the answer is the response. The comparison is ordering at a counter: you state what you want (the request), the person behind the counter does something and tells you the outcome (the response).

Each request has a few parts:

  • A method, which says what kind of action you want. GET means read something, POST means create or submit something.
  • A URL, the address of the thing you are acting on.
  • Headers, which are small labels attached to the request, such as the format of the data you are sending.
  • A body, the actual data, often written in JSON, a plain text format for structured data that looks like {"name": "value"}.
  • A status code, a number in the response that summarises what happened. 201 means something was created successfully. 403 means forbidden: the server understood you but refused.

What a cookie and a token are

A website needs to know who you are on every request, because the web itself does not remember anything between requests. After you log in, the server gives your browser a small piece of data called a cookie, which the browser sends back automatically with every later request. Think of it as a wristband at an event: you show it once at the door, and after that staff recognise you by it without asking for your ID again.

A common form of this is a token, a long string of characters that proves you are logged in. One specific kind is a JWT, short for JSON Web Token, which packs the proof into a signed string. Anyone holding the token can act as that user, which is why tokens are treated as secrets and are blanked out in published write-ups.

What a race condition is

Many server operations follow the pattern check, then act. Check that the user has fewer than three workspaces, then create a new one. If two requests arrive at almost the same moment, both can run the check before either has finished the act. Both see two workspaces, both decide a third is allowed, and both create one. The limit of three is now four, or more if many requests arrive together.

This is also called a time-of-check to time-of-use gap: the situation can change between the moment the system looks and the moment it acts. The window during which the trick works is called the race window, and it is usually very short, which is why the requests have to be fired in parallel rather than one after another.

What the researcher was testing

The application offers three subscription tiers: normal, premium and professional. Premium and professional require an additional payment. The feature under test is workspace creation: a normal user can create at most three workspaces, and more requires paying for a higher tier. The researcher's question was whether a race condition could let a normal user bypass the payment step and obtain more workspaces than the plan allows.

Setting up

To reproduce the issue, the researcher needed:

  • A normal (free) account with three workspaces already created, so that further creation attempts are refused.
  • Burp Suite, a tool that sits between your browser and the website and lets you capture and replay requests, with an extension called Turbo Intruder, which sends the same request many times at once.
  • A Python proof-of-concept script using threading and requests to reproduce the same concurrency outside Burp.
  • The workspace creation request itself: a POST to the workspace endpoint with a JSON body and a session cookie.

Finding it

While reviewing version authorisation, meaning how the application decides which tier you are on and what it lets you do, the researcher noticed the three tiers and the payment requirement attached to two of them. The limit of three workspaces for normal users is enforced at creation time: once the account already holds three workspaces, a further creation attempt is rejected with 403 Forbidden.

From the original on r0b0ts.medium.com

The screenshot shows the request and response for a normal user who already has three workspaces: the creation request is refused with 403.

From the original on r0b0ts.medium.com

The refusal is what stops a free account from creating more workspaces, and the researcher suspected it could be raced. If several creation requests arrive close enough together, each may pass the check before any of them has recorded a new workspace, which is the classic shape of a race condition.

Exploitation

Step 1: Confirm the limit

With three workspaces already present, a normal creation request returns 403 Forbidden. This establishes the baseline: when requests are sent one after another, the limit holds. You need that baseline before you can claim anything is wrong, because it proves the refusal is real and not a fluke of one request.

Step 2: Fire the requests concurrently with Turbo Intruder

The researcher triggered the race condition with the Burp Suite extension Turbo Intruder and obtained a lot of workspaces. A response status of 201 means the workspace was created successfully. The point of sending them in parallel is to land as many requests as possible inside the race window, so that they all pass the check before any of them has finished creating its workspace.

Step 3: Reproduce with a Python script

The researcher also wrote a proof-of-concept script that sends the same request from multiple threads. A thread is one line of execution inside a program; running several threads means the program does several things at the same time, which is how the script imitates many requests arriving together.

Python
import threadingimport requests, jsonimport timetry_making = 30data = {"[request body]"}headers = {'Content-Type': 'application/json; charset=utf-8'}cookies = {'_dct': '[JWT token]'}#request with credentialdef making_workspace():    global try_making, data, headers, cookies    if try_making > 0:        response = requests.post('https://vulnerable_host/workspace', data=json.dumps(data), headers=headers, cookies=cookies)        print(response.text)        try_making -= 1        #request with multithread            def current_execution():    for i in range(3):        making_workspace()        #threadingthread1 = threading.Thread(target=current_execution)thread2 = threading.Thread(target=current_execution)thread3 = threading.Thread(target=current_execution)thread4 = threading.Thread(target=current_execution)thread5 = threading.Thread(target=current_execution)thread6 = threading.Thread(target=current_execution)thread7 = threading.Thread(target=current_execution)thread8 = threading.Thread(target=current_execution)thread9 = threading.Thread(target=current_execution)#thread startthread1.start()thread2.start()thread3.start()thread4.start()thread5.start()thread6.start()thread7.start()thread8.start()thread9.start()#thread endthread1.join()thread2.join()thread3.join()thread4.join()thread5.join()thread6.join()thread7.join()thread8.join()thread9.join()print("Final remain trying: %d" % try_making)

Line by line, in plain words:

  • import threadingimport requests, jsonimport time brings in the pieces the script needs: threading for running things in parallel, requests for sending web requests, json for building the request body, and time.
  • try_making = 30 sets a shared counter of how many creation attempts are still allowed. It is a budget, so the script does not run forever.
  • data = {"[request body]"} is the body of the creation request. In the published code it has been replaced with a placeholder, because the researcher removed the real payload.
  • headers = {'Content-Type': 'application/json; charset=utf-8'} tells the server that the body is JSON text encoded in UTF-8, so the server knows how to read it.
  • cookies = {'_dct': '[JWT token]'} is the login proof. The cookie is named _dct and carries a JWT, which is redacted here. Without it the server would not know which account is asking.
  • def making_workspace(): defines one function, a named block of steps, that performs a single creation attempt.
  • global try_making, data, headers, cookies says the function will read and change the shared counter and use the shared data, headers and cookie rather than private copies.
  • if try_making > 0: only proceeds while there is budget left.
  • response = requests.post('https://vulnerable_host/workspace', data=json.dumps(data), headers=headers, cookies=cookies) sends the actual POST to the workspace address, with the JSON body, the headers and the cookie. json.dumps turns the Python data into JSON text.
  • print(response.text) shows the server's answer, so you can see which attempts succeeded.
  • try_making -= 1 reduces the budget by one, so the total number of attempts stays bounded.
  • def current_execution(): defines what each thread will do.
  • for i in range(3): repeats the next line three times.
  • making_workspace() performs one creation attempt per repetition, so each thread makes three attempts.
  • The nine lines thread1 = threading.Thread(target=current_execution) through thread9 = threading.Thread(target=current_execution) create nine threads, each set to run current_execution.
  • The nine lines thread1.start() through thread9.start() set all nine threads going, which is what makes the requests overlap in time.
  • The nine lines thread1.join() through thread9.join() make the main program wait until every thread has finished, so the final message is printed only at the end.
  • print("Final remain trying: %d" % try_making) reports how much of the budget was left, which tells you how many attempts were actually made.

The script keeps a shared counter, try_making, set to 30, and decrements it after each request. Nine threads each call making_workspace() three times, so the total number of attempts is bounded by the counter. The request is a POST to https://vulnerable_host/workspace with a JSON body, a Content-Type: application/json; charset=utf-8 header and a _dct cookie carrying a JWT. The request body and the token are redacted in the published code.

From the original on r0b0ts.medium.com

The researcher notes that the thread count and the try_making value had to be adjusted to trigger the issue successfully, and that the request payload was removed from the published code.

Step 4: Tune the race window

The race window changed with each execution, so the number of threads had to be adjusted each time to land the requests inside it. In everyday terms, the gap between the check and the action is not a fixed length: sometimes it is a little wider, sometimes narrower, so you try different amounts of parallel traffic until enough requests slip through together.

From the original on r0b0ts.medium.com

A diagram accompanies the code to make the threading easier to follow.

Step 5: Result

Running the script produced many workspaces, each created with a 201 response.

From the original on r0b0ts.medium.com

The screenshot shows the result of the proof-of-concept run, with a lot of workspaces created.

Why it works

The report does not describe the server-side implementation; the likely cause is a non-atomic count-then-insert. Serialising here means making requests take turns, one at a time, so that the second one sees the result of the first. Concurrent creation requests can all pass the limit check before any of them records a new workspace. The report does not describe the server-side implementation. Atomic means all-or-nothing, like a single indivisible step that nothing else can squeeze into.

Impact

A normal user can create more workspaces than the plan allows. The report does not quantify the number of extra workspaces beyond saying it was a lot, and does not describe any other effect on the application.

After submitting the report, the researcher received a response that left them sad and upset, and they note that the program had not given advance notice.

Fix

A lock is like a single key to a changing room: whoever holds it goes in alone, and everyone else waits their turn.

Variants to test

Once you understand the pattern, the same idea applies anywhere a limit is checked and then acted on. These are the places worth trying:

  1. Other plan-limited resources. Try concurrent creation of any resource capped by subscription tier, such as projects, API keys or seats. A positive result is more resources than the plan allows, with 201 responses for requests that should have been refused.
  2. Coupon and discount redemption. Send the same redemption request many times in parallel. A positive result is the discount applied more than once or a balance credited multiple times.
  3. Referral or signup bonuses. Fire concurrent requests that each grant a bonus. A positive result is multiple credits for a single eligible action.
  4. Withdrawal or transfer endpoints. Send parallel requests that each check a balance before debiting. A positive result is a total debited or transferred exceeding the balance.
  5. Varying the concurrency. As the researcher found, the race window shifts between runs, so sweep thread counts and request counts rather than relying on a single configuration, and look for any response that should have been a 403 but came back as a success.

Glossary

  • API: the set of addresses and rules a program uses to talk to a server, so that actions like creating a workspace can be requested without loading a whole page.
  • Request: the message your browser or script sends to a server, stating what it wants.
  • Response: the server's answer to a request, including a status code and usually some data.
  • Method: the part of a request that says what kind of action it is, such as GET to read or POST to create.
  • URL: the address of a resource on the web.
  • Header: a small label attached to a request or response, such as the format of the data being sent.
  • Body: the actual data carried by a request, often in JSON.
  • JSON: a plain text format for structured data, written as name and value pairs.
  • Status code: a number in a response summarising the outcome, such as 201 for created or 403 for forbidden.
  • Cookie: a small piece of data a site stores in your browser and receives back on later requests, used to recognise you.
  • Token: a string that proves you are logged in, often sent inside a cookie.
  • JWT (JSON Web Token): a signed token format that carries proof of identity; anyone holding it can act as that user.
  • Session: the period during which a site remembers who you are, based on your cookie or token.
  • Workspace: a container inside the application that belongs to a user, like a folder or desk; the free plan allows three.
  • Subscription tier: a level of paid plan, here normal, premium and professional, each with different limits.
  • Authorisation: how an application decides what a logged-in user is allowed to do.
  • Race condition: a flaw where two actions happening at almost the same moment interfere, because a check and the action that follows it are not done as one indivisible step.
  • Race window: the short period during which overlapping requests can slip past a check.
  • Time-of-check to time-of-use gap: the gap between the moment a system checks a condition and the moment it acts on it, during which the situation can change.
  • Concurrent / parallel: happening at the same time rather than one after another.
  • Thread: one line of execution inside a program; several threads let a program do several things at once.
  • Burp Suite: a tool that sits between your browser and a website so you can capture, inspect and replay requests.
  • Turbo Intruder: a Burp Suite extension for sending the same request many times in parallel.
  • Proof of concept (POC): a small script or set of steps that demonstrates a flaw really works.
  • Atomic: all-or-nothing, a single indivisible step that nothing else can interrupt.
  • Serialise: make operations take turns, one at a time, so each sees the result of the previous one.
  • Lock: a mechanism that lets only one operation at a time proceed, like a single key to a changing room.
  • Database constraint: a rule enforced by the database itself, so invalid data cannot be stored even if the application code is careless.
  • Redacted: removed or replaced with a placeholder to keep secrets out of a published report.

More by r0b0ts

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.