tomcat8.0.30升级为8.5.51注意事项

最近由于爆发了Apache Tomcat AJP协议任意文件下载和任意文件包含可导致远程命令执行的漏洞,tomcat8系列的需要升级至8.5.51.
升级注意几个问题:

  1. bin/catalina.sh
    我们是通过在执行环境配置env来区别不同环境的,所以需要在bin/catalina.sh中添加-Denv=prod代表正式环境。另外性能优化相关的都在这个文件中配置。从原8.0.30复制过来
  2. conf/server.conf
    在这个文件中配置端口号,这个端口号和原来的一致(nginx转发),所以启动前要先关闭原tomcat
  3. conf/context.xml
    启动的时候有警告,在conf/context.xml中配置

[localhost-startStop-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/classes/static/js/ueditor/third-party/highcharts/highcharts.src.js] to the cache for web application [/dgshop-0.0.1-release] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache

  1. conf/catalina.properties
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
	at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:667)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)


由于高版本的tomcat的限制(Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,在http解析时做了严格限制),可以通过在conf/catalina.properties中添加两行和conf/server.xml添加两行配置解决

conf/catalina.properties,requestTargetAllow只能最多配置|{},如果要放开更多的字符需要在conf/server.xml中的Connector添加属性。

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

conf/server.xml添加需要放开的字符

relaxedPathChars="|{}[],"^\"
relaxedQueryChars="|{}[],"^\"

参考

终极解决方案: Invalid character found in the request target. The valid characters are defined in RFC 3986

你可能感兴趣的:(JavaEE,Tomcat)