Skip to content

Images can't be uploaded using WYSIWYG if media directory is a symlink #13929

@erikhansen

Description

@erikhansen

As of 2.2.3, it's not possible to upload images via the WYSIWYG if the media directory is a symlink. This is due to this new file.

Preconditions

  1. Install Magento 2.2.3
  2. Ensure that the media directory is a symlink. For example, the pub/media directory should be a symlink that points somewhere else.

Steps to reproduce

  1. Edit a CMS Block and click "Insert Image".
  2. Try to upload an image.

Expected result

  1. The image should upload successfully.

Actual result

  1. You'll get an error like this:
    Directory /var/www/prod/releases/20180228212716/pub/media/wysiwyg is not under storage root path.
    
    magento admin-xazv0

Workaround

UPDATE: As of Magento 2.2.5 / 2.3.0, this issue has been fixed and you shouldn't apply the patch below or else you'll break the functionality.

We've temporarily fixed this by changing this line from this:

$realPath = realpath($path);
$root = $this->directoryList->getPath($directoryConfig);

to this (note the addition of the realpath function call):

$realPath = realpath($path);
// BEGIN EDIT
/**
 * Since media directory is a symlink, need to run both paths through realpath in order for the comparison to
 * work.
 * The proper fix for this should involve a STORE > Configuration setting where an admin can choose whether to
 * allow symlinked directories.
 */
$root = realpath($this->directoryList->getPath($directoryConfig));
// END EDIT

Metadata

Metadata

Assignees

No one assigned

    Labels

    Event: balance-cdEvent: distributed-cdDistributed Contribution DayEvent: kiev-cdFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions