删除服务器头tomcat

问题描述 投票:14回答:4

我能够将org.apache.coyote.http11.Http11Protocol.SERVER的值重命名为其他任何内容,因此HTTP-Response-Header包含以下内容:

服务器:Apache

而不是默认值

服务器:Apache-狼/ 1.1

使用org.apache.coyote.http11.Http11Protocol.SERVER的空值不会删除Server-Header。

如何从响应中删除Server-Header?

http-headers tomcat7
4个回答
5
投票

简短回答 - 您无法删除标题,但您应该修改它(请参阅其他答案)。

服务器头在RFC中定义,并且是必需的。 (未在规范中定义为可选)

取自http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.38

14.38服务器 Server response-header字段包含有关源服务器用于处理请求的软件的信息。 该字段可以包含多个产品令牌(第3.8节)以及标识服务器和任何重要子产品的注释。产品令牌按其对于识别应用程序的重要性的顺序列出。

如果响应是通过代理转发的,则代理应用程序不得修改Server响应头。相反,它应该包括一个Via字段(如第14.45节所述)。

  Note: Revealing the specific software version of the server might
  allow the server machine to become more vulnerable to attacks
  against software that is known to contain security holes. Server
  implementors are encouraged to make this field a configurable
  option.

6
投票

您可以修改tomcat server.xml并添加“server”选项并将其设置为您想要的任何内容。应为您运行的任何http或ssl连接器设置服务器选项。例如,下面是示例server.xml文件中的HTTP连接器配置示例

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" enableLookups="false" xpoweredby="false" server="Web"/>

5
投票

从Tomcat 5.5开始应该是可能的。看看这个讨论:https://mail-archives.apache.org/mod_mbox/tomcat-users/200508.mbox/%[email protected]%3E和这个链接:https://tomcat.apache.org/tomcat-4.1-doc/config/coyote.html

因此,以下应将服务器头设置为TEST。空应该使其为空。

<Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8180" inProcessors="5" maxProcessors="75" enableLookups="true" acceptCount="10" debug="0" connectionTimeout="20000" useURIValidationHack="false" server="TEST"/>

在大多数情况下,将Server标头设置为Apache在安全方面应该足够好。仅此而言,无法推断出哪个操作系统或哪个模块以及运行的模块版本的确切版本。


0
投票

如果你使用嵌入式tomcat,那么你可以尝试下面的代码。

import org.apache.catalina.startup.Tomcat;

final Tomcat server = new Tomcat();
server.getConnector().setXpoweredBy(false);
server.getConnector().setAttribute("server", "");
© www.soinside.com 2019 - 2024. All rights reserved.