前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Tomcat特殊字符报400(The valid characters are defined in RFC 7230 and RFC 3986)

Tomcat特殊字符报400(The valid characters are defined in RFC 7230 and RFC 3986)

作者头像
日薪月亿
发布2019-05-14 14:41:10
3.4K0
发布2019-05-14 14:41:10
举报
文章被收录于专栏:技术探索技术探索

Tomcat在 7.0.73, 8.0.39, 8.5.7 等版本后(详情:https://stackoverflow.com/questions/41053653/tomcat-8-is-not-able-to-handle-get-request-with-in-query-parameters/44005213#44005213),添加了对于http头的验证,就是添加了些规则去限制HTTP头的规范性(详情:http://www.jianshu.com/p/1c870461fa41)

  • 报错信息如下: org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level. java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
  • 根据rfc规范(RFC 3986规范定义了Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符(RFC3986中指定了以下字符为保留字符:! * ’ ( ) ; : @ & = + $ , / ? # [ ]))。
  • url中不允许有 |,{,}等特殊字符,但在实际生产中还是有些url有可能携带有这些字符,特别是|还是较为常见的。在tomcat升级到7以后,对url字符的检查都变严格了,如果出现这类字符,tomcat将直接返回400状态码。
  • 修改tomcat的配置,在catalina.properties添加下面的配置,重启服务器即可。 tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
  • tomcat官方说明 http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html; https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html
  • 源码片段如下:

1234

if (IS_CONTROL[i] || i > 127 || i == ' ' || i == '\"' || i == '#' || i == '<' || i == '>' || i == '\\' || i == '^' || i == '`' || i == '{' || i == '|' || i == '}') { IS_NOT_REQUEST_TARGET[i] = true; // reject the character!

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-03-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档