在Apache Tomcat 6.0中禁用PUT TRACE DELETE请求

问题描述 投票:10回答:2

我需要在我的Application Server,Apache Tomcat 6.0上禁用PUT,DELETE和TRACE HTTP请求。

所有其他来源,我已经搜索到现在,已经指示我走向httpd.conf中的limit参数,因此我事先说明我没有使用Apache Web Server,并且请求直接由Tomcat处理,并且所以图片中没有httpd.conf。

请建议我如何在Tomcat上进行操作?

http tomcat application-server security-constraint
2个回答
19
投票

在您的WEB INF中,添加您可以添加安全约束:

<security-constraint>
     <web-resource-collection>
          <web-resource-name>Forbidden</web-resource-name>
          <url-pattern>/blah/*</url-pattern>
          <http-method>PUT</http-method>
          <http-method>DELETE</http-method>
          <http-method>TRACE</http-method>
     </web-resource-collection>
     <auth-constraint>
          <role-name>empty_role</role-name>
     </auth-constraint>
</security-constraint>

或者,您可以执行以下两项操作:

在server.xml中,编辑<connector>元素,添加一个属性:allowTrace="false"。然后编辑DefaultServlet:$ CATALINA_HOME / conf / web.xml

<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>
        org.apache.catalina.servlets.DefaultServlet
    </servlet-class>
    <!-- blah blah blah -->
    <init-param>
        <param-name>readonly</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>

0
投票

答案在于servlet规范。在查看servlet的API:http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/http/HttpServlet.html时,您会看到不同的方法处理不同类型的HTTP请求。此外,还有一个称为过滤器的强大功能,可用于围绕servlet和过滤器包装一些代码。

所以解决方案是:

  • 修改servlet只支持do和get;要么
  • 创建过滤器以清除其他类型的请求。
© www.soinside.com 2019 - 2024. All rights reserved.