Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browse field type goto 403 after 3.0.9 #59

Closed
drserhio opened this issue Nov 15, 2024 · 8 comments
Closed

browse field type goto 403 after 3.0.9 #59

drserhio opened this issue Nov 15, 2024 · 8 comments
Assignees
Labels
bug Something isn't working Priority: MUST

Comments

@drserhio
Copy link

CrudController / setupCreateOperation
Browse Field Type
Request https://site.com/admin/elfinder/popup/attribute_name
request('mimes') - not present
403 error permanently

That's how it works (class BackpackElfinderController):
try {
if(request('mimes')){
$mimes = Crypt::decrypt(urldecode(request('mimes')));
}
} catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
Log::error('Someone attempted to tamper with mime types in elfinder popup. The attempt was blocked.');
abort(403, 'Unauthorized action.');
}

Copy link

Based on the information provided in the knowledge sources, I can offer some insights into your issue with the browse field type in Backpack 3.0.9 and later versions.

It seems you're encountering a 403 error when trying to access the elFinder popup for the browse field type. This issue appears to be related to the handling of MIME types in the BackpackElfinderController.

The code snippet you provided shows that the controller is attempting to decrypt the 'mimes' parameter from the request. If this decryption fails, it results in a 403 error.

To address this issue, you might want to check the following:

  1. Ensure that the 'mimes' parameter is being properly set and encrypted when the browse field is initialized. This should be happening in the CRUD setup for your field.

  2. Verify that the encryption key used in your application matches the one used when the 'mimes' parameter was encrypted.

  3. Check if there are any middleware or other components in your application that might be interfering with the request parameters.

Unfortunately, the provided knowledge sources don't contain specific information about this particular error in Backpack 3.0.9 or later versions. The closest relevant information I found is about file type restrictions in the browse field, but it doesn't directly address your 403 error issue.

If the problem persists, you might want to:

  1. Check the Backpack documentation for any changes in how the browse field type is implemented in version 3.0.9 and later.

  2. Consider opening an issue on the Backpack CRUD GitHub repository with details about your setup and the exact steps to reproduce the error.

  3. Review your Laravel and Backpack logs for any additional error messages that might provide more context.

I apologize that I don't have more specific information to resolve your issue. If you need further assistance, you might want to provide more details about your setup and the exact steps to reproduce the error.

Relevant sources:

Github Issue (closed): [4.0][Bug] Multiple images upload to the File Manager
Github Issue (closed): addField type browse file restriction
Github Issue (closed): How to extend elfinder
where to put permission check
Github Issue (closed): [Feature request] Allow mime_types filter on browse field
Github Issue (closed): Elfinder known vulnerabilities
Github Issue (closed): denyAccess(); throws AccessDeniedException with error 500 instead 403
Github Issue (closed): upload field required
Github Issue (closed): [Bug] export buttom and browse field
How to forbid to create and upload folders to file manager
Github Issue (closed): Browse field type and wrong iframe URL to elFinder

@pxpm
Copy link
Contributor

pxpm commented Nov 18, 2024

Thanks for the report @drserhio and sorry for the bad experience.

A composer update should get you the fixed versions of FileManager and PRO. If you get filemanager 3.0.10 and pro 2.2.23 you are all set.

If you are unable to update PRO you need to manually apply the fix in your browser field.

1 - check if you already have the field published in your resources/view/vendor/backpack/pro/fields/browse_multiiple.blade.php or resources/view/vendor/backpack/crud/fields/browse_multiiple.blade.php. If you do skip to step 3.
2 - publish the browse_multiple file into your resources folder: php artisan backpack:field --from=browse_multiple . This will create a file in your resources/view/vendor/backpack/crud/fields/browse_multiiple.blade.php
3 - do the following changes at lines 14 ~ 16:

- if (isset($field['mime_types'])) {
-    $field['wrapper']['data-elfinder-trigger-url'] .= '&mimes='.urlencode(serialize($field['mime_types']));
- }
+ $field['wrapper']['data-elfinder-trigger-url'] .= '&mimes='.urlencode(Crypt::encrypt($field['mime_types'] ?? ''));

Let us know if you are still experiencing issues 👍

@munjaldevelopment
Copy link

munjaldevelopment commented Nov 18, 2024

Thanks for the solution @pxpm but still this issue NOT resolved on single browse button popup..

@munjaldevelopment
Copy link

Adding this line in browse.blade.php solve the issue.

image

@pxpm
Copy link
Contributor

pxpm commented Nov 18, 2024

Thanks @munjaldevelopment I've just released a new version o backpack pro with the fix.

This field didn't support the mimes functionality so I overlooked it, my bad 🙏

Please allow a few moments for our private repository to pick the changes and you can get the fixed version with a composer update.

For people unable to update PRO, please see the instructions here on how to publish the browse field: #59 (comment) (changing the relevant parts for the browse field)

1 - Add at the top of your file:

$field['attributes']['data-elfinder-trigger-url'] = $field['attributes']['data-elfinder-trigger-url'] ?? url(config('elfinder.route.prefix').'/popup/'.$field['name']);
$field['attributes']['data-elfinder-trigger-url'] .= '?mimes='.urlencode(Crypt::encrypt($field['mime_types'] ?? ''));

2 - remove line 13:

- data-elfinder-trigger-url="{{ url(config('elfinder.route.prefix').'/popup') }}"

3 - Change line 74 to:

- href: triggerUrl + '/' + name,
+ href: triggerUrl,

Once again, thank you very much 🙏

@drserhio
Copy link
Author

drserhio commented Nov 18, 2024 via email

@BenjaminVerhaegen
Copy link

Hi, the elfinder on ckeditor is also returning a 403. How can i fix this?

@pxpm
Copy link
Contributor

pxpm commented Nov 21, 2024

Hey @BenjaminVerhaegen thanks for the report. If you have access to PRO, I've just released a fixed version, allow a few moments for our private repository to pick the changes and you can get the fixed version with a composer update.

In case you don't have access to PRO updates anymore, follow a similar approach I described earlier to publish ckeditor.blade.php to your resources folder and change the following.

Lines 10~11

-    if($hasElfinder && !in_array('ckfinder', $toolbar)) {
-       $toolbar = array_merge($toolbar, ['|', 'ckfinder']);
+    if($hasElfinder) {
+       $field['attributes']['data-elfinder-trigger-url'] = $field['attributes']['data-elfinder-trigger-url'] ?? url(config('elfinder.route.prefix').'/popup/'.$field['name'].'?multiple=1');
+        $field['attributes']['data-elfinder-trigger-url'] .= '&mimes='.urlencode(Crypt::encrypt($field['elfinderOptions']['onlyMimes'] ?? ''));
+        if(! in_array('ckfinder', $toolbar)) {
+           $toolbar = array_merge($toolbar, ['|', 'ckfinder']);
+        }
+    }

Line 97 add:

+  let elfinderTriggerUrl = element.data('elfinder-trigger-url');

Line 112 replace:

- href: '{{url(config('elfinder.route.prefix').'/popup/elfinder?multiple=1')}}',
+ href: elfinderTriggerUrl,

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Priority: MUST
Projects
Status: Done
Development

No branches or pull requests

5 participants