-
Notifications
You must be signed in to change notification settings - Fork 9.4k
FIX: Can't validate uploaded file for tmp folder mismatching #27352
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
base: 2.4-develop
Are you sure you want to change the base?
Conversation
…r tmp folder mismatching magento#25835 when upload file, php returns destination path of symlinked tmp folder. but sys_get_temp_dir() function only return target path of symlinked folder. this mismatch made it can't pass the validation. this commit validate on both target path and destination path if symlink found. I couldn't find php $_FILE source reference, so I put both pathes on validation.
Hi @baranada. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
Closing this PR since the issue can be resolved by configuring |
Hi @baranada, thank you for your contribution! |
@baranada: changes look good at first sight, but don't work in all cases. For example, on macOS, when executing Here are suggested changes to make it work in all cases I think: $sysTmpFolder = sys_get_temp_dir();
$sysTmpFolderRealPath = realpath($sysTmpFolder);
$allowedFolders = [
$sysTmpFolder,
$sysTmpFolderRealPath,
$this->directoryList->getPath(DirectoryList::MEDIA),
$this->directoryList->getPath(DirectoryList::VAR_DIR),
$this->directoryList->getPath(DirectoryList::TMP),
$this->directoryList->getPath(DirectoryList::UPLOAD),
]; I'm reopening this PR based on the fact that I believe there is an actual improvement we can make here. |
@hostep, thank you for your reply. |
@baranada: to be safe I would check on both paths, I'm not familiar enough with how the path in the $_FILES global are being set in all kinds of different environments. I think we are probably most safe when checking for both the symlinked and the realpath directories. |
Hi @baranada: are you still able/willing to put some extra time into this? Thanks! |
I couldn't make test code for this. |
@lenaorobei: can you or somebody else please review this, that would be appreciated, thanks! 🙂 |
@magento run all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good. @baranada, could you please write simple integration test to cover this case?
Since I am not familiar with magento2 test code, I will try and come back to you next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this PR to corresponding status as requested in #27352 (review)
@magento run all tests |
Hi, @baranada! |
Hi @baranada, thank you for your contribution! |
Hi @baranada. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. |
@magento run all tests |
Description (*)
when upload file, php $_FILE variable returns destination path of symlinked tmp folder.
but sys_get_temp_dir() function only return target path of symlinked folder.
this mismatch made it can't pass the validation. this commit validate on both target path and destination path if symlink found.
I couldn't find php $_FILE source reference, so I put both path on validation.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
"Invalid parameter given. A valid $fileId[tmp_name] is expected"
Questions or comments
Contribution checklist (*)