You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bu...@apache.org on 2018/04/21 03:43:02 UTC
[3/3] hbase git commit: HBASE-20406 HBase Thrift HTTP - Shouldn't
handle TRACE/OPTIONS methods
HBASE-20406 HBase Thrift HTTP - Shouldn't handle TRACE/OPTIONS methods
Signed-off-by: Josh Elser <el...@apache.org>
Signed-off-by: Ted Yu <yu...@gmail.com>
Signed-off-by: Sean Busbey <bu...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/46cb5dfa
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/46cb5dfa
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/46cb5dfa
Branch: refs/heads/master
Commit: 46cb5dfa226892fd2580f26ce9ce77225bd7e67c
Parents: eb3f5b2
Author: Kevin Risden <kr...@apache.org>
Authored: Thu Apr 12 21:08:15 2018 -0500
Committer: Sean Busbey <bu...@apache.org>
Committed: Fri Apr 20 22:42:03 2018 -0500
----------------------------------------------------------------------
.../hadoop/hbase/http/TestHttpServer.java | 13 ++++++++++--
.../hadoop/hbase/thrift/ThriftServerRunner.java | 2 ++
.../hbase/thrift/TestThriftHttpServer.java | 21 ++++++++++++++++----
3 files changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/46cb5dfa/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServer.java
----------------------------------------------------------------------
diff --git a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServer.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServer.java
index 16350d5..10553da 100644
--- a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServer.java
+++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServer.java
@@ -605,8 +605,6 @@ public class TestHttpServer extends HttpServerFunctionalTest {
myServer.stop();
}
-
-
@Test
public void testNoCacheHeader() throws Exception {
URL url = new URL(baseUrl, "/echo?a=b&c=d");
@@ -619,4 +617,15 @@ public class TestHttpServer extends HttpServerFunctionalTest {
assertEquals(conn.getHeaderField("Expires"), conn.getHeaderField("Date"));
assertEquals("DENY", conn.getHeaderField("X-Frame-Options"));
}
+
+ @Test
+ public void testHttpMethods() throws Exception {
+ // HTTP TRACE method should be disabled for security
+ // See https://www.owasp.org/index.php/Cross_Site_Tracing
+ URL url = new URL(baseUrl, "/echo?a=b");
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestMethod("TRACE");
+ conn.connect();
+ assertEquals(HttpURLConnection.HTTP_FORBIDDEN, conn.getResponseCode());
+ }
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/46cb5dfa/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
----------------------------------------------------------------------
diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
index 39ea259..28ba28a 100644
--- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
+++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
@@ -79,6 +79,7 @@ import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.ParseFilter;
import org.apache.hadoop.hbase.filter.PrefixFilter;
import org.apache.hadoop.hbase.filter.WhileMatchFilter;
+import org.apache.hadoop.hbase.http.HttpServerUtil;
import org.apache.hadoop.hbase.log.HBaseMarkers;
import org.apache.hadoop.hbase.security.SaslUtil;
import org.apache.hadoop.hbase.security.SaslUtil.QualityOfProtection;
@@ -448,6 +449,7 @@ public class ThriftServerRunner implements Runnable {
ServletContextHandler ctxHandler = new ServletContextHandler(httpServer, "/",
ServletContextHandler.SESSIONS);
ctxHandler.addServlet(new ServletHolder(thriftHttpServlet), "/*");
+ HttpServerUtil.constrainHttpMethods(ctxHandler);
// set up Jetty and run the embedded server
HttpConfiguration httpConfig = new HttpConfiguration();
http://git-wip-us.apache.org/repos/asf/hbase/blob/46cb5dfa/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServer.java
----------------------------------------------------------------------
diff --git a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServer.java b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServer.java
index d583234..6117953 100644
--- a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServer.java
+++ b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftHttpServer.java
@@ -21,6 +21,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
@@ -38,6 +40,7 @@ import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransportException;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -171,8 +174,10 @@ public class TestThriftHttpServer {
Thread.sleep(100);
}
+ String url = "http://"+ HConstants.LOCALHOST + ":" + port;
try {
- talkToThriftServer(customHeaderSize);
+ checkHttpMethods(url);
+ talkToThriftServer(url, customHeaderSize);
} catch (Exception ex) {
clientSideException = ex;
} finally {
@@ -189,11 +194,19 @@ public class TestThriftHttpServer {
}
}
+ private void checkHttpMethods(String url) throws Exception {
+ // HTTP TRACE method should be disabled for security
+ // See https://www.owasp.org/index.php/Cross_Site_Tracing
+ HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
+ conn.setRequestMethod("TRACE");
+ conn.connect();
+ Assert.assertEquals(HttpURLConnection.HTTP_FORBIDDEN, conn.getResponseCode());
+ }
+
private static volatile boolean tableCreated = false;
- private void talkToThriftServer(int customHeaderSize) throws Exception {
- THttpClient httpClient = new THttpClient(
- "http://"+ HConstants.LOCALHOST + ":" + port);
+ private void talkToThriftServer(String url, int customHeaderSize) throws Exception {
+ THttpClient httpClient = new THttpClient(url);
httpClient.open();
if (customHeaderSize > 0) {