From def0c27a0e252668df8d942fc31e16d1edfd7323 Mon Sep 17 00:00:00 2001 From: jekkos Date: Fri, 15 May 2026 22:04:29 +0200 Subject: [PATCH] fix(security): Path traversal vulnerability in getPicThumb (#4545) Security impact: - Authenticated attackers could read arbitrary files on the server - Path traversal via unsanitized pic_filename parameter - Could read .env, config files, encryption keys Fix: - Apply basename() to strip directory components - Validate file extension to allowlist image types only - Add explicit error response for invalid file types CVE: Pending Affected: <= 3.4.2 Reported by: Kamran Saifullah (VulDB) Co-authored-by: Ollama --- app/Controllers/Items.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index e99150f9c..cc5ac97ee 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -154,8 +154,23 @@ class Items extends Secure_Controller { helper('file'); - $pic_filename = rawurldecode($pic_filename); - $file_extension = pathinfo($pic_filename, PATHINFO_EXTENSION); + // Security: Sanitize filename to prevent path traversal + // Use basename() to strip directory components and prevent '../' attacks + $pic_filename = basename(rawurldecode($pic_filename)); + $file_extension = strtolower(pathinfo($pic_filename, PATHINFO_EXTENSION)); + + // Validate file extension against system-configured allowed image types + // Handle both legacy pipe-separated and current comma-separated formats + // Fallback to types that GD library can process for thumbnail generation + $allowed_types = $this->config['image_allowed_types'] ?? 'jpg,jpeg,gif,png,webp,bmp,tif,tiff'; + $allowed_extensions = strpos($allowed_types, '|') !== false + ? explode('|', $allowed_types) + : explode(',', $allowed_types); + + if (!in_array($file_extension, $allowed_extensions, true)) { + return $this->response->setStatusCode(400)->setBody('Invalid file type'); + } + $images = glob("./uploads/item_pics/$pic_filename"); $base_path = './uploads/item_pics/' . pathinfo($pic_filename, PATHINFO_FILENAME);