The MediaBrowserController::index() method handles file deletion for the media browser. When the fileRemove action is triggered, the user-supplied name parameter is concatenated with the base upload directory path without any path traversal validation. The FILTER_SANITIZE_SPECIAL_CHARS filter only encodes HTML special characters (&, ', ", <, >) and characters with ASCII value < 32, and does not prevent directory traversal sequences like ../. Additionally, the endpoint does not validate CSRF tokens, making it exploitable via CSRF attacks.
Affected File: phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/MediaBrowserController.php
Lines 43-66:
#[Route(path: 'media-browser', name: 'admin.api.media.browser', methods: ['GET'])]
public function index(Request $request): JsonResponse|Response
{
$this->userHasPermission(PermissionType::FAQ_EDIT);
// ...
$data = json_decode($request->getContent());
$action = Filter::filterVar($data->action, FILTER_SANITIZE_SPECIAL_CHARS);
if ($action === 'fileRemove') {
$file = Filter::filterVar($data->name, FILTER_SANITIZE_SPECIAL_CHARS);
$file = PMF_CONTENT_DIR . '/user/images/' . $file;
if (file_exists($file)) {
unlink($file);
}
// Returns success without checking if deletion was within intended directory
}
}
Root Causes:
FILTER_SANITIZE_SPECIAL_CHARS does not remove or encode ../ sequences. It only encodes HTML special characters.Token::verifyToken(). Compare with ImageController::upload() which validates CSRF tokens at line 48.basename() to strip directory components or realpath() to verify the resolved path stays within the intended directory.methods: ['GET']...4.1.1Exploitability
AV:NAC:LPR:LUI:RScope
S:CImpact
C:NI:HA:H8.7/CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:N/I:H/A:H