小编典典

Tomcat安全约束TRACE不一致

tomcat

我正在使用web.xml尝试禁用未使用的HTTP方法,并返回不包含任何tomcat信息的正文。

因此,我将应用程序的web.xml更改为:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>restricted methods</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>TRACE</http-method>
        <http-method>PUT</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>DELETE</http-method>
        <http-method>HEAD</http-method>
    </web-resource-collection>
    <auth-constraint />
</security-constraint>

因此,禁止的方法将返回带有空主体的403,这是禁止的。但是TRACE会返回带有Tomcat HTML页面的405。

我尝试通过ErrorServlet使用以下命令重定向所有错误:

<error-page>
    <location>/ErrorServlet</location>
</error-page>

这只是确保内容主体为0。但这似乎并未拦截这些内容。

那么为什么TRACE会被区别对待?

谢谢


阅读 267

收藏
2020-06-16

共1个答案

小编典典

这对我来说很有意义,因为在所有情况下,除TRACE之外,您都在提交对由URL和代码403标识的Web资源的请求,这意味着拒绝对该资源的访问。尝试使用允许的方法来访问相同的资源。可能也禁止他们吗?

另一方面,TRACE不需要访问任何资源,它只是回显客户端的输入,因此405(“不允许使用方法”)看起来适合这种情况。

拥有自定义错误页面是一个好主意。每种错误代码的特定示例可以在以下位置找到:https : //serverfault.com/questions/254102/custom-
error-pages-on-apache-tomcat

2020-06-16