aboutsummaryrefslogtreecommitdiff
path: root/p/ext.php
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2021-02-02 08:27:34 -0500
committerGravatar GitHub <noreply@github.com> 2021-02-02 14:27:34 +0100
commitd7cfea155f2515a2e5681c5fa2470214cbe1d662 (patch)
treed3c5bf470d2ff92e8f28a2d2ac4f24f1a21c1746 /p/ext.php
parent36f9d44d540c32e092e4511beef44a44453db84d (diff)
Fix extension file search (#3413)
Before, it was possible to retrieve only the files from extensions. Thus making core extension files unreachable. Now, the selected file is search through all extensions folders.
Diffstat (limited to 'p/ext.php')
-rw-r--r--p/ext.php24
1 files changed, 23 insertions, 1 deletions
diff --git a/p/ext.php b/p/ext.php
index 471471ed5..d283e5f8c 100644
--- a/p/ext.php
+++ b/p/ext.php
@@ -13,6 +13,28 @@ const SUPPORTED_TYPES = [
'svg' => 'image/svg+xml',
];
+/**
+ * @return string
+ */
+function get_absolute_filename(string $file_name) {
+ $core_extension = realpath(CORE_EXTENSIONS_PATH . '/' . $file_name);
+ if (false !== $core_extension) {
+ return $core_extension;
+ }
+
+ $extension = realpath(EXTENSIONS_PATH . '/' . $file_name);
+ if (false !== $extension) {
+ return $extension;
+ }
+
+ $third_party_extension = realpath(THIRDPARTY_EXTENSIONS_PATH . '/' . $file_name);
+ if (false !== $third_party_extension) {
+ return $third_party_extension;
+ }
+
+ return '';
+}
+
function is_valid_path_extension($path, $extensionPath) {
// It must be under the extension path.
$real_ext_path = realpath($extensionPath);
@@ -71,7 +93,7 @@ if (empty(SUPPORTED_TYPES[$file_type])) {
sendBadRequestResponse('File type is not supported.');
}
-$absolute_filename = realpath(EXTENSIONS_PATH . '/' . $file_name);
+$absolute_filename = get_absolute_filename($file_name);
if (!is_valid_path($absolute_filename)) {
sendBadRequestResponse('File is not supported.');
}