Django文件上传输入验证和安全 [英] Django file upload input validation and security

查看:240
本文介绍了Django文件上传输入验证和安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个非常简单的django上传应用程序,但我想使其尽可能安全。这是应用程序将是完全一种方式,IE。任何上传文件的人都不必检索它。到目前为止,我已经完成了以下操作:

I'm creating a very simple django upload application but I want to make it as secure as possible. This is app is going to be completely one way, IE. anybody who uploads a file will never have to retrieve it. So far I've done the following:


  1. 禁止某些文件扩展名(.php,.html,.py,.rb,.pl ,.cgi,.htaccess等)

  2. 设置最大文件大小限制和文件名字符长度限制。

  3. 密码保护目录文件被上传到(由.taccess由root拥有,所以Web服务器不可能覆盖它)

假设apache和mod_python都在这个的前端和那个apache本身已被保护,有什么其他的最佳做法的事情我应该做什么或考虑来保护我的申请?

Assuming that apache and mod_python are on the front end of this and that apache itself has been secured, are there any other "best practice" things I should do or consider to protect my application?

提前感谢

推荐答案

不允许文件扩展名可能是浪费时间。 unix服务器不使用扩展名 - 它使用所有权和权限。

Disallowing a file extension is -- potentially -- a waste of time. A unix server doesn't use the extension -- it uses ownership and permissions.

接受上传时,您通常会重命名该文件,以防止其被滥用。上传的文件应简单地命名为upload_xxx,xxx是提供声明的名称和数据类型的某些数据库记录的密钥。

When accepting an upload, you will often rename the file to prevent it being misused. Uploaded files should be simply named "upload_xxx" with the "xxx" being a key to some database record that provides the claimed name and data type.

您必须实际读取该文件并确认该文件的内容是某人声称的内容。

You have to actually read the file and confirm that the content of the file is what someone claims it is.

例如,如果他们声称上传了.JPG,则必须实际读取该文件,以确保它是JPEG,而不是.EXE。

For example, if they claim to upload a .JPG, you have to actually read the file to be sure it's a JPEG, not an .EXE.

这篇关于Django文件上传输入验证和安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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