Tomcat升级后变更maxPartCount默认值导致问题处理

说明

  • 由于安全需要对tomcat进行版本升级,tomcat 版本由 8.5.100 升级至 9.0.106 后,在请求参数过多时,会出现如下报错:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.tomcat.util.http.fileupload.impl.FileCountLimitExceededException: attachment
        at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:124)
        at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:115)
        at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:88)
        at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:122)
        at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1205)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:555)
        at org.springframework.web.servlet.FrameworkServlet.service
…………

问题定位及处理

  • 仅看 9.0.106 更新记录未发现有何明显问题
  • 9.0.107 发布时,看变更记录,maxPartCount 参数默认值发生了变更
  • 查看对应的 bugzilla(https://bz.apache.org/bugzilla/show_bug.cgi?id=69710),发现官方为避免恶意攻击请求,将 maxPartCount 默认值由 1000 变更为了 10(9.0.106),导致请求参数过多时,会抛出上述异常。由于影响过大,社区在 9.0.107 版本将此参数默认值变更为 50,常规业务场景下,不会触发上述异常。
  • 针对请求参数个数确实很多的情况,可手动更改此参数放开限制,配置如下:

参考