Skip to content

Commit 85422bb

Browse files
author
Karthik Kambatla
committed
HADOOP-13299. JMXJsonServlet is vulnerable to TRACE. (Haibo Chen via kasha)
1 parent 0f701f4 commit 85422bb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/jmx/JMXJsonServlet.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,16 @@ protected boolean isInstrumentationAccessAllowed(HttpServletRequest request,
147147
return HttpServer2.isInstrumentationAccessAllowed(getServletContext(),
148148
request, response);
149149
}
150-
150+
151+
/**
152+
* Disable TRACE method to avoid TRACE vulnerability.
153+
*/
154+
@Override
155+
protected void doTrace(HttpServletRequest req, HttpServletResponse resp)
156+
throws ServletException, IOException {
157+
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
158+
}
159+
151160
/**
152161
* Process a GET request for the specified resource.
153162
*

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/jmx/TestJMXJsonServlet.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.junit.BeforeClass;
2525
import org.junit.Test;
2626

27+
import javax.servlet.http.HttpServletResponse;
28+
import java.io.IOException;
2729
import java.net.HttpURLConnection;
2830
import java.net.URL;
2931
import java.util.regex.Matcher;
@@ -81,4 +83,15 @@ public static void assertReFind(String re, String value) {
8183
assertEquals("GET", conn.getHeaderField(ACCESS_CONTROL_ALLOW_METHODS));
8284
assertNotNull(conn.getHeaderField(ACCESS_CONTROL_ALLOW_ORIGIN));
8385
}
86+
87+
@Test
88+
public void testTraceRequest() throws IOException {
89+
URL url = new URL(baseUrl, "/jmx");
90+
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
91+
conn.setRequestMethod("TRACE");
92+
93+
assertEquals("Unexpected response code",
94+
HttpServletResponse.SC_METHOD_NOT_ALLOWED, conn.getResponseCode());
95+
}
96+
8497
}

0 commit comments

Comments
 (0)