2

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)
G Josh
  • 271
  • 1
  • 5
  • 15
  • 1
    I think the solution is to encode those characters before sending them to the server (guessing, but that seems likely). – markspace May 31 '19 at 02:07
  • Possible duplicate of [Tomcat 8 is not able to handle get request with '|' in query parameters?](https://stackoverflow.com/questions/41053653/tomcat-8-is-not-able-to-handle-get-request-with-in-query-parameters) – Mebin Joe May 31 '19 at 06:59
  • If the problem is that puppet overwrites it, then you need to fix it in your puppet deployment. – Mark Rotteveel May 31 '19 at 19:57
  • Is XML encoding not an option? If you can control what is sent, just don't send invalid characters. – Stefan Falk Jun 01 '19 at 08:39
  • Thanks for the help everyone. It is viable to configure puppet, but I'm gonna go ahead and just update the code and not send invalid characters – G Josh Jun 03 '19 at 01:38

1 Answers1

2

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
Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
  • Thanks! Yeah, looks like I can get Puppet to be configured to setup ```relaxedQueryChars``` I can also get this fixed in the application bi encoding those characters. Both of these options seem viable and I'll just go ahead and update my code. – G Josh Jun 03 '19 at 01:36