Skip to content

Commit 6ddfcfd

Browse files
committed
Revert "HBASE-23303 Add default security headers if SSL is enabled (#4128)"
This reverts commit 87f8d9a.
1 parent a8ba838 commit 6ddfcfd

5 files changed

Lines changed: 16 additions & 35 deletions

File tree

hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,9 @@ private void initializeWebServer(String name, String hostName, Configuration con
639639
addGlobalFilter("clickjackingprevention", ClickjackingPreventionFilter.class.getName(),
640640
ClickjackingPreventionFilter.getDefaultParameters(conf));
641641

642-
HttpConfig httpConfig = new HttpConfig(conf);
643-
644-
addGlobalFilter("securityheaders", SecurityHeadersFilter.class.getName(),
645-
SecurityHeadersFilter.getDefaultParameters(conf, httpConfig.isSecure()));
642+
addGlobalFilter("securityheaders",
643+
SecurityHeadersFilter.class.getName(),
644+
SecurityHeadersFilter.getDefaultParameters(conf));
646645

647646
// But security needs to be enabled prior to adding the other servlets
648647
if (authenticationEnabled) {

hbase-http/src/main/java/org/apache/hadoop/hbase/http/SecurityHeadersFilter.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636

3737
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
3838
public class SecurityHeadersFilter implements Filter {
39-
private static final Logger LOG = LoggerFactory.getLogger(SecurityHeadersFilter.class);
40-
private static final String DEFAULT_HSTS = "max-age=63072000;includeSubDomains;preload";
41-
private static final String DEFAULT_CSP =
42-
"default-src https: data: 'unsafe-inline' 'unsafe-eval'";
39+
40+
private static final Logger LOG =
41+
LoggerFactory.getLogger(SecurityHeadersFilter.class);
42+
private static final String DEFAULT_HSTS = "";
43+
private static final String DEFAULT_CSP = "";
4344
private FilterConfig filterConfig;
4445

4546
@Override
@@ -69,10 +70,12 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
6970
public void destroy() {
7071
}
7172

72-
public static Map<String, String> getDefaultParameters(Configuration conf, boolean isSecure) {
73+
public static Map<String, String> getDefaultParameters(Configuration conf) {
7374
Map<String, String> params = new HashMap<>();
74-
params.put("hsts", conf.get("hbase.http.filter.hsts.value", isSecure ? DEFAULT_HSTS : ""));
75-
params.put("csp", conf.get("hbase.http.filter.csp.value", isSecure ? DEFAULT_CSP : ""));
75+
params.put("hsts", conf.get("hbase.http.filter.hsts.value",
76+
DEFAULT_HSTS));
77+
params.put("csp", conf.get("hbase.http.filter.csp.value",
78+
DEFAULT_CSP));
7679
return params;
7780
}
7881
}

hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestSSLHttpServer.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
import java.io.ByteArrayOutputStream;
2323
import java.io.File;
24-
import java.io.IOException;
2524
import java.io.InputStream;
2625
import java.net.URI;
2726
import java.net.URL;
28-
import java.security.GeneralSecurityException;
2927
import javax.net.ssl.HttpsURLConnection;
3028
import org.apache.hadoop.conf.Configuration;
3129
import org.apache.hadoop.fs.FileUtil;
@@ -73,7 +71,6 @@ public static void setup() throws Exception {
7371
serverConf = HTU.getConfiguration();
7472

7573
serverConf.setInt(HttpServer.HTTP_MAX_THREADS, TestHttpServer.MAX_THREADS);
76-
serverConf.setBoolean(ServerConfigurationKeys.HBASE_SSL_ENABLED_KEY, true);
7774

7875
keystoresDir = new File(HTU.getDataTestDir("keystore").toString());
7976
keystoresDir.mkdirs();
@@ -120,17 +117,6 @@ public void testEcho() throws Exception {
120117
assertEquals("a:b\nc&lt;:d\ne:&gt;\n", readOut(new URL(baseUrl, "/echo?a=b&c<=d&e=>")));
121118
}
122119

123-
@Test
124-
public void testSecurityHeaders() throws IOException, GeneralSecurityException {
125-
HttpsURLConnection conn = (HttpsURLConnection) baseUrl.openConnection();
126-
conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory());
127-
assertEquals(HttpsURLConnection.HTTP_OK, conn.getResponseCode());
128-
assertEquals("max-age=63072000;includeSubDomains;preload",
129-
conn.getHeaderField("Strict-Transport-Security"));
130-
assertEquals("default-src https: data: 'unsafe-inline' 'unsafe-eval'",
131-
conn.getHeaderField("Content-Security-Policy"));
132-
}
133-
134120
private static String readOut(URL url) throws Exception {
135121
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
136122
conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory());

hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ public synchronized void run() throws Exception {
288288
httpConfig.setSendDateHeader(false);
289289

290290
ServerConnector serverConnector;
291-
boolean isSecure = false;
292291
if (conf.getBoolean(REST_SSL_ENABLED, false)) {
293-
isSecure = true;
294292
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
295293
httpsConfig.addCustomizer(new SecureRequestCustomizer());
296294

@@ -377,8 +375,8 @@ public synchronized void run() throws Exception {
377375
ctxHandler.addFilter(filter, PATH_SPEC_ANY, EnumSet.of(DispatcherType.REQUEST));
378376
}
379377
addCSRFFilter(ctxHandler, conf);
380-
HttpServerUtil.addClickjackingPreventionFilter(ctxHandler, conf, PATH_SPEC_ANY);
381-
HttpServerUtil.addSecurityHeadersFilter(ctxHandler, conf, isSecure, PATH_SPEC_ANY);
378+
HttpServerUtil.addClickjackingPreventionFilter(ctxHandler, conf);
379+
HttpServerUtil.addSecurityHeadersFilter(ctxHandler, conf);
382380
HttpServerUtil.constrainHttpMethods(ctxHandler, servlet.getConfiguration()
383381
.getBoolean(REST_HTTP_ALLOW_OPTIONS_METHOD, REST_HTTP_ALLOW_OPTIONS_METHOD_DEFAULT));
384382

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestRESTServerSSL.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.security.KeyPair;
2525
import java.security.cert.X509Certificate;
2626
import java.util.Optional;
27+
2728
import org.apache.hadoop.conf.Configuration;
2829
import org.apache.hadoop.hbase.HBaseClassTestRule;
2930
import org.apache.hadoop.hbase.HBaseTestingUtil;
@@ -121,12 +122,6 @@ public void testSslConnection() throws Exception {
121122

122123
Response response = sslClient.get("/version", Constants.MIMETYPE_TEXT);
123124
assertEquals(200, response.getCode());
124-
125-
// Default security headers
126-
assertEquals("max-age=63072000;includeSubDomains;preload",
127-
response.getHeader("Strict-Transport-Security"));
128-
assertEquals("default-src https: data: 'unsafe-inline' 'unsafe-eval'",
129-
response.getHeader("Content-Security-Policy"));
130125
}
131126

132127
@Test(expected = org.apache.http.client.ClientProtocolException.class)

0 commit comments

Comments
 (0)