? Pending

User tests: Successful: Unsuccessful:

avatar obuisard
obuisard
18 Aug 2022

When coming back from the Media Helper 'canUpload' function, error messages are lost.

Pull Request for Issue #38068.

Summary of Changes

When a file is denied upload, the message 'Unable to upload file.' is returned.
In the case of SVGs, for instance, a file can be denied for security reasons but no feedback is returned to the user, although all messages are present in the Media Helper.

This PR uses the last entry returned by the Media Helper rather than the default message.

Testing Instructions

Upload a file that is not part of the allowed file types, a file that is too large or an SVG file that is complex and contains suspicious tags (like DOCTYPE). Or remove SVG from the allowed extensions... Anything that can fail the upload of an image or SVG file.

Actual result BEFORE applying this Pull Request

The error message is 'Unable to upload file.'

Expected result AFTER applying this Pull Request

In the case of a SVG file, the message returned should be 'Possible IE XSS Attack found.'

Documentation Changes Required

None

avatar obuisard obuisard - open - 18 Aug 2022
avatar obuisard obuisard - change - 18 Aug 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 18 Aug 2022
Category Front End Plugins
avatar obuisard obuisard - change - 18 Aug 2022
Title
[4.2] Take advantage of the messages returned from the media upload
[4.2] Return messages from the media helper upload on failure
avatar obuisard obuisard - edited - 18 Aug 2022
avatar obuisard obuisard - change - 18 Aug 2022
The description was changed
avatar obuisard obuisard - edited - 18 Aug 2022
avatar obuisard obuisard - change - 18 Aug 2022
The description was changed
avatar obuisard obuisard - edited - 18 Aug 2022
avatar brianteeman
brianteeman - comment - 19 Aug 2022

I like the idea of this PR - a lot

It is not a replacement however to resolving the issue of why svg can no longer be uploaded

avatar richard67
richard67 - comment - 19 Aug 2022

@obuisard Please fix the code style errors reported here: https://ci.joomla.org/joomla/joomla-cms/57037/1/6

avatar laoneo
laoneo - comment - 19 Aug 2022

Getting the exception from the message queue is problematic, what when a plugin added a message before to the queue. Instead of I would add an optional parameter to the canUpload function to throw an exception which is by default false. Then you are on the safe side and doesn't have to deal with the apps message list.

avatar zero-24
zero-24 - comment - 19 Aug 2022

And I would say the message should be limited to Superusers as they are the only one who could do anything about it. This way we also not give a to specific error messages to the possible public user.

avatar zero-24
zero-24 - comment - 19 Aug 2022

Maybe its worth adding 'please contact the site admin for a detailed error analyse' in that case too.

avatar Fedik
Fedik - comment - 19 Aug 2022

Sorry the fix is incorrect.

The MessageQueue already sent with response:

// Send the data
echo new JsonResponse($data);

By default JsonResponse include MessageQueue, it just need to be rendered on client side.
// Get the message queue if requested and available
$app = Factory::getApplication();
if (!$ignoreMessages && $app !== null && \is_callable(array($app, 'getMessageQueue'))) {
$messages = $app->getMessageQueue();
// Build the sorted messages list
if (\is_array($messages) && \count($messages)) {
foreach ($messages as $message) {
if (isset($message['type']) && isset($message['message'])) {
$lists[$message['type']][] = $message['message'];
}
}
}
// If messages exist add them to the output
if (isset($lists) && \is_array($lists)) {
$this->messages = $lists;
}
}

@zero-24 I do not think that need any restriction here, maybe a better message string.
Insetad of technical Possible IE XSS Attack found., need something more clear, kind of This file looks suspicious, therefore cannot be uploaded, or something similar.

avatar obuisard
obuisard - comment - 19 Aug 2022

I like the idea of this PR - a lot

It is not a replacement however to resolving the issue of why svg can no longer be uploaded

Indeed Brian, but I thought this was the first step that could be handled as a fix in 4.2 so people don't wait until 4.3 for the full resolution.

avatar obuisard obuisard - change - 19 Aug 2022
Labels Added: ?
avatar obuisard
obuisard - comment - 19 Aug 2022

Getting the exception from the message queue is problematic, what when a plugin added a message before to the queue. Instead of I would add an optional parameter to the canUpload function to throw an exception which is by default false. Then you are on the safe side and doesn't have to deal with the apps message list.

I totally agree. But I wanted a working fix available as soon as possible without modifying any function's signature.

avatar obuisard
obuisard - comment - 19 Aug 2022

And I would say the message should be limited to Superusers as they are the only one who could do anything about it. This way we also not give a to specific error messages to the possible public user.

I disagree. All users should be able to know that a file has a wrong extension type other than just a message telling them the file cannot be upload.

avatar obuisard
obuisard - comment - 19 Aug 2022

Sorry the fix is incorrect.

The MessageQueue already sent with response:

// Send the data
echo new JsonResponse($data);

By default JsonResponse include MessageQueue, it just need to be rendered on client side.

// Get the message queue if requested and available
$app = Factory::getApplication();
if (!$ignoreMessages && $app !== null && \is_callable(array($app, 'getMessageQueue'))) {
$messages = $app->getMessageQueue();
// Build the sorted messages list
if (\is_array($messages) && \count($messages)) {
foreach ($messages as $message) {
if (isset($message['type']) && isset($message['message'])) {
$lists[$message['type']][] = $message['message'];
}
}
}
// If messages exist add them to the output
if (isset($lists) && \is_array($lists)) {
$this->messages = $lists;
}
}

Great if there is a better way to do this! Do you mind providing your solution? Thank you @Fedik

@zero-24 I do not think that need any restriction here, maybe a better message string. Insetad of technical Possible IE XSS Attack found., need something more clear, kind of This file looks suspicious, therefore cannot be uploaded, or something similar.

Totally agree.

avatar Fedik
Fedik - comment - 19 Aug 2022

Do you mind providing your solution?

I will look

avatar obuisard
obuisard - comment - 19 Aug 2022

Do you mind providing your solution?

I will look

Super! Thank you Fedir

avatar Fedik
Fedik - comment - 19 Aug 2022

please test #38536

avatar laoneo
laoneo - comment - 19 Aug 2022

Closing this in favor of #38536. Thanks @obuisard for bringing this issue on the table.

avatar laoneo laoneo - close - 19 Aug 2022
avatar laoneo laoneo - change - 19 Aug 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-08-19 16:05:25
Closed_By laoneo

Add a Comment

Login with GitHub to post a comment