You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CreateOrder Method in the OrderService.cs is vulnerable to a race condition that allows multiple simultaneous requests to oversell products. This issue enables attackers to purchase more items than are available in stock by exploiting the timing window between stock checks and stock updates, leading to negative stock quantities and unauthorized purchases.
Steps to Reproduce (PoC)
An attacker can exploit this vulnerability by attempting to purchase a product at almost the same time with limited stock (stock = 1) using two accounts. If both accounts successfully purchase the product, it confirms the presence of a race condition. This can be done using custom scripts or Burp Suite turbo intruder to send concurrent checkout requests.
To further demonstrate the vulnerability, please refer to the following YouTube video:POC
Suggested Fix
Vulnerable code from OrderService.cs:
To mitigate this vulnerability, implement atomic operations or utilize database transactions with appropriate locking mechanisms to ensure that stock checks and updates occur as a single, indivisible operation.
In this code:
Fixes/simplcommerce#1111
The transaction is started using _checkoutItemRepository.BeginTransaction().
The product is queried and locked for update using _checkoutItemRepository.saveChanges().
The stock quantity is checked and updated within the transaction.
The transaction is committed after the order is created.
This ensures that the stock check and update are performed atomically, preventing race conditions.
Description
The CreateOrder Method in the OrderService.cs is vulnerable to a race condition that allows multiple simultaneous requests to oversell products. This issue enables attackers to purchase more items than are available in stock by exploiting the timing window between stock checks and stock updates, leading to negative stock quantities and unauthorized purchases.
Steps to Reproduce (PoC)
An attacker can exploit this vulnerability by attempting to purchase a product at almost the same time with limited stock (stock = 1) using two accounts. If both accounts successfully purchase the product, it confirms the presence of a race condition. This can be done using custom scripts or Burp Suite turbo intruder to send concurrent checkout requests.
To further demonstrate the vulnerability, please refer to the following YouTube video:POC
Suggested Fix
Vulnerable code from OrderService.cs:
![carbon (3)](https://private-user-images.githubusercontent.com/53648024/397874080-d92b3f63-7fef-4ed6-9933-94043995c0d2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNDgxMTEsIm5iZiI6MTczOTI0NzgxMSwicGF0aCI6Ii81MzY0ODAyNC8zOTc4NzQwODAtZDkyYjNmNjMtN2ZlZi00ZWQ2LTk5MzMtOTQwNDM5OTVjMGQyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDA0MjMzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThkYWE0NmQxMTk5YjdjMTQ0NzkwMzhiMzIzNzliNmI1ZmU2ZWVlMmZiNDc4NzIzMjk2MDYyODViNTBhNDUzNzkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.TW7qNsbd9t2f0JRraZowimX8nSMv7eNrTfl-F80rWnU)
To mitigate this vulnerability, implement atomic operations or utilize database transactions with appropriate locking mechanisms to ensure that stock checks and updates occur as a single, indivisible operation.
Useful Links
https://cwe.mitre.org/data/definitions/362.html
https://github.com/AbdullahAlmutawa/CVE-2024-53476
The text was updated successfully, but these errors were encountered: