Tomcat 8.5 400 error: Invalid character found in the request target. Problem resolution

Keywords: Java Tomcat Apache IE

When the project was recently deployed, because MIS was configured as Tomcat 8.5 server, the Web application was abnormal and HTTP 400 error was reported (Chrome no exception, IE error). The reason for the problem is that the server receiving the request in version 8.5 will not escape the symbol. The reason why Chrome is not abnormal may be that the browser itself has escaped. The specific error information is as follows:

 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:472)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:683)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
        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)

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

After consulting a large amount of information, there are two solutions:

Plan 1:
Replace the lower version of Tomcat to avoid this problem.

Plan 2:
Add the last line in conf/catalina.properties:

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

After restarting the server, solve the problem.

Official Guide Address: http://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html

Official note:

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH

If this is true '%2F' and '%5C' will be permitted as path.delimiters.If not specified, the default value of false will be used.

Posted by LTJason on Thu, 14 Feb 2019 13:33:17 -0800