我正在处理一个任务,使PHP文件上传更加安全,我的客户希望遵循网站http://www.acunetix.com/websitesecurity/upload-forms-threat.htm上提到的指南。
我们能够遵循该网站上提到的所有指南,除了htaccess规则。他们提到要执行以下操作。
为了确保只有 gif、jpg 和 png 文件能够被执行,但又不希望 htaccess 文件放在上传图片的文件夹中,因为该文件夹具有权限并且htaccess文件可能会被覆盖。所以他们建议将此文件放在根目录下。
我想知道如果我们将文件放在根目录下,并仅允许执行图像类型的文件,那么我的 php 脚本将如何执行?当我在根目录下添加这个 htaccess 文件时,我的 php 脚本就无法运行并返回权限错误。我正在努力解决这个问题。
您能帮我解决这个问题或提供任何其他有效的安全检查方法吗?我们不希望系统存在安全漏洞。
非常感谢您的帮助。
我们能够遵循该网站上提到的所有指南,除了htaccess规则。他们提到要执行以下操作。
Define a .htaccess file that will only allow access to files with allowed extensions.
Do not place the .htaccess file in the same directory where the uploaded files will be stored. It should be placed in the parent directory.
A typical .htaccess which allows only gif, jpg, jpeg and png files should include the following (adapt it for your own need). This will also prevent double extension attacks.
deny from all
<Files ~ "^\w+\.(gif|jpe?g|png)$">
order deny,allow
allow from all
</Files>
If possible, upload the files in a directory outside the server root.
Prevent overwriting of existing files (to prevent the .htaccess overwrite attack).
Create a list of accepted mime-types (map extensions from these mime types).
Generate a random file name and add the previously generated extension.
Don’t rely on client-side validation only, since it is not enough. Ideally one should have both server-side and client-side validation implemented.
为了确保只有 gif、jpg 和 png 文件能够被执行,但又不希望 htaccess 文件放在上传图片的文件夹中,因为该文件夹具有权限并且htaccess文件可能会被覆盖。所以他们建议将此文件放在根目录下。
我想知道如果我们将文件放在根目录下,并仅允许执行图像类型的文件,那么我的 php 脚本将如何执行?当我在根目录下添加这个 htaccess 文件时,我的 php 脚本就无法运行并返回权限错误。我正在努力解决这个问题。
您能帮我解决这个问题或提供任何其他有效的安全检查方法吗?我们不希望系统存在安全漏洞。
非常感谢您的帮助。
public_html/user_uploaded_files/.htaccess
,并在其中添加php_flag engine off
。 - Yes Barry