Submit #1062366: SourceCodester Online Food Ordering System 1.0 Path Traversalinfo

TitleSourceCodester Online Food Ordering System 1.0 Path Traversal
Description# [G18] User-controlled image names can escape the image directory before `unlink` **Assessment:** Confirmed by source audit; partially reported by the final Agent run. Category deletion and both update handlers are additional instances. **Vulnerability type:** Path Traversal Leading to Arbitrary File Deletion (CWE-22). ## Description Four handlers prepend an intended image-directory path to a caller-controlled image name and pass the result to `file_exists()`/`unlink()` without canonicalizing it or checking that the resolved target remains inside the image directory. A name containing `../` components can resolve to an existing file outside that directory. ## Source evidence and analysis Repository root: `targets/web-scan-20261028/web/`. Food deletion (`admin/delete.php`, lines 5–9): ```php $image = $_GET['image_name']; if (!empty($image) && file_exists('../images/food/'.$image)) { unlink('../images/food/'.$image); } ``` Category deletion (`admin/delete_category.php`, lines 5–11): ```php $image = $_GET['image_name']; if ($image != "") { $image_path = "../images/category/" . $image; if (file_exists($image_path)) { $remove = unlink($image_path); } } ``` Food update (`admin/update_food.php`, lines 18 and 37–40) trusts the POST value when a replacement upload succeeds: ```php $current_image = $_POST['current_img']; ... if (!empty($current_image) && file_exists('../images/food/' . $current_image)) { unlink('../images/food/' . $current_image); } ``` Category update (`admin/update_category.php`, lines 24 and 45–48) has the same condition: ```php $originalImage = $_POST['current_image']; ... if ($originalImage != "" && file_exists("../images/category/" . $originalImage)) { unlink("../images/category/" . $originalImage); } ``` `file_exists()` only checks whether the constructed path exists; it does not enforce containment. Prefixing with a directory is not sufficient because the later `../` components are resolved by the filesystem. The update handlers reach the unlink only after a replacement upload succeeds. Food/category direct deletion also performs a database deletion; missing authorization on those routes is documented separately in G02. ## Reproduction (disposable local instance only) Use only a local disposable copy. Create a harmless marker file **one directory above** the resolved `images/food/` directory (or `images/category/` for category handlers). If the PHP working directory differs from the usual `admin/` directory, calculate the normalized target path first and place the marker there. Then send the relative path that climbs out of the image directory: ```text image_name=../traversal-marker.txt ``` For the direct food-deletion route, for example: ```bash BASE=http://127.0.0.1:8080 curl -i "$BASE/admin/delete.php?id=0&image_name=../traversal-marker.txt" ``` Use a disposable/nonexistent food ID so the test does not remove a real database row. The file deletion is independent of whether the row deletion succeeds. `delete_category.php` accepts the analogous category-relative name. For `update_food.php` and `update_category.php`, set `current_img`/`current_image` to the traversal name and include a successful harmless replacement upload; those handlers do not unlink the path when no replacement image is uploaded. Confirm the marker disappears, then discard the entire test copy. Never target system files or data outside a disposable test directory. ## Impact and scope A caller who can reach the affected handler can delete an existing file outside the intended image directory, if the PHP process has filesystem permission to remove it. The reachable impact depends on deployment paths/permissions and a known or guessable target. The reviewed code proves the missing path-containment check, not that every deployment permits deletion of arbitrary system files. The direct delete endpoints are also unauthenticated (G02). ## Recommended fix Do not accept path components from the request. Store and retrieve server-generated image basenames by record ID. Before deletion, resolve the target with `realpath()` and verify it is a regular file whose canonical path remains beneath the canonical image directory; reject symlinks and traversal. Apply the same safe helper to every delete/update path and enforce authorization before file operations.
Source⚠️ https://gist.github.com/Ka7arotto/c74ecc431ff3df8150a66bd3063113c5/edit
User
 Goku (UID 80486)
Submission10/28/2026 13:33 (29 days ago)
Moderation11/26/2026 09:36 (29 days later)
StatusDuplicate
VulDB entry426508 [SourceCodester Online Food Ordering System 1.0 admin/delete.php unlink image_name path traversal]
Points0

Are you interested in using VulDB?

Download the whitepaper to learn more about our service!