6

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)
danny
  • 427
  • 1
  • 15
  • 25
  • Similar to https://stackoverflow.com/questions/50361171/how-to-allow-character-in-urls-for-tomcat-8-5 which has a well-accepted answer. – Mukul Bansal Jun 14 '19 at 06:19

2 Answers2

9

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" />
danny
  • 427
  • 1
  • 15
  • 25
  • Danny you are correct, the issue has something to do with the {} that I have in my request. But I think this could be caused by an missing library, that was actually there to create JSON in the HTTP body, and was missing. I will have to investigate it further, but your hint was correct. – Erdinc Ay Jul 24 '19 at 15:25
4

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:

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Interesting that invalid URL chars ever worked, especially if RH is using standard HTTP/URL libs/classes, that you'd think would have never allowed those chars (unless the set has grown?). – galaxis May 25 '21 at 16:54
  • @galaxis - you are making a few assumptions there. – Stephen C May 25 '21 at 22:38