【问题标题】:How to Allow ^ character in URLs for tomcat 8.5如何在 tomcat 8.5 的 URL 中允许 ^ 字符
【发布时间】:2018-10-25 22:26:20
【问题描述】:

我有一个以下格式的请求 URL

http://hostname:port/path&param1={"vars":[{"a":"val1","b":"^"},{"c":"val2","d":"^"}]}&param2=Value3|95|3%20-%206%20Months

我按此更改了 catalina.properties stackoverflow question.

但根据tomcat documentation tomcat.util.http.parser.HttpParser.requestTargetAllow 属性已被弃用,relaxedPathCharsrelaxedQueryChars 属性已被弃用与连接器标签一起使用。

但是,当我将 xml 文件更改为以下时

 <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars="^" relaxedPathChars="^"/>

我仍然收到一个 400 错误的角色 ^

请求

我不确定这是否是正确的配置。

【问题讨论】:

    标签: tomcat8


    【解决方案1】:

    理想情况下,在将请求发送到服务器之前,您应该始终对查询参数进行 URL 编码。阅读:https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/

    如果您想使用 RelaxQueryChars 路线,请注意您的查询中的以下字符也在您应该添加到异常的集合中: " { } [ ] ^ |

    在你的 server.xml 中试试这个:

    &lt;Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars='^{}[]|&amp;quot;' /&gt;

    bug ticket 62273 上更深入地了解relaxedQueryChars/relaxedPathChars。更改已添加到 Tomat 的所有分支:

    • 9.0.8
    • 8.5.31
    • 8.0.52
    • 7.0.87

    我认为您根本不需要 RelaxPathChars 属性(这是指 URL 路径上的字符)。然而,the Tomcat team's test results 似乎暗示以下可用于最大程度的向后兼容性:

    relaxedPathChars='[]|' relaxedQueryChars='[]|{}^&#x5c;&#x60;&quot;&lt;&gt;' />

    nb/ 查询的第一个参数应该由 ?不是&

    http://hostname:port/path?param1=...&amp;param2=...&amp;param3=...

    【讨论】:

    • 感谢您的回答。尽管tomcat 8.5.31 在8.5.x 行中支持relaxQueryChars,但我已经弄清楚了。
    【解决方案2】:

    需要使用 unicode 而不是文字 &lt;&gt; 字符。这是我在server.xml 中的实际relaxedQueryChars 值:

    relaxedQueryChars="&#x5B;&#x5D;&#x7C;&#x7B;&#x7D;&#x5E;&#x5C;&#x60;&#x22;&#x3C;&#x3E;"
    &#x5B; -> [
    &#x5D; -> ]
    &#x7C; -> |
    &#x7B; -> {
    &#x7D; -> }
    &#x5E; -> ^
    &#x5C; -> \
    &#x60; -> `
    &#x22; -> "
    &#x3C; -> <
    &#x3E; -> >
    

    【讨论】:

    • 这仅在手动编辑 server.xml 时有效。任何读取和写入此文件的尝试都会损坏该文件。
    猜你喜欢
    • 1970-01-01
    • 2023-03-06
    • 2021-11-01
    • 1970-01-01
    • 2011-05-09
    • 2012-05-14
    • 1970-01-01
    • 2014-11-23
    • 2021-01-23
    相关资源
    最近更新 更多