| शीर्षक | SourceCodester Online Food Ordering System 1.0 https://gist.github.com/Ka7arotto/c74ecc431ff3df8150a66bd3063113 |
|---|
| विवरण | # [G17] Food and category handlers store uploads with client-chosen extensions
**Assessment:** Confirmed by source audit; partially reported by the final Agent run. The category-update route is an additional missed instance.
**Vulnerability type:** Unrestricted Upload of File with Dangerous Type (CWE-434).
## Description
Three upload handlers derive the stored file extension from the client-supplied filename and move the uploaded bytes into public image directories without an extension allowlist or content verification. This permits content with a non-image extension (including `.php`) to be stored under a predictable public path pattern. Whether the server executes an uploaded script depends on the deployment's handler configuration; the source does not by itself prove remote code execution.
## Source evidence and analysis
Repository root: `targets/web-scan-20261028/web/`.
Food creation (`admin/add_food.php`, lines 15–25):
```php
$image_name = $_FILES['image']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);
$new_image_name = 'food_'.rand(000, 999). '.'.$ext;
$image_src = $_FILES['image']['tmp_name'];
$image_destination = '../images/food/'.$new_image_name;
$upload_image = move_uploaded_file($image_src, $image_destination);
```
Food update (`admin/update_food.php`, lines 24–30) follows the same pattern:
```php
$image_name = $_FILES['new_image']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);
$new_image_name = "food_" . rand(100,999) . '.' . $ext;
$image_source = $_FILES['new_image']['tmp_name'];
$image_destination = '../images/food/' . $new_image_name;
$upload = move_uploaded_file($image_source, $image_destination);
```
Category update (`admin/update_category.php`, lines 29–37) also preserves the submitted extension:
```php
$image_name = $_FILES['update_image']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);
$new_image_name = "Category_" . time() . "." . $ext;
$source_path = $_FILES['update_image']['tmp_name'];
$destination_path = "../images/category/" . $new_image_name;
$upload = move_uploaded_file($source_path, $destination_path);
```
None of these three paths checks the extension against an image allowlist or validates the file content before saving it under the web-served `images/` tree. PHP supplies `tmp_name`; the issue is not path traversal through that temporary path. `admin/add_category.php` does have a `.jpg`/`.jpeg`/`.png`/`.gif` extension allowlist, so that route is not included in this finding; that check still does not prove file contents are genuine images.
## Reproduction (disposable local instance only)
1. Create a harmless test file:
```bash
printf '%s\n' '<?php echo "upload-proof"; ?>' > proof.php
```
2. Upload it to one of the three routes using a disposable test row/category. For food creation, for example:
```bash
BASE=http://127.0.0.1:8080
curl -i -X POST "$BASE/admin/add_food.php" \
-F 'submit=1' -F 'title=UploadProbe' -F 'description=test' \
-F 'price=1' -F 'category_id=30' -F 'featured=No' -F 'active=No' \
-F '[email protected];filename=proof.php'
```
The update routes use `new_image` and `update_image` respectively; send them only against disposable records. Inspect the database/upload directory for the randomized destination name. Request that file from the local server. If PHP is enabled for that directory, the response may contain `upload-proof`; if scripts are not executed there, the file is still stored and served as uploaded content. Delete the test file/row afterward.
## Impact and scope
The source proves an attacker-controlled extension and unverified bytes can be stored in web-accessible directories. This can enable active-content hosting, content-type confusion, or code execution **only if** the deployed server executes the uploaded extension in that directory. The scanner has not established that deployment condition, so this report does not assert unconditional RCE. The shared guard's failure to terminate also affects the routes' authorization (G01).
## Recommended fix
Use a server-side allowlist of image formats, inspect actual file content with a trusted image parser, and re-encode accepted images to a server-chosen filename and extension. Store uploads outside the executable web root where possible, or configure the upload directory to serve files as inert content with script execution disabled. Apply authorization before receiving or moving the file.
|
|---|
| स्रोत | ⚠️ https://gist.github.com/Ka7arotto/c74ecc431ff3df8150a66bd3063113c5 |
|---|
| उपयोगकर्ता | Goku (UID 80486) |
|---|
| सबमिशन | 28/10/2026 01:44 PM (1 महीना पहले) |
|---|
| संयम | 26/11/2026 09:36 AM (29 days later) |
|---|
| स्थिति | स्वीकृत |
|---|
| VulDB प्रविष्टि | 444235 [SourceCodester Online Food Ordering System 1.0 File Upload /admin/add_food.php move_uploaded_file image/new_image/update_image अधिकार वृद्धि] |
|---|
| अंक | 20 |
|---|