如何为Spring Boot应用程序设置自定义Http头“服务器”

前端之家收集整理的这篇文章主要介绍了如何为Spring Boot应用程序设置自定义Http头“服务器”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

默认情况下,嵌入式Tomcat的Spring Boot应用程序的HTTP“server”标头是:

@H_301_6@Server → Apache-Coyote/1.1

如何在Spring Boot中实现使用另一个(自定义)“服务器”标头?

对于Tomcat本身,可以在< Connector>处配置它. XML中的元素通过服务器属性

https://tomcat.apache.org/tomcat-8.0-doc/security-howto.html#Connectors开始:

The server attribute controls the value of the Server HTTP header. The default value of this header for Tomcat 4.1.x to 8.0.x is Apache-Coyote/1.1. This header can provide limited information to both legitimate clients and attackers.

但是攻击者仍然会知道这是一个Tomcat服务器.

最佳答案
您可以使用安全配置中的StaticHeadersWriter设置custom headers,这是一个Java配置示例:

@H_301_6@public class SecurityConfig extends WebSecurityConfigurerAdapter {
  protected void configure(HttpSecurity http) throws Exception {
    http
      .headers()
        .addHeaderWriter(new StaticHeadersWriter("Server","here to serve you"))
      ....
  }
  ...
}
原文链接:https://www.f2er.com/spring/431956.html

猜你在找的Spring相关文章