通常HTTP的GET、POST方法比较常用。如果Tomcat允许PUT、DELETE、TRACK、OPTIONS等方法,一些安全监测软件会认为是允许HTTP危险方法,作为一种漏洞写在检测报告中。其实按照RESTful风格,恰恰需要使用这些方法。
可以修改tomcat/conf/web.xml(也可在项目的/WEB-INF/web.xml中修改),增加以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
...
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint></auth-constraint>
</security-constraint>
</web-app>