dongtun3259 2012-05-08 00:52
浏览 183
已采纳

如果允许用户上传的所有文件类型扩展名,则存在安全风险

Background: I have a website where people can store transactions. As part of this transaction, they could attached a receipt if they wanted.

Question: Is there any security risk if a user is allowed to upload any type of file extension to my website?

Info:

  • The user will be only person to ever re-download the same file
  • There will be no opportunity for the user to "run" the file
  • They will only be able to download it back to themselves.
  • No other user will ever have access to another users files
  • There will be a size restriction on the say (say 2mb)

More info: I was originally going to restrict the files to "pdf/doc/docx" - but then realised some people might want to store a jpg, or a .xls etc - and realised the list of files they "might" want to store is quite large...

edit: The file will be stored outside public_html - and served via a "readfile()" function that accepts a filename (not a path) - so is there anything that can 'upset' readfile()?

  • 写回答

2条回答 默认 最新

  • dongsuo0517 2012-05-08 00:57
    关注

    Yes, it is definitely a security risk unless you take precautions. Lets say, to re-download the file, the use has to go to example.com/uploads/{filename}. The user could upload a malicious PHP file, and then 'redownload' it by going to example.com/uploads/malicious.php. This would, of course, cause the PHP script to execute on your server giving him enough power to completely wreck everything.

    To prevent this, create a page that receives the filename as a parameter, and then serve the page to the user with the correct content-type.

    Something like, example.com/files?filename=malicious.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献