如何在 tomcat 8.5 的 URL 中允许 ^ 字符
How to Allow ^ character in URLs for tomcat 8.5
我有一个请求URL,格式如下
http://hostname:port/path¶m1={"vars":[{"a":"val1","b":"^"},{"c":"val2","d":"^"}]}¶m2=Value3|95|3%20-%206%20Months
我按照这个修改了catalina.properties
.
但根据 tomcat documentation tomcat.util.http.parser.HttpParser.requestTargetAllow 属性 已弃用并且 relaxedPathChars 和 relaxedQueryChars 属性将与 Connector 标签一起使用。
但是,当我将 xml 文件更改为以下
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars="^" relaxedPathChars="^"/>
我仍然收到一个 400 错误的字符请求 ^
我不确定这是否是正确的配置。
理想情况下,您应该始终在将请求发送到服务器之前对查询参数进行 URL 编码。阅读:https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/
如果您想沿着 relaxedQueryChars 路线走下去,请注意您查询中的以下字符也在您应该添加到例外的集合中:
" { } [ ] ^ |
在您的 server.xml 中试试这个:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars='^{}[]|"' />
在 bug ticket 62273 上更深入地了解 relaxedQueryChars/relaxedPathChars。更改已添加到 Tomat 的所有分支:
- 9.0.8
- 8.5.31
- 8.0.52
- 7.0.87
我认为您根本不需要 relaxedPathChars 属性(这是指 URL 路径上的字符)。但是,the Tomcat team's test results 似乎表明以下内容可用于最大程度的向后兼容性:
relaxedPathChars='[]|'
relaxedQueryChars='[]|{}^\`"<>' />
nb/ 您查询的第一个参数应该用 ?不是 &
http://hostname:port/path?param1=...¶m2=...¶m3=...
需要使用 unicode 而不是文字 <
或 >
字符。这是我在 server.xml
:
中的实际 relaxedQueryChars
值
relaxedQueryChars="[]|{}^\`"<>"
[ -> [
] -> ]
| -> |
{ -> {
} -> }
^ -> ^
\ -> \
` -> `
" -> "
< -> <
> -> >
我有一个请求URL,格式如下
http://hostname:port/path¶m1={"vars":[{"a":"val1","b":"^"},{"c":"val2","d":"^"}]}¶m2=Value3|95|3%20-%206%20Months
我按照这个修改了catalina.properties
但根据 tomcat documentation tomcat.util.http.parser.HttpParser.requestTargetAllow 属性 已弃用并且 relaxedPathChars 和 relaxedQueryChars 属性将与 Connector 标签一起使用。
但是,当我将 xml 文件更改为以下
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars="^" relaxedPathChars="^"/>
我仍然收到一个 400 错误的字符请求 ^
我不确定这是否是正确的配置。
理想情况下,您应该始终在将请求发送到服务器之前对查询参数进行 URL 编码。阅读:https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/
如果您想沿着 relaxedQueryChars 路线走下去,请注意您查询中的以下字符也在您应该添加到例外的集合中:
" { } [ ] ^ |
在您的 server.xml 中试试这个:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars='^{}[]|"' />
在 bug ticket 62273 上更深入地了解 relaxedQueryChars/relaxedPathChars。更改已添加到 Tomat 的所有分支:
- 9.0.8
- 8.5.31
- 8.0.52
- 7.0.87
我认为您根本不需要 relaxedPathChars 属性(这是指 URL 路径上的字符)。但是,the Tomcat team's test results 似乎表明以下内容可用于最大程度的向后兼容性:
relaxedPathChars='[]|'
relaxedQueryChars='[]|{}^\`"<>' />
nb/ 您查询的第一个参数应该用 ?不是 &
http://hostname:port/path?param1=...¶m2=...¶m3=...
需要使用 unicode 而不是文字 <
或 >
字符。这是我在 server.xml
:
relaxedQueryChars
值
relaxedQueryChars="[]|{}^\`"<>"
[ -> [
] -> ]
| -> |
{ -> {
} -> }
^ -> ^
\ -> \
` -> `
" -> "
< -> <
> -> >