如何保护Web服务器的图像上传目录? [英] How do i secure a web server's image upload directory?

查看:79
本文介绍了如何保护Web服务器的图像上传目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的Web应用程序,人们可以将图像从Web表单上传到我的Web服务器。

For my web application, people can upload images from a web form to my web server.

我应该为该图像上传设置CHMOD设置目录,以便人们可以出于安全原因将图像(从Web服务器)上传到该目录,但不执行他们上传的任何文件。

chmod设置是? :

Would the chmod settings be? :

chmod 744 directory/   


推荐答案

在这种情况下,可执行有两种可能的含义,而这两种都是您需要配置的。

There are two possible meanings for "executable" in this context, and both are things you need to configure against.


  1. 可执行二进制文件,可以通过在命令行中将文件名键入外壳程序来从命令行运行

  1. An executable binary file that may run from the command line by typing the file's name into a shell

可以被读取并由Web服务器作为脚本处理的文件。

A file that may be read and processed as script by a web server.

处理二进制可执行文件

要针对un * x系统上的情况1进行配置,您需要确保上传目录和其中的文件由Web服务器用户拥有,并且只能由该用户读取。该目录必须是可执行的。这意味着可以访问该目录中的文件)。如果Web用户需要列出目录中的文件,则它也必须可读。当然,它也必须是可写的,以允许创建新文件。

To configure against case 1 on a un*x system, you need to ensure that your upload directory, and files therein, are owned by the web server user and only readable by that user. The directory must be executable; this means that the files inside that directory can be accessed). If the web user needs to list the files in the directory, it must also be readable. It, of course, must also be writable to allow new files to be created.

因此,您想要的八进制集将是

Thus the octal set you want would be

chown <web-server-user> <upload-dir>
chmod 0700 <upload-dir>

文件不能是可执行文件,只能由Web服务器读取和写入,因此这些文件应该

The files must not be executable and should only be readable and writable by the web server,so these should be

chmod 0600 <uploaded-file>

请注意,这意味着只有Web服务器用户查看这些文件。这是安全的最佳情况。但是,如果您确实确实需要其他本地用户才能看到这些文件,请使用

Please note that this means that only the web server user will be able to see these files. This is the best situation for security. However, if you really do need other local users to be able to see these files,then use

chmod 0755 <upload-dir>
chmod 0644 <uploaded-file>

处理网络服务器可执行文件

针对情况2的编码是Web服务器特定的。

Coding against case 2 is web server specific.

一种选择是将上载目录放置在webroot之外,完全拒绝对上载文件的直接URL访问,并且仅通过服务器端代码提供服务。您的代码读取并回显文件内容,从而确保Web服务器永远不会将其作为脚本处理

One option is to place the upload directory outside of the webroot, dissalowing direct URL access to the uploaded files completely and only to serve them via server-side code. Your code reads and echoes the file content, thus ensuring it is never processed as script by the web server

另一种方法是将Web服务器配置为不允许脚本处理上传目录中的文件数量。此配置特定于Web服务器。但是,例如,在Apache中,您可以通过输入服务器配置来实现此目的:

The other option is to configure your web server to not allow script processing of files in the upload directory. This configuration is web-server specific. However, for example, in Apache you can achieve this this by entering into your server configuration:

<Directory "path-to-upload-dir">
  AllowOverride None
  Options -ExecCGI
</Directory>

AllowOverride没什么重要,因为它会阻止任何人将.htaccess文件上传到您的上传目录并重新配置该目录的Web服务器权限。

AllowOverride None is important, as it stops anyone uploading a .htaccess file to your uploads directory and re-configuring the web server permissions for that directory.

这篇关于如何保护Web服务器的图像上传目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆