如何让Tomcat在URL中接受未转义的括号?

cbn*_*bnz 7 java url jsp tomcat

我之前从未使用过Tomcat,但我最近继承了一个JSP项目,现在我需要让它运行起来.我已经设法在Eclipse中本地安装Tomcat 8.0,一切正常.我还在Ubuntu VPS上安装了Tomcat 8.0.该应用程序运行正常,除了它处理URL的一个小问题.

客户端应用程序在参数中生成带有未转义方形和大括号的URL,如下所示:

GET /saveItems.json?items=[{%22json%22:%22here%22}]
Run Code Online (Sandbox Code Playgroud)

尽管我想改变客户端应用程序,但我不能.我只需要让这个后端运行.

我的应用程序的本地副本处理这个罚款.但是,在服务器上,我收到此错误:

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.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:286)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1504)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1460)
    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)
Run Code Online (Sandbox Code Playgroud)

我一直在寻找可能影响这个的设置,没有任何运气.我在这里错过了什么?

小智 8

我通过编辑$ CATALINA_HOME\conf\server.xml使这个可行

旧价值: <Connector ... protocol="HTTP/1.1"... />

新价值: <Connector ... protocol="HTTP/1.1"... relaxedQueryChars='[]|{}^&#x5c;&#x60;&quot;&lt;&gt;' />

  • 请注意,根据您的用例,您可能还想使用relaxedPathChars 而不是relaxedQueryChars。请参阅 https://vividcode.io/support-brackets-in-url-query-string-with-tomcat/ (2认同)

Bec*_*ang 6

Tomcat 8.0.39/8.5.9/7.0.73在HTTP请求行解析中添加对有效字符的附加检查.根据此要求,version 8.0.42/8.5.12/7.0.76进行一些更改以允许一些无效字符.
{,如果字符存在于系统属性的值中},|则允许使用 tomcat.util.http.parser.HttpParser.requestTargetAllow.

您可以添加系统属性tomcat.util.http.parser.HttpParser.requestTargetAllow={}以防止此错误.其中一个解决方案是编辑$CATALINA_HOME\conf\catalina.properties.

  • 在 tomcat 9.0.11 + tomcat.util.http.parser.HttpParser.requestTargetAllow 中不再使用。仅使用relaxedQueryChars。 (3认同)