Chmod 640 用于在 SUPEE 7405 补丁后上传的文件


Chmod 640 for uploaded file after SUPEE 7405 patch

安装 SUPEE 7405 补丁后,我们注意到从管理员上传图像时出现问题。所有文件权限都设置为 CHMOD 640,这使得所有用户都无法访问它们。

有没有不涉及重写/lib/Varien/File/Uploader.php 文件的解决方案?

SUPEE-7405的新版本已发布,可解决此问题:

http://magento.com/security/patches/supee-7405

更新于 2016 年 2 月 23 日

此版本的更新版本现已推出。这些更新增加了对 PHP 5.3 的支持,并解决了原始版本中遇到的上传文件权限、合并购物车和 SOAP API 的问题。

请注意,即使没有修订后的修补程序,您也可以使用建议的文件权限来修复问题(见下文)。

<小时 />

Magento希望网络服务器拥有站点文件:

http://devdocs.magento.com/guides/m1x/install/installer-privileges_after.html#privs-after

您可以通过使 Web 服务器成为文件的所有者来解决此问题。

chown -R web-server-user-name magento/root/path

Web 服务器用户名通常www-dataapache

如果您按照上述链接中的说明进行操作,Web 服务器将具有对所有文件的读取访问权限,以及对媒体文件和 var 文件的写入访问权限。这应该是典型站点操作所需的全部内容。如果您需要使用Magento Connect,则必须暂时授予Web服务器对所有文件的写入访问权限。

所有文件权限都设置为 CHMOD 640,这使得所有用户都无法访问它们。

只有 Web 服务器用户需要访问文件。无需向所有用户授予任何权限。

例如,如果您需要通过 FTP 编辑或上传文件,则可能需要向特定用户授予访问权限。在这种情况下,我所做的是设置一个拥有文件系统的用户,并将文件的组设置为Web服务器:

cd magento/root/directory
 
# Set ownership 
# 'username' should be the file system owner username
# 'webserver' should be the webserver username
chown -R username:webserver .
 
# Give the user read/write access to all files.
# Give the webserver read access to all files
find . -type f -exec chmod 640 {} ';
find . -type d -exec chmod 2750 {} '; 
 
# Give the user and the webserver read/write access to var and media
find var/ -type f -exec chmod 660 {} ';
find media/ -type f -exec chmod 660 {} ';
find var/ -type d -exec chmod 2770 {} ';
find media/ -type d -exec chmod 2770 {} ';
chmod 2770 includes
chmod 660 includes/config.php

上述命令将为您的文件系统所有者提供对所有内容的读/写访问权限,以及 Web 服务器对所有内容的读取访问权限。网络服务器还可以写入媒体和

var目录。

我们已经为我们的环境解决了这个问题,但是,我不确定这对其他人有多大帮助。即使我不是网络工程师,我也会尝试解释它。如果有足够多的人觉得这篇文章有帮助,我会将其标记为正确。另外,请注意,即使问题是由Magento的SUPEE 7405补丁引起的,该解决方案也是基于网络的,而不是基于代码的。

我相信补丁中chmod更改的目的是防止黑客劫持您的图像并将敏感数据存储在其中(例如结帐标题图像黑客)。为了防止这种黑客攻击,他们限制通过chmod 640对上传的文件/图像的所有访问。

话虽如此...

Magento 1.X的最新补丁似乎需要更改环境配置。正如我们的一位网络工程师所说,他们假设我们正在将Apache与mod_php一起使用,它以Apache用户的身份读取和写入所有文件。但是,如果您使用的是 fcgi 或 suphp,则文件将以域用户身份写入。根据您的环境,您可能需要将 Apache 添加到您的组并允许它读取文件。

首先尝试chown -R解决方案,如果这不起作用,您可能需要联系您的主机或将Apache添加到您的"组"中,以便它具有所有者访问权限。

请继续这个文件

lib/Varien/File/Uploader.php 

只需更改 220 号线并将chmod($destinationFile, 0640)更改为 chmod($destinationFile, 0644)

它正在工作。

接受的答案是一个很好的解决方案。

如果您无法更改所有权(可能是因为您在共享服务器上),则可以运行 cron 作业来更改新上传文件的文件权限。

*/3 * * * * find /path/to/magento/ -type f -perm 640 -exec chmod 644 {} ';
*/3 * * * * find /path/to/magento/ -type d -perm 750 -exec chmod 2755 {} ';

看看这个: https://community.magento.com/t5/Security-Patches/after-installing-SUPEE-7405-can-no-longer-add-or-change-images/td-p/26785/page/3

更改上传.php代码适用于我的所有分期付款。

To fix existing uploaded images, you need to change ALL existing uploaded images permissions (chmod) from 0640 to 0644.
To fix it for the future, you would need to edit /lib/Varien/File/Uploader.php and change the line from (after applying the patch)
chmod($destinationFile, 0640);
 to
chmod($destinationFile, 0644);
There is a similar one for directories that you'll need to change from 0750 to 0755.