How to make Tomcat support non-RFC7230/ RFC3986 characters in GET parameters?

3.7k Views Asked by At

After upgrading Tomcat version from 7.0 to 8.5, I found if Chinese or Korean characters are included in GET request parameters, tomcat will throw an IllegalArgumentException: Invalid character found in the request target.

org.apache.coyote.http11.Http11Processor service
INFO: 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:1149)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(Thread.java:748)

the reason is that tomcat no longer supports characters other than RFC 7230 and RFC 3986. We tried some solutions:

  1. Configure relaxedQueryChars in server.xml according to
<Service name="Catalina">
  <Connector port="10001" protocol="HTTP/1.1"
    connectionTimeout="20000"
    maxThreads="1024"
    minSpareThreads="64"
    redirectPort="8443"
    URIEncoding="UTF-8"
    useBodyEncodingForURI="true"
    maxHttpHeaderSize="65536"
    maxPostSize="-1"
    maxParameterCount="10000"
    bindOnInit="false"
    relaxedPathChars="[ \ ] ^ ` { | }"
    relaxedQueryChars="[ \ ] ^ ` { | }" />

However, the value may be any combination of the following characters: " < > [ \ ] ^ { | }`, any other characters present in the value will be ignored. That means Chinese/Korean parameters will still get an error.

  1. Modify the client side and encode each parameter when requesting the api.
    It can solve the problem, but it seems not feasible since we cannot modify all the clients, for example, the released APP cannot be modified.

Is there any good general solution? I hope can change some tomcat configuration to make it support Chinese/Korean characters in GET parameters.

0

There are 0 best solutions below