简体   繁体   English

ASP.NET FileUpload Control-缓冲到磁盘时的安全性问题

[英]ASP.NET FileUpload Control - Security concerns when buffered to disk

The MSDN states that when a file is uploaded using the ASP.NET ( v.2.0 ) Fileupload control or the underlying HttpPostedFile that "Files are uploaded in MIME multipart/form-data format. By default, all requests, including form fields and uploaded files, larger than 256 KB are buffered to disk, rather than held in server memory." MSDN指出,当使用ASP.NET(v.2.0)Fileupload控件或基础HttpPostedFile 上传文件时“文件以MIME multipart / form-data格式上传。默认情况下,所有请求,包括表单字段和上载大于256 KB的文件将缓冲到磁盘上,而不是保存在服务器内存中。” MSDN Link MSDN链接

Does anyone know where on the disk it is buffered to and when this buffer is purged / removed ie is it when the request ends and what happens in the case of an error or unexpected scenario where the request doesn't end gracefully? 是否有人知道它在磁盘上的缓冲位置以及何时清除/删除该缓冲区,即请求结束时的状态以及在错误或意外情况下请求无法正常结束的情况下会发生什么?

My concern is that if an application has the ability to upload sensitive information ( CC Data, Personal Data etc ) this file will be buffered on the disk and potentially not removed at the end of the request. 我担心的是,如果应用程序能够上传敏感信息(CC数据,个人数据等),则该文件将被缓冲在磁盘上,并且在请求结束时可能不会被删除。 Would this be a problem on a shared host ie could this buffer be accessed from outside the application? 共享主机上是否会出现问题,即可以从应用程序外部访问此缓冲区?

Maybe I have misunderstood something but any advice / insight / help would be much appreciated, thanks. 也许我误会了一些东西,但是任何建议/见解/帮助将不胜感激,谢谢。

OK have managed to find some answers to the questions posed above so just going to stick them here in case it helps anyone else. OK设法找到了上述问题的答案,所以只要将其粘贴在这里,以防其他人受到帮助。

By default ( in the machine.config ) the settings for file uploads / request in general are 默认情况下(在machine.config中),文件上载/请求的设置通常为

4mb as the maximum size for a request and 256bytes stored in memory before the request is buffered to disk. 请求的最大大小为4mb,在将请求缓冲到磁盘之前将其存储在内存中为256bytes。 These settings can be overridden in the web.config in the httpRuntime section. 这些设置可以在httpRuntime部分的web.config中覆盖。

<httpRuntime maxRequestLength="8192" requestLengthDiskThreshold="512" />

The example above would allow a request size up to 8mb and would start buffering on disk after 512bytes. 上面的示例将允许最大8mb的请求,并在512bytes之后开始在磁盘上进行缓冲。 The file is buffered to 该文件被缓冲到

C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\Temporary ASP.NET Files\\ [APP_NAME] \\ [SOME_HEX_NAME_DIR] \\ [SOME_HEX_NAME_DIR] \\uploads\\ C:\\ WINDOWS \\ Microsoft.NET \\ Framework \\ v2.0.50727 \\ ASP.NET临时文件\\ [APP_NAME] \\ [SOME_HEX_NAME_DIR] \\ [SOME_HEX_NAME_DIR] \\ uploads \\

at this path a file will be created with [unique_name]_post.tmp this exists for the duration of the request but cannot be accessed due to the request having a lock on it. 在此路径下,将使用[unique_name] _post.tmp创建一个文件,该文件在请求期间一直存在,但由于请求已锁定而无法访问。

I tried to interrupt the request in a few ways ( stopping IIS, killing the process, closing the page whilst uploading ) and in all instances the tmp file was removed. 我试图以几种方式中断请求(停止IIS,终止进程,在上载时关闭页面),并且在所有情况下均删除了tmp文件。

So from this it doesn't appear that the sensitive data being buffered is much of an issue as the buffered file does not hang around long. 因此,由此看来,缓冲的敏感数据似乎不会成为大问题,因为缓冲的文件不会长时间徘徊。

Some more info if it helps anyone: 一些其他信息,如果它可以帮助任何人:

From MSDN : "The RequestLengthDiskThreshold property specifies the input-stream buffering threshold limit in number of bytes. Its value should not exceed the MaxRequestLength property value. After a request entity exceeds this threshold, it is buffered transparently onto disk." 来自MSDN :“ RequestLengthDiskThreshold属性以字节数指定输入流缓冲阈值限制。其值不应超过MaxRequestLength属性值。请求实体超过此阈值后,将透明地缓冲到磁盘上。”

I believe that if maxRequestLength is set to the same level as requestLengthDiskThreshold (noting that the former in kB and the latter bytes), then the uploaded content will never be written to disk. 我相信,如果将maxRequestLength设置为与requestLengthDiskThreshold相同的级别(请注意,前者以kB为单位,后者为字节),那么上传的内容将永远不会写入磁盘。

The downside is of course that you will use more memory to service file uploads. 缺点当然是您将使用更多内存来服务文件上传。

eg. 例如。

<httpRuntime maxRequestLength="256" requestLengthDiskThreshold="262144"></httpRuntime>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM