Fix directory path served as file in \Magento\MediaStorage\App\Media#40516
Open
DmitryFurs wants to merge 1 commit intomagento:2.4-developfrom
Open
Fix directory path served as file in \Magento\MediaStorage\App\Media#40516DmitryFurs wants to merge 1 commit intomagento:2.4-developfrom
\Magento\MediaStorage\App\Media#40516DmitryFurs wants to merge 1 commit intomagento:2.4-developfrom
Conversation
|
Hi @DmitryFurs. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Contributor
|
@magento create issue |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Magento\MediaStorage\App\Media::launch()does not check whether the requested path is a file before serving it. When a directory path is requested (e.g.,/media/email/logo/websites/1/), it passesisReadable()but reachesMagento\Framework\File\Transfer\Adapter\Http::send()which throws:The same bug was previously fixed in
pub/get.php(line 70) with anis_dir()guard, but the equivalent check was never added toMedia::launch().This PR adds
isFile()checks alongside existingisReadable()checks in two places:launch()- before setting the response file pathcreateLocalCopy()- before returning early for already-synced filesSentry Catch:

Related Pull Requests
is_dir()fix forpub/get.php(same bug, different code path)Manual testing scenarios
Stores > Configuration > Sales > Sales Emails > Email Logo Imagevar/resource_config.json)File '...' does not exists.Alternative scenario:
/media/catalog/product/m/a/) whenvar/resource_config.jsonis expired or missingHttp::send()Questions or comments
The
is_dir()guard inpub/get.php(line 55) was added to fix #296, but only covers the fast-path when the resource config cache is valid. When the cache is expired or missing,get.phpfalls through toMedia::launch()which lacks this check.Real-world trigger: Microsoft Outlook sends
OPTIONSpreflight requests to directory paths before loading email logo images. Access log example:Outlook's
OPTIONSrequest targets the parent directory URL (without the filename), which passes throughget.phptoMedia::launch()and causes the exception. This is reproducible with any email client that sends preflight requests to media URLs.Contribution checklist (*)
Resolved issues:
\Magento\MediaStorage\App\Media#40520: Fix directory path served as file in\Magento\MediaStorage\App\Media