默认情况下,带有嵌入式 Tomcat 的 Spring Boot 应用程序的 HTTP“服务器”标头是:
Server → Apache-Coyote/1.1
怎么可以在春季启动可以实现使用另一个(自定义)“服务器”标头吗?
对于Tomcat本身,可以在<Connector>
XML 中的元素通过server
属性:
From https://tomcat.apache.org/tomcat-8.0-doc/security-howto.html#连接器 https://tomcat.apache.org/tomcat-8.0-doc/security-howto.html#Connectors :
服务器属性控制服务器 HTTP 标头的值。 Tomcat 4.1.x 到 8.0.x 的此标头的默认值为 Apache-Coyote/1.1。此标头可以向合法客户端和攻击者提供有限的信息。
但攻击者仍然会知道这是一个 Tomcat 服务器。
您可以设置自定义标头 http://docs.spring.io/spring-security/site/docs/current/reference/html/headers.html#headers-custom使用静态标头编写器 https://docs.spring.io/spring-security/site/docs/current-SNAPSHOT/apidocs/org/springframework/security/web/header/writers/StaticHeadersWriter.html在您的安全配置中,这是一个 Java 配置示例:
public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.headers()
.addHeaderWriter(new StaticHeadersWriter("Server","here to serve you"))
....
}
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)