Problem with special characters in request header in Tomcat 9

G Josh :

After a recent upgrade to Tomcat 9 from Tomcat 8, I got issues with the request header that has special characters, for my case "<" and ">" characters. Error says "Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986"

I tried to search around for a way and stumbled upon a solution which says I can add "relaxedQueryChars="<,>" into my server's server.xml but the problem with this solution is that we're not allowed to edit anything in the server as it is managed by puppet so it just gets overwritten every time.

Is there a way to add relaxedQueryChars="<,>" on my application instead of adding it in the server? Somewhere like in context.xml or web.xml, I don't really know.

Error message:

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
    org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:834)
Mark Thomas :

Sorry, no. relaxedQueryChars is a Connector attribute so it can only be set in server.xml.

Possible options include:

  • Fixing the application to encode those characters
  • Updatign the Puppet config to set the required value for relaxedQueryChars

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=156631&siteId=1