Skip to content

Consistent behaviour for disallowed path's errors #31583

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

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/code/Magento/MediaStorage/App/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public function launch(): ResponseInterface
$fileAbsolutePath = $this->directoryPub->getAbsolutePath($this->relativeFileName);
$fileRelativePath = str_replace(rtrim($this->mediaDirectoryPath, '/') . '/', '', $fileAbsolutePath);
if (!$isAllowed($fileRelativePath, $allowedResources)) {
throw new LogicException('The path is not allowed: ' . $this->relativeFileName);
require_once 'errors/404.php';
exit;
Comment on lines -193 to +194
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we shouldn't remove the exception from here, instead, we should handle it properly where we believe that the 404 should be displayed. Other clients that use this function may react differently than show 404 and exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is fully encapsulated in the \Magento\Framework\App\Bootstrap class, so there is no way to handle this exception from pub/get.php.

}
}

Expand Down