This is an automated email from the ASF dual-hosted git repository.
liuml07 pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new e32e138 HDFS-15320. StringIndexOutOfBoundsException in
HostRestrictingAuthorizationFilter (#1992)
e32e138 is described below
commit e32e1384d961078e520870c30725c461c0b9233c
Author: Akira Ajisaka <[email protected]>
AuthorDate: Sun May 3 05:02:27 2020 +0900
HDFS-15320. StringIndexOutOfBoundsException in
HostRestrictingAuthorizationFilter (#1992)
Signed-off-by: Mingliang Liu <[email protected]>
---
.../common/HostRestrictingAuthorizationFilter.java | 11 +++++++---
.../TestHostRestrictingAuthorizationFilter.java | 25 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HostRestrictingAuthorizationFilter.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HostRestrictingAuthorizationFilter.java
index 1a51b46..e9f1cf0 100644
---
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HostRestrictingAuthorizationFilter.java
+++
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HostRestrictingAuthorizationFilter.java
@@ -229,9 +229,14 @@ public class HostRestrictingAuthorizationFilter implements
Filter {
throws IOException, ServletException {
final String address = interaction.getRemoteAddr();
final String query = interaction.getQueryString();
- final String path =
- interaction.getRequestURI()
- .substring(WebHdfsFileSystem.PATH_PREFIX.length());
+ final String uri = interaction.getRequestURI();
+ if (!uri.startsWith(WebHdfsFileSystem.PATH_PREFIX)) {
+ LOG.trace("Rejecting interaction; wrong URI: {}", uri);
+ interaction.sendError(HttpServletResponse.SC_NOT_FOUND,
+ "The request URI must start with " + WebHdfsFileSystem.PATH_PREFIX);
+ return;
+ }
+ final String path = uri.substring(WebHdfsFileSystem.PATH_PREFIX.length());
String user = interaction.getRemoteUser();
LOG.trace("Got request user: {}, remoteIp: {}, query: {}, path: {}",
diff --git
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/TestHostRestrictingAuthorizationFilter.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/TestHostRestrictingAuthorizationFilter.java
index bd78a50..34bc616 100644
---
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/TestHostRestrictingAuthorizationFilter.java
+++
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/TestHostRestrictingAuthorizationFilter.java
@@ -243,6 +243,31 @@ public class TestHostRestrictingAuthorizationFilter {
filter.destroy();
}
+ /**
+ * Test acceptable behavior to malformed requests
+ * Case: the request URI does not start with "/webhdfs/v1"
+ */
+ @Test
+ public void testInvalidURI() throws Exception {
+ HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(request.getMethod()).thenReturn("GET");
+ Mockito.when(request.getRequestURI()).thenReturn("/InvalidURI");
+ HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+
+ Filter filter = new HostRestrictingAuthorizationFilter();
+ HashMap<String, String> configs = new HashMap<String, String>() {};
+ configs.put(AuthenticationFilter.AUTH_TYPE, "simple");
+ FilterConfig fc = new DummyFilterConfig(configs);
+
+ filter.init(fc);
+ filter.doFilter(request, response,
+ (servletRequest, servletResponse) -> {});
+ Mockito.verify(response, Mockito.times(1))
+ .sendError(Mockito.eq(HttpServletResponse.SC_NOT_FOUND),
+ Mockito.anyString());
+ filter.destroy();
+ }
+
private static class DummyFilterConfig implements FilterConfig {
final Map<String, String> map;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]