tomcat cannot parse request parameters correctly

24-Mar-2018 14:11:20.564 INFO [http-nio-8080-exec-3] 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:476)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
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)

Error code 400 The request parameter is incorrect
. The tomcat version is 8.5.29, and invalid characters are used in the request.
According to the RFC specification, the url is only allowed to contain four special characters of English letters (a-zA-Z), numbers (0-9), -_.~ and reserved characters ( ! * ' ( ) ; : @ & = + $ , / ? # [ ] ) (26*2+10+4+18=84) These 84 characters.
And there are {} braces in my request, so tomcat reports an error.

 

Solution: 1. Configure tomcat's support for characters
Add tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} in catalina.properties but only support versions after 7.0.76, 8.0.42, 8.5.12 ( These versions support setting the above properties)
2. Replace tomcat, Tomcat has added restrictions on Url from version 7.0.73, 8.0.39, 8.5.7.
3. Encode and decode the request

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324657433&siteId=291194637