Remove the HTTP Server header in Jetty 9

前端 未结 7 1864
执念已碎
执念已碎 2020-12-30 01:36

This is how you hide the server version in Jetty 8:

Server server = new Server(port);
server.setSendServerVersion(false);

How do you do it

相关标签:
7条回答
  • 2020-12-30 01:39

    Some security analysis software will flag sending the server version in the response header as an issue.

    OP was looking for solution for embedded, but if your Jetty deployment uses the server.ini file, you can simply set jetty.send.server.version=false

    0 讨论(0)
  • 2020-12-30 01:40

    If you use jetty9 as a standalone server you can disable the server signature by setting jetty.httpConfig.sendServerVersion=false in the file start.ini.

    0 讨论(0)
  • 2020-12-30 01:41

    in jetty9.2, change this config to false in start.ini

    # should jetty send the server version header?
    jetty.send.server.version=true
    
    0 讨论(0)
  • 2020-12-30 01:49

    In Jetty 9, you need to configure it on HttpConfiguration:

    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSendServerVersion( false );
    HttpConnectionFactory httpFactory = new HttpConnectionFactory( httpConfig );
    ServerConnector httpConnector = new ServerConnector( server,httpFactory );
    server.setConnectors( new Connector[] { httpConnector } );
    
    0 讨论(0)
  • 2020-12-30 01:55

    Lambda-style variant of Jacob's solution (which worked for me):

    final Server server = new Server(port);
    Stream.of(server.getConnectors()).flatMap(connector -> connector.getConnectionFactories().stream())
                .filter(connFactory -> connFactory instanceof HttpConnectionFactory)
                .forEach(httpConnFactory -> ((HttpConnectionFactory)httpConnFactory).getHttpConfiguration().setSendServerVersion(false));
    
    0 讨论(0)
  • 2020-12-30 01:58

    If worked out some code that seems to work. Not sure if its right, but at least it works (:

    Server server = new Server(port);
    for(Connector y : server.getConnectors()) {
        for(ConnectionFactory x  : y.getConnectionFactories()) {
            if(x instanceof HttpConnectionFactory) {
                ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(false);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题