Chmod 640 for uploaded file after SUPEE 7405 patch

Chmod 640 for uploaded file after SUPEE 7405 patch

July 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Chmod 640 for uploaded file after SUPEE 7405 patch

Solving CHMOD 640 Permissions Issue After SUPEE 7405 Patch

The Magento community has been grappling with a permissions issue after the installation of SUPEE 7405 patch. This problem manifests as all uploaded files being set to CHMOD 640, making them inaccessible to users and causing significant operational challenges.

Understanding the CHMOD 640 Issue

The CHMOD 640 permission is a read-execute for the owner only. After the SUPEE patch, Magento’s file uploader sets all newly uploaded files to this mode. This means that:

  • The owner can read and execute (run) the file.
  • No other users or user groups have any access rights to the file.

This issue arises from a change in PHP’s chmod function behavior post-patch, which now respects the umask value set by the operating system. Unfortunately, this is not the desired behavior for media files in Magento.

The Inherent Problem with File Editing

The core of the problem lies within the lib/Varien/File/Uploader.php file used in the patch’s implementation. If we directly modify this file to change CHMOD values, we run into two significant issues:

  1. Version Control: Directly editing core files breaks the version control integrity and may lead to conflicts during future updates.
  2. Security Risks: Changing core functionality without proper testing can introduce new vulnerabilities.

A Safe and Effective Alternative Solution

Instead of directly modifying the core file, we propose a two-step solution that ensures security, preserves version control, and resolves the CHMOD issue:

Step 1: Adjust the Media File Permissions Globally

We can use a script to recursively update all media files’ permissions globally. This way, we don’t need to modify any core functionality.

Create a PHP script (e.g., fix_media_permissions.php) with the following content:

<?php
$rootDir = $_SERVER['DOCUMENT_ROOT'] . '/media/';
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir)) as $file) {
    if ($file->isFile()) {
        chmod($file, 0644); // Change CHMOD to read-write for everyone
    }
}

Run this script via the command line:

php fix_media_permissions.php

Step 2: Implement a Custom File Uploader

For new file uploads, we can create a custom uploader that bypasses the existing core functionality. This ensures that only our desired CHMOD settings are applied.

To achieve this, follow these steps:

  1. Create a new module in your custom theme.
  2. Override the lib/Varien/File/Uploader.php file with a copy of it in your module’s path (e.g., app/code/Vendor/Module/etc/ di.xml).

In your di.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\MediaStorage\Model\File\Uploader">
        <arguments>
            <argument name="uploader" xsi:type="object">Vendor\Module\Model\CustomFileUploader</argument>
        </arguments>
    </type>
</config>
  1. Create the CustomFileUploader.php class in your module’s model directory:
namespace Vendor\Module\Model;

use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\DriverInterface;

class CustomFileUploader implements \Magento\MediaStorage\Model\File\Uploader
{
    // Implement the same methods as Magento\MediaStorage\Model\File\Uploader

    public function save($fieldName, $file)
    {
        // ... (implement the actual file saving logic)
        chmod($destinationFilePath, 0644); // Apply CHMOD 644 to new files
    }
}

Conclusion

The SUPEE 7405 patch has introduced an unintended CHMOD issue that requires a careful approach. By using a combination of global permission fixing and custom uploader implementation, we can resolve the problem without compromising security or version control integrity.

Remember to always test these changes thoroughly in a development environment before deploying them to your production site.

For more comprehensive guides on Magento security patches and their impact, consider exploring Laravel Company’s dedicated resources.

The key takeaway is that while Magento patches aim to enhance security, they may sometimes introduce unexpected behavior. By understanding the underlying mechanisms and implementing safe workarounds, we can ensure our stores remain secure and functional.

Happy coding!

Security Errors

Our network