日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tomcat对URL合法字符的判断(RFC 7230 and RFC 3986 异常排查)

發布時間:2025/3/20 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tomcat对URL合法字符的判断(RFC 7230 and RFC 3986 异常排查) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

  • 起因

有一個數據上報接口,之前在物理機上部署,數據上報正常。

最近將項目遷移到 docker 中,結果出現了異常如下:

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 3986at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:192)at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1028)at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)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:745)
  • 問題原因

問題排查過程:略

原因:請求中出現了字符"{"(示例請求)

https://127.0.0.1:8080/metric?data=[{%22app

在不更改接口數據的前提下,解決方案為:在tomcat的cataline.properties追加配置

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

官方文檔鏈接:http://tomcat.apache.org/tomcat-8.0-doc/config/systemprops.html#Other

tomcat.util.http.parser.HttpParser. requestTargetAllow

A string comprised of characters the server should allow even when they are not encoded. These characters would normally result in a 400 status.

The acceptable characters for this property are:?|,?{?, and?}

WARNING: Use of this option will expose the server to CVE-2016-6816.

If not specified, the default value of?null?will be used.

  • 問題來源

那么為什么之前接口不會出現異常呢?是tomcat版本不同導致的。

查看源碼后發現:org.apache.tomcat.util.http.parser.HttpParser

tomcat 8.2.3 版本及 tomcat 7.0.82 ,都有如下代碼,讀取配置

String prop = System.getProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow"); if (prop != null) {for (int i = 0; i < prop.length(); i++) {char c = prop.charAt(i);if (c == '{' || c == '}' || c == '|') {REQUEST_TARGET_ALLOW[c] = true;} else {log.warn(sm.getString("httpparser.invalidRequestTargetCharacter",Character.valueOf(c)));}} }

而tomcat 8.0.14 版本中并沒有讀取配置,對 |?{?}?的處理,而是默認為合法字符。

static {// Setup the flag arraysfor (int i = 0; i < 128; i++) {if (i < 32) {isToken[i] = false;} else if (i == '(' || i == ')' || i == '<' || i == '>' || i == '@' ||i == ',' || i == ';' || i == ':' || i == '\\' || i == '\"' ||i == '/' || i == '[' || i == ']' || i == '?' || i == '=' ||i == '{' || i == '}' || i == ' ' || i == '\t') {isToken[i] = false;} else {isToken[i] = true;}if (i >= '0' && i <= '9' || i >= 'A' && i <= 'F' ||i >= 'a' && i <= 'f') {isHex[i] = true;} else {isHex[i] = false;}} }

雖然沒有進行全面的比對,但可以看出在 8.0.x 左右的一些版本中,tomcat.util.http.parser.HttpParser. requestTargetAllow?這個配置是沒有生效的,即? |?{?}?這3個符號認為是合法的。

  • 結論:
  • tomcat.util.http.parser.HttpParser. requestTargetAllow?這個字段可以解決URL中存在 |?{?}?字符的問題。
  • tomcat自tomcat 8.0.35版本之后對URL參數做了比較規范的限制,必須遵循RFC 7230 and RFC 3986規范,對于非保留字字符(json格式的請求參數)必須做轉義操作。
  • ?

    ?

    ?

    ?

    ?

    轉載于:https://my.oschina.net/pding/blog/1794176

    總結

    以上是生活随笔為你收集整理的tomcat对URL合法字符的判断(RFC 7230 and RFC 3986 异常排查)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。