Nice programing

Tomcat 8은 '|'로 요청 받기를 처리 할 수 ​​없습니다.

nicepro 2021. 1. 5. 21:09
반응형

Tomcat 8은 '|'로 요청 받기를 처리 할 수 ​​없습니다. 쿼리 매개 변수에서?


Tomcat 8을 사용하고 있습니다. 한 경우에는 요청에으로 구분 된 매개 변수가있는 외부 소스에서 오는 외부 요청을 처리해야합니다 |.

요청은 다음과 같습니다.

http://localhost:8080/app/handleResponse?msg=name|id|

이 경우 다음과 같은 오류가 발생합니다.

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.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:667)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    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)

편집 1

Apache Tomcat 8.0.30에서는 작동하지만 Tomcat 8.5에서는 작동하지 않습니다.


이 동작은 모든 주요 Tomcat 릴리스에 도입되었습니다.

  • 톰캣 7.0.73 , 8.0.39 , 8.5.7

수정하려면 다음 중 하나를 수행하십시오.

  • relaxedQueryChars이 문자를 허용하도록 설정 (권장, Lincoln의 답변 참조 )
  • set requestTargetAllow옵션 (Tomcat 8.5에서 더 이상 사용되지 않음) ( Jérémie의 답변 참조 ).
  • 이전 버전 중 하나로 다운 그레이드 할 수 있습니다 (권장하지 않음-보안).

changelog를 기반으로 이러한 변경 사항은이 동작에 영향을 미칠 수 있습니다.

Tomcat 8.5.3 :

토큰이 아닌 HTTP 메서드 이름이있는 요청 (RFC 7231에서 요구됨)이 400 응답으로 거부되는지 확인합니다.

Tomcat 8.5.7 :

HTTP 요청 줄 구문 분석에 유효한 문자에 대한 추가 검사를 추가하여 잘못된 요청 줄이 더 빨리 거부되도록합니다.


최상의 옵션 (표준에 따름) -클라이언트에서 URL을 인코딩하려는 경우 :

encodeURI("http://localhost:8080/app/handleResponse?msg=name|id|")
> http://localhost:8080/app/handleResponse?msg=name%7Cid%7C

또는 쿼리 문자열 :

encodeURIComponent("msg=name|id|")
> msg%3Dname%7Cid%7C

다른 문제가있는 문자 ( 잘못된 URI 문자 목록) 로부터 사용자를 보호합니다 .


Tomcat 7.0.76 , 8.0.42 , 8.5.12 이후로 속성 requestTargetAllow정의 하여 문자를 허용 할 수 있습니다 .

이 줄을 catalina.properties

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

이 매개 변수 tomcat.util.http.parser.HttpParser.requestTargetAllow는 Tomcat 8.5 : tomcat official doc 이후 더 이상 사용되지 않습니다 .

relaxedQueryChars / relaxedPathChars다음 문자를 허용하기 위해 커넥터 정의에서 사용할 수 있습니다 : tomcat official doc .


문제 : Tomcat (7.0.88)에서 400 – 잘못된 요청으로 이어지는 예외가 발생합니다.

java.lang.IllegalArgumentException: Invalid character found in the request target. 
The valid characters are defined in RFC 7230 and RFC 3986.

이 문제는 7.0.88 이후 대부분의 tomcat 버전에서 발생합니다.

솔루션 : (Apache 팀에서 제안) :

Tomcat은 보안을 강화했으며 더 이상 쿼리 문자열에 원시 대괄호를 허용하지 않습니다. 요청에는 [,] (대괄호)가 있으므로 요청이 서버에서 처리되지 않습니다.

relaxedQueryCharsserver.xml (% TOMCAT_HOME % / conf) 아래의 태그 아래에 속성을 추가 합니다.

<Connector port="80" 
           protocol="HTTP/1.1"
           maxThreads="150"
           connectionTimeout="20000"
           redirectPort="443"
           compression="on"
           compressionMinSize="2048"
           noCompressionUserAgents="gozilla, traviata"
           compressableMimeType="text/html,text/xml"
                                     relaxedQueryChars="[,]"
             />

If application needs more special characters that are not supported by tomcat by default, then add those special characters in relaxedQueryChars attribute, comma-separated as above.


The URI is encoded as UTF-8, but Tomcat is decoding them as ISO-8859-1. You need to edit the connector settings in the server.xml and add the URIEncoding="UTF-8" attribute.

or edit this parameter on your application.properties

server.tomcat.uri-encoding=utf-8


Escape it. The pipe symbol is one that has been handled differently over time and between browsers. For instance, Chrome and Firefox convert a URL with pipe differently when copy/paste them. However, the most compatible, and necessary with Tomcat 8.5 it seems, is to escape it:

http://localhost:8080/app/handleResponse?msg=name%7Cid%7C

ReferenceURL : https://stackoverflow.com/questions/41053653/tomcat-8-is-not-able-to-handle-get-request-with-in-query-parameters

반응형