Skip to content

Commit 7e6b91d

Browse files
committed
fix: code cleanup and improved code from 4.2
1 parent 3058437 commit 7e6b91d

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

phpmyfaq/assets/templates/admin/login.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
</div>
3434
<div class="card-body">
3535
<form action="{{ loginUrl }}" method="post" accept-charset="utf-8" role="form">
36-
<input type="hidden" name="redirect-action" value="{{ redirectAction }}">
3736
<div class="form-floating mb-3">
3837
<input class="form-control" id="faqusername" name="faqusername" type="text"
3938
placeholder="{{ msgUsername }}">

phpmyfaq/assets/templates/admin/user/twofactor.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<form action="{{ systemUri }}admin/check" method="post"
2626
accept-charset="utf-8" role="form" class="pmf-form-login">
2727
<input type="hidden" name="user-id" id="user-id" value="{{ userId }}">
28-
<input type="hidden" name="redirect-action" value="{{ redirectAction }}">
2928
<div class="form-group">
3029
<label for="token">{{ msgEnterTwofactorToken }}</label>
3130
<div class="col-4 mx-auto my-2">

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/ImageController.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232

3333
final class ImageController extends AbstractController
3434
{
35+
private const array ALLOWED_MIME_TYPES = [
36+
'gif' => 'image/gif',
37+
'jpg' => 'image/jpeg',
38+
'jpeg' => 'image/jpeg',
39+
'png' => 'image/png',
40+
'webp' => 'image/webp',
41+
'mov' => 'video/quicktime',
42+
'mp4' => 'video/mp4',
43+
'webm' => 'video/webm',
44+
];
45+
3546
/**
3647
* @throws Exception|\Exception
3748
*/
@@ -43,7 +54,7 @@ public function upload(Request $request): JsonResponse
4354
$session = $this->container->get(id: 'session');
4455

4556
$uploadDir = PMF_CONTENT_DIR . '/user/images/';
46-
$validFileExtensions = ['gif', 'jpg', 'jpeg', 'png', 'webp', 'mov', 'mp4', 'webm'];
57+
$validFileExtensions = array_keys(self::ALLOWED_MIME_TYPES);
4758
$timestamp = time();
4859

4960
if (!Token::getInstance($session)->verifyToken('pmf-csrf-token', $request->query->get('csrf'))) {
@@ -93,11 +104,34 @@ public function upload(Request $request): JsonResponse
93104
);
94105
}
95106

96-
// Accept upload if there was no origin, or if it is an accepted origin
107+
// Accept upload if there was no origin or if it is an accepted origin
97108
$fileName = $timestamp . '_' . $file->getClientOriginalName();
98109
$fileName = str_replace(' ', '_', $fileName);
99110
$file->move($uploadDir, $fileName);
100111

112+
$filePath = $uploadDir . $fileName;
113+
$fileExtension = strtolower((string) $file->getClientOriginalExtension());
114+
115+
// Validate actual MIME type matches the claimed extension
116+
$detectedMime = mime_content_type($filePath);
117+
$expectedMime = self::ALLOWED_MIME_TYPES[$fileExtension] ?? null;
118+
119+
if ($detectedMime === false || $expectedMime === null || $detectedMime !== $expectedMime) {
120+
if (file_exists($filePath)) {
121+
unlink($filePath);
122+
}
123+
124+
return $this->json(
125+
[
126+
'success' => false,
127+
'data' => ['code' => Response::HTTP_BAD_REQUEST],
128+
'messages' => ['File content does not match the file extension'],
129+
],
130+
Response::HTTP_BAD_REQUEST,
131+
$headers,
132+
);
133+
}
134+
101135
// Add to the list of uploaded files
102136
$uploadedFiles[] = $fileName;
103137
}

phpmyfaq/src/phpMyFAQ/Controller/Administration/AuthenticationController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public function login(Request $request): Response
106106
'isLogout' => $request->query->get(key: 'action') === 'logout',
107107
'logoutMessage' => Translation::get(key: 'ad_logout'),
108108
'loginUrl' => $this->configuration->getDefaultUrl() . 'admin/authenticate',
109-
'redirectAction' => $request->query->get(key: 'action') ?? '',
110109
'msgUsername' => Translation::get(key: 'ad_auth_user'),
111110
'msgPassword' => Translation::get(key: 'ad_auth_passwd'),
112111
'msgRememberMe' => Translation::get(key: 'rememberMe'),

0 commit comments

Comments
 (0)