Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix tomcat org.apache.tomcat.util.http.parser.HttpParser.<clinit> Character [[] is not allowed and will continue to be rejected

There are characters [ and ] in my request URL, and project deployed on Tomcat8.5.33. Some exception happens when I post request.

20-Sep-2018 10:55:36.494 WARNING [http-nio-8075-exec-2] org.apache.tomcat.util.http.parser.HttpParser.<clinit> Character [[] is not allowed and will continue to be rejected.
20-Sep-2018 10:55:36.494 WARNING [http-nio-8075-exec-2] org.apache.tomcat.util.http.parser.HttpParser.<clinit> Character []] is not allowed and will continue to be rejected.
20-Sep-2018 10:56:07.083 INFO [http-nio-8075-exec-10] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
 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:479)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:684)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
    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:748)
like image 888
danny Avatar asked Sep 20 '18 03:09

danny


2 Answers

Tomcat8.5.33 doesn't allow special character in URL, like |{}[]. And there are two methods to avoid this error.

If your special character is one of |{}, you could add config conf\catalina.properties like below directly:

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

If your special character are some others, you could config conf\server.xml like below:

<Connector port="8075" protocol="HTTP/1.1" relaxedQueryChars='|[]'
               connectionTimeout="20000"
               redirectPort="8443" />
like image 64
danny Avatar answered Nov 14 '22 23:11

danny


There are characters [ and ] in my request URL ....

This is the real problem. You are sending your server a request with an invalid URL. A valid URL cannot contain [ and ] ... except in an IP literal in the host part. They must be %-escaped in all other cases.

The correct solution is to fix your URLs and/or the software that generates them on the client side.

Tomcat is simply enforcing the rules in the URL / URI specifications ... that have been in the spec for the last 20+ years or so.

Reference:

  • RFC3986 - Uniform Resource Identifier (URI): Generic Syntax
like image 33
Stephen C Avatar answered Nov 14 '22 22:11

Stephen C