Skip to content

Commit 174ac62

Browse files
authored
HIVE-28653: Jetty version disclosure in Hive (apache#5800)
1 parent d476a99 commit 174ac62

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

common/src/java/org/apache/hive/http/HttpServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ ServerConnector createAndAddChannelConnector(int queueSize, Builder b) {
652652

653653
final HttpConfiguration conf = new HttpConfiguration();
654654
conf.setRequestHeaderSize(1024*64);
655+
conf.setSendServerVersion(false);
656+
conf.setSendXPoweredBy(false);
655657
final HttpConnectionFactory http = new HttpConnectionFactory(conf);
656658

657659
if (!b.useSSL) {

hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ private Connector createChannelConnector(Server server) {
282282
ServerConnector connector;
283283
final HttpConfiguration httpConf = new HttpConfiguration();
284284
httpConf.setRequestHeaderSize(1024 * 64);
285+
httpConf.setSendServerVersion(false);
286+
httpConf.setSendXPoweredBy(false);
285287
final HttpConnectionFactory http = new HttpConnectionFactory(httpConf);
286288

287289
if (conf.getBoolean(AppConfig.USE_SSL, false)) {
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hive.service;
20+
21+
import org.apache.hadoop.hive.conf.HiveConf;
22+
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
23+
import org.apache.hc.client5.http.classic.methods.HttpGet;
24+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
25+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
26+
import org.apache.hc.client5.http.impl.classic.HttpClients;
27+
import org.apache.hc.core5.http.Header;
28+
import org.apache.hive.jdbc.miniHS2.MiniHS2;
29+
import org.junit.AfterClass;
30+
import org.junit.Assert;
31+
import org.junit.BeforeClass;
32+
import org.junit.Test;
33+
34+
import java.io.IOException;
35+
import java.util.HashMap;
36+
37+
public class TestHttpServices {
38+
39+
private static MiniHS2 miniHS2 = null;
40+
41+
@BeforeClass
42+
public static void startServices() throws Exception {
43+
HiveConf hiveConf = new HiveConf();
44+
hiveConf.set(MetastoreConf.ConfVars.THRIFT_TRANSPORT_MODE.toString(), "http"); // HS2 -> HMS thrift on http
45+
46+
miniHS2 = new MiniHS2.Builder()
47+
.withConf(hiveConf)
48+
.withHTTPTransport() // Cli service -> HS2 thrift on http
49+
.withRemoteMetastore()
50+
.build();
51+
52+
miniHS2.start(new HashMap<>());
53+
}
54+
55+
@AfterClass
56+
public static void stopServices() {
57+
if (miniHS2 != null && miniHS2.isStarted()) {
58+
miniHS2.stop();
59+
}
60+
}
61+
62+
@Test
63+
public void testWebUIResponseDoesNotContainServerVersionAndXPoweredBy() throws Exception {
64+
testHttpServiceDoesNotContainServerVersionAndXPoweredBy(
65+
"http://" + miniHS2.getHost() + ":" + miniHS2.getWebPort());
66+
}
67+
68+
@Test
69+
public void testCliServiceResponseDoesNotContainServerVersionAndXPoweredBy() throws Exception {
70+
testHttpServiceDoesNotContainServerVersionAndXPoweredBy(
71+
"http://" + miniHS2.getHost() + ":" + miniHS2.getWebPort() + "/cliservice");
72+
}
73+
74+
@Test
75+
public void testHMSServiceResponseDoesNotContainServerVersionAndXPoweredBy() throws Exception {
76+
testHttpServiceDoesNotContainServerVersionAndXPoweredBy(
77+
"http://" + miniHS2.getHost() + ":" + miniHS2.getWebPort() + "/" +
78+
MetastoreConf.ConfVars.METASTORE_CLIENT_THRIFT_HTTP_PATH.getDefaultVal());
79+
}
80+
81+
private void testHttpServiceDoesNotContainServerVersionAndXPoweredBy(String miniHS2) throws IOException {
82+
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
83+
HttpGet request = new HttpGet(miniHS2);
84+
85+
try (CloseableHttpResponse response = httpClient.execute(request)) {
86+
for (Header header : response.getHeaders()) {
87+
Assert.assertNotEquals("x-powered-by", header.getName().toLowerCase());
88+
Assert.assertNotEquals("server", header.getName().toLowerCase());
89+
}
90+
}
91+
}
92+
}
93+
}

service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ public void setThreadFactory(ThreadFactory threadFactory) {
123123
hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_RESPONSE_HEADER_SIZE);
124124
conf.setRequestHeaderSize(requestHeaderSize);
125125
conf.setResponseHeaderSize(responseHeaderSize);
126+
conf.setSendServerVersion(false);
127+
conf.setSendXPoweredBy(false);
126128
final HttpConnectionFactory http = new HttpConnectionFactory(conf) {
127129
public Connection newConnection(Connector connector, EndPoint endPoint) {
128130
Connection connection = super.newConnection(connector, endPoint);

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ public void setThreadFactory(ThreadFactory threadFactory) {
395395
MetastoreConf.getIntVar(conf, ConfVars.METASTORE_THRIFT_HTTP_REQUEST_HEADER_SIZE));
396396
httpServerConf.setResponseHeaderSize(
397397
MetastoreConf.getIntVar(conf, ConfVars.METASTORE_THRIFT_HTTP_RESPONSE_HEADER_SIZE));
398+
httpServerConf.setSendServerVersion(false);
399+
httpServerConf.setSendXPoweredBy(false);
398400

399401
final HttpConnectionFactory http = new HttpConnectionFactory(httpServerConf);
400402

0 commit comments

Comments
 (0)