Tomcat에서 HTTP 메소드를 허용하지 않는 것은 대소 문자를 구분합니까?

PUT, DELETE 등을 허용하지 않으려 고 응용 프로그램의 web.xml에 다음을 입력했습니다.

 <security-constraint>
 <web-resource-collection>
  <web-resource-name>restricted methods</web-resource-name>
  <url-pattern>/*</url-pattern>
  <http-method>DELETE</http-method>
  <http-method>PUT</http-method>
  <http-method>SEARCH</http-method>
  <http-method>COPY</http-method>
  <http-method>MOVE</http-method>
  <http-method>PROPFIND</http-method>
  <http-method>PROPPATCH</http-method>
  <http-method>MKCOL</http-method>
  <http-method>LOCK</http-method>
  <http-method>UNLOCK</http-method>
  <http-method>delete</http-method>
  <http-method>put</http-method>
  <http-method>search</http-method>
  <http-method>copy</http-method>
  <http-method>move</http-method>
  <http-method>propfind</http-method>
  <http-method>proppatch</http-method>
  <http-method>mkcol</http-method>
  <http-method>lock</http-method>
  <http-method>unlock</http-method>
 </web-resource-collection>
 <auth-constraint />
 </security-constraint>

좋아, 지금 :

내가 방법으로 요청 DELETE하면 403을 다시 얻습니다.

내가 방법으로 요청 delete하면 403을 다시 얻습니다.

그러나

내가 방법으로 요청 DeLeTe하면 OK!

대소 문자를 구분하지 못하게하려면 어떻게해야합니까?

편집 : C # 프로그램으로 테스트하고 있습니다.

    private void button1_Click(object sender, EventArgs e)
    {
        textBox1.Text = "making request";
        System.Threading.Thread.Sleep(400);
        WebRequest req = WebRequest.Create("http://serverurl/Application/cache_test.jsp");
        req.Method = txtMethod.Text;
        try
        {
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            textBox1.Text = "Status: " + resp.StatusCode;

            if (resp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                WebHeaderCollection header = resp.Headers;
                using (System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream(), ASCIIEncoding.ASCII))
                {
                    //string responseText = reader.ReadToEnd();
                    textBox1.Text += "\r\n" + reader.ReadToEnd();
                }
            }
        }
        catch (Exception ex)
        {
            textBox1.Text = ex.Message;
        }
    }

txtMethod.Text메소드 이름을 입력하는 텍스트 상자입니다. 403이 있으면 catch 블록에서 예외가 발생합니다.

cache_test.jsp는 다음을 포함합니다.

<%
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma","no-cache");

out.print("Method used was: "+request.getMethod());
%>



답변

HTTP 표준과 관련하여 Tomcat의 잘못된 동작에 관계없이 블랙리스트가 아닌 특정 방법을 허용하려면 화이트리스트를 사용해야합니다.

예를 들어, 다음 방법을 제외한 모든 차단 허용 목록 대소 문자 GETHEAD.

<security-constraint>
    <web-resource-collection>
        <web-resource-name>restricted methods</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method-omission>GET</http-method-omission>
        <http-method-omission>HEAD</http-method-omission>
    </web-resource-collection>
    <auth-constraint />
</security-constraint>

(참고 : Tomcat 7 이상이 필요합니다. 이전 버전을 사용하는 사용자는 서블릿 필터와 같은 다른 솔루션을 조사해야합니다.)

심판


답변

글쎄, Server: Apache-CoyotteHTTP 응답에 헤더 서명이있는 임의의 임의 서버를 빠르게 테스트 한 후에 get / HTTP/1.1\r\nHost: <target_IP>\r\n\r\n는 400 HTTP 코드를 수신해야 할 때마다 간단한 netcat 연결 로 보내는 것이 옳은 것처럼 보입니다 .

예를 들면 다음과 같습니다.

$ { echo -en "get / HTTP/1.1\r\nHost: <target_IP>:8080\r\n\r\n" ; } | nc <target_IP> 8080

01:14:58.095547 IP 192.168.1.3.57245 > <target_IP>.8080: Flags [P.], seq 1:42, ack 1, win 115, options [nop,nop,TS val 4294788321 ecr 0], length 41
E..]C.@.@..Y......p.....A..v.......s.......
..D.....get / HTTP/1.1
Host: <target_IP>:8080

[...]

01:14:58.447946 IP <target_IP>.8080 > 192.168.1.3.57245: Flags [.], seq 1:1409, ack 43, win 65494, options [nop,nop,TS val 7981294 ecr 4294787971], length 1408
E...f...i.....p.............A..............
.y....C.HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Tue, 27 Jan 2015 00:15:14 GMT

나는 여기에 약간 충격을 받았다고 말해야하며 그러한 경우 그 행동이 모든 HTTP / 1.1 메소드로 확장되었다는 사실에 놀라지 않을 것입니다.

RFC 2616 (아래 참조)을 잘못 위반하여 잘못된 결과를 초래할 수 있으므로 버그 추적 도구 에서 버그 보고서를 작성 하고 적절한 메일 링리스트 로 메일을 보내야합니다 .

5.1.1 방법

  The Method  token indicates the method to be performed on the
  resource identified by the Request-URI. The method is case-sensitive.

      Method         = "OPTIONS"                ; Section 9.2
                     | "GET"                    ; Section 9.3
                     | "HEAD"                   ; Section 9.4
                     | "POST"                   ; Section 9.5
                     | "PUT"                    ; Section 9.6
                     | "DELETE"                 ; Section 9.7
                     | "TRACE"                  ; Section 9.8
                     | "CONNECT"                ; Section 9.9
                     | extension-method
      extension-method = token

답변