| Название | SourceCodester Online Food Ordering System 1.0 SQL Injection |
|---|
| Описание | # [G11] Food updates interpolate price and status fields into SQL
**Assessment:** Confirmed by source audit; reported by the final Agent run.
**Vulnerability type:** SQL Injection (CWE-89).
## Description
The food-update handler HTML-escapes the title and description, but inserts the submitted price, featured flag, and active flag directly into an `UPDATE`. HTML encoding is not SQL parameterization, and the numeric-looking form field is not validated on the server.
## Source evidence and analysis
Repository root: `targets/web-scan-20261028/web/`.
The handler casts the row ID, HTML-escapes two fields, and takes the other values directly from POST (`admin/update_food.php`, lines 14–21):
```php
$id = intval($_POST['new_id']);
$title = htmlspecialchars($_POST['title'], ENT_QUOTES, 'UTF-8');
$description = htmlspecialchars($_POST['description'], ENT_QUOTES, "UTF-8");
$current_image = $_POST['current_img'];
$price = $_POST['price'];
$featured = $_POST['featured'];
$active = $_POST['active'];
```
Those values are later interpolated into SQL (`admin/update_food.php`, lines 47–57):
```php
$sql = "Update tbl_food Set
title = '$title',
description = '$description',
price = $price,
image_name = '$new_image_name',
featured = '$featured',
active = '$active'
WHERE id = $id
";
$res = mysqli_query($conn, $sql);
```
The `price` value is unquoted SQL syntax, while featured/active are quoted but still unescaped. Escaping title/description for browser output does not make the SQL statement safe. The `id` cast does not protect other columns.
## Reproduction (disposable local instance only)
Use a disposable food row and retain its ID. The expression below is evaluated by SQL rather than rejected as an invalid price:
```bash
BASE=http://127.0.0.1:8080
curl -i -X POST "$BASE/admin/update_food.php?id=12" \
--data-urlencode 'submit=1' \
--data-urlencode 'new_id=12' \
--data-urlencode 'title=SQLProbe' \
--data-urlencode 'description=source-audit-test' \
--data-urlencode 'current_img=' \
--data-urlencode 'price=0 OR 1=1' \
--data-urlencode 'featured=No' \
--data-urlencode 'active=No'
```
Replace `12` with a disposable row ID. In the test row, the price expression evaluates to `1`; restore or remove that row afterward. Do not send this request to production.
## Impact and scope
A caller can alter the SQL expression used to update food fields. In the example, the stored price is changed through an expression; other injected values may alter the statement further. The source proves SQL injection but not multi-statement execution. The shared authorization guard is non-terminating (G01), which affects reachability independently of this SQL flaw.
## Recommended fix
Use a prepared `UPDATE` and bind every column value and the row ID. Parse price as a validated decimal, and restrict status values to the supported options. Do not use HTML output encoding as SQL protection; encode separately at the HTML output sink.
|
|---|
| Источник | ⚠️ https://gist.github.com/Ka7arotto/c74ecc431ff3df8150a66bd3063113c5 |
|---|
| Пользователь | Goku (UID 80486) |
|---|
| Представление | 28.10.2026 13:27 (29 дни назад) |
|---|
| Модерация | 26.11.2026 09:36 (29 days later) |
|---|
| Статус | принято |
|---|
| Запись VulDB | 444233 [SourceCodester Online Food Ordering System 1.0 /admin/update_food.php price SQL-инъекция] |
|---|
| Баллы | 20 |
|---|