【发布时间】:2012-01-16 13:27:24
【问题描述】:
我正在执行一项确保 PHP 文件上传安全的任务,我的客户希望遵循网站上提到的指南http://www.acunetix.com/websitesecurity/upload-forms-threat.htm
我们能够遵循本网站上提到的所有准则,接受 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 脚本当然不起作用并返回权限错误。努力完成这项工作。
您能帮我完成这项工作或以任何其他有效的方式进行此安全检查吗?我们不想在系统上留下安全漏洞。
任何帮助将不胜感激。
谢谢大家。
【问题讨论】:
标签: php security file .htaccess upload