Skip to content

Fix: Add path traversal protection to DirectivePlugin (APSB26-05)#50

Open
Maksold wants to merge 1 commit into
MagestyApps:masterfrom
Maksold:fix/apsb26-05-path-traversal-protection
Open

Fix: Add path traversal protection to DirectivePlugin (APSB26-05)#50
Maksold wants to merge 1 commit into
MagestyApps:masterfrom
Maksold:fix/apsb26-05-path-traversal-protection

Conversation

@Maksold
Copy link
Copy Markdown

@Maksold Maksold commented Mar 27, 2026

Summary

Magento 2.4.6-p14 security patch (APSB26-05) added path traversal protection to Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute() via DirectoryResolver::validatePath(). This ensures that only files within the pub/media/ directory can be served.

However, DirectivePlugin::aroundExecute() returns early for SVG/vector images before calling $proceed(), which means the new security validation is completely bypassed for vector image requests.

Security Issue

An admin user could craft a ___directive parameter that resolves to a path outside pub/media/ (e.g., ../../app/etc/env.php). If the file passes isVectorImage() check (extension or MIME type), its contents would be returned via file_get_contents() without any path validation.

Changes

  • Add DirectoryResolver to validate that the resolved file path is within the media directory
  • Add Filesystem for proper path resolution via getAbsolutePath() (consistent with core Magento approach)
  • Normalize path separators (\/) before processing
  • Replace file_get_contents() with $mediaDirectory->readFile() to use Magento's filesystem abstraction instead of raw PHP file access

Affected Magento Versions

All Magento installations using magestyapps/module-web-images with Magento 2.4.6-p14+ (and likely earlier versions that had less comprehensive but still relevant path handling).

Testing

  1. Upload an SVG image via WYSIWYG media gallery → should render correctly (no regression)
  2. Attempt to access a file outside pub/media/ via crafted directive → should fail with "Invalid Path" exception and fall through to $proceed()

Magento 2.4.6-p14 security patch (APSB26-05) added path traversal
protection to Cms\Controller\Adminhtml\Wysiwyg\Directive::execute()
via DirectoryResolver::validatePath(). However, the DirectivePlugin
uses aroundExecute() and returns early for SVG files, completely
bypassing this security validation.

Changes:
- Add DirectoryResolver to validate file path is within media directory
- Add Filesystem for proper path resolution via getAbsolutePath()
- Normalize path separators (backslash to forward slash)
- Replace file_get_contents() with Magento filesystem abstraction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant