首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何防止服务器端的大文件上载

问如何防止服务器端的大文件上载
EN

Stack Overflow用户
提问于 2015-03-11 07:36:56
回答 2查看 2K关注 0票数 3

我希望防止我的应用程序受到resource consumption类型的resource consumption攻击。这意味着攻击者可以通过将大型文件上载到服务器来占用服务器资源,如内存和磁盘容量。

我想知道是否可能检查传入文件的元数据,如大小和取消上传一旦达到一个限制。否则,攻击者可能会将20 GB文件上载到服务器,如果服务器等待上载完成以完成验证,那么甚至在上传完成之前,我的服务器就可能会被这样大的文件淹没。

我想知道如何用Java实现这一点。我正在使用Apache/coyote 1.1。

更新:

我在PHP中找到了如下解决方案。

代码语言:javascript
复制
post_max_size integer
    Sets max size of post data allowed. This setting also affects file upload.
    To upload large files, this value must be larger than upload_max_filesize.
    If memory limit is enabled by your configure script, memory_limit also
    affects file uploading. Generally speaking, memory_limit should be larger
    than post_max_size. When an integer is used, the value is measured in bytes.
    Shorthand notation, as described in this FAQ, may also be used. If the size
    of post data is greater than post_max_size, the $_POST and $_FILES
    superglobals are empty [...]

max_file_uploads integer
    The maximum number of files allowed to be uploaded simultaneously. Starting
    with PHP 5.3.4, upload fields left blank on submission do not count towards
    this limit.

在Java中有什么替代品可以替代吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-12 06:18:19

我们可以通过以下方法来测量上传文件的大小,

  1. 客户端(使用HTML5、JSP、JS等)
  2. 上传过程中的动态测量(容器级)
  3. 上传后的测量结束(容器级别)

因为可以调整/破解#1实现。依赖于#2是很好的。MultipartConfig有能力在达到限制时中断文件上传(低于#2)。

注意:

  1. 您可以使用多部分配置作为注释(或)作为web.xml文件中的servlet配置元素。
票数 2
EN

Stack Overflow用户

发布于 2015-03-11 08:03:32

https://www.netroby.com/view.php?id=3585,看看您是否可以限制文件上传的大小。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28980944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档