哪里是保存用户上传图像的最佳位置 [英] where is the best place to save images from users upload

查看:30
本文介绍了哪里是保存用户上传图像的最佳位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个展示画廊的网站.用户可以从网络上传自己的内容(通过输入 URL)或从他们的计算机上传图片.

I have a website that shows galleries. Users can upload their own content from the web (by entering a URL) or by uploading a picture from their computer.

我将 URL 存储在数据库中,这对于第一个用例来说工作正常,但如果用户从他们的计算机上传,我需要弄清楚实际图像的存储位置.

I am storing the URL in the database which works fine for the first use case but I need to figure out where to store the actual images if a user does a upload from their computer.

此处是否有任何建议或最佳做法来说明我应该将它们存储在哪里?

Is there any recommendation here or best practice on where I should store these?

我应该将它们保存在 appdata 或 content 文件夹中吗?是否应该根本不将它们存储在网站中,因为它是用户内容?

Should I save them in the appdata or content folders? Should they not be stored with the website at all because it's user content?

推荐答案

您不应该将用户上传的内容存储在您的站点结构中可以通过已知 URL 直接访问的任何位置.这是一个安全风险,因为用户可以上传 .htm 文件和 .js 文件.即使具有正确扩展名的文件也可能包含恶意代码,经过身份验证的用户可以在您的站点上下文中执行这些代码,从而允许服务器端或客户端攻击.

You should NOT store the user uploads anywhere they can be directly accessed by a known URL within your site structure. This is a security risk as users could upload .htm file and .js files. Even a file with the correct extension can contain malicious code that can be executed in the context of your site by an authenticated user allowing server-side or client-side attacks.

参见例如 http://www.acunetix.com/websitesecurity/upload-forms-threat.htm当用户可以上传自己的文件时会出现哪些安全问题?其中提到了在您允许用户上传文件然后在您的网站中显示它们以供下载之前您需要注意的一些问题.

See for example http://www.acunetix.com/websitesecurity/upload-forms-threat.htm and What security issues appear when users can upload their own files? which mention some of the issues you need to be aware of before you allow users to upload files and then present them for download within your site.

  1. 不要把文件放在你正常的网站目录结构中

  1. Don't put the files within your normal web site directory structure

不要使用用户给你的原始文件名.您可以添加带有原始文件名的内容处置标头,以便他们可以以相同的文件名再次下载它,但服务器上的路径和文件名不应受到用户的影响.

Don't use the original file name the user gave you. You can add a content disposition header with the original file name so they can download it again as the same file name but the path and file name on the server shouldn't be something the user can influence.

不要相信图像文件 - 调整它们的大小并仅提供调整后的版本以供后续下载

Don't trust image files - resize them and offer only the resized version for subsequent download

不要相信 mime 类型或文件扩展名,打开文件并对其进行操作以确保它是它声称的那样.

Don't trust mime types or file extensions, open the file and manipulate it to make sure it's what it claims to be.

限制上传大小和时间.

这篇关于哪里是保存用户上传图像的最佳位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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