Skip to content

Commit ca5fa6a

Browse files
committed
HADOOP-6441. Protect web ui from cross site scripting attacks (XSS) on
the host http header and using encoded utf-7. (omalley) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@891132 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8e021d4 commit ca5fa6a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,9 @@ Release 0.21.0 - Unreleased
12221222
HADOOP-6375. Sync documentation for FsShell du with its implementation.
12231223
(Todd Lipcon via cdouglas)
12241224

1225+
HADOOP-6441. Protect web ui from cross site scripting attacks (XSS) on
1226+
the host http header and using encoded utf-7. (omalley)
1227+
12251228
Release 0.20.2 - Unreleased
12261229

12271230
NEW FEATURES

src/java/org/apache/hadoop/http/HttpServer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,25 @@ public Map<String, String[]> getParameterMap() {
624624
}
625625
return result;
626626
}
627+
628+
/**
629+
* Quote the url so that users specifying the HOST HTTP header
630+
* can't inject attacks.
631+
*/
632+
@Override
633+
public StringBuffer getRequestURL(){
634+
String url = rawRequest.getRequestURL().toString();
635+
return new StringBuffer(HtmlQuoting.quoteHtmlChars(url));
636+
}
637+
638+
/**
639+
* Quote the server name so that users specifying the HOST HTTP header
640+
* can't inject attacks.
641+
*/
642+
@Override
643+
public String getServerName() {
644+
return HtmlQuoting.quoteHtmlChars(rawRequest.getServerName());
645+
}
627646
}
628647

629648
@Override
@@ -641,6 +660,10 @@ public void doFilter(ServletRequest request,
641660
) throws IOException, ServletException {
642661
HttpServletRequestWrapper quoted =
643662
new RequestQuoter((HttpServletRequest) request);
663+
final HttpServletResponse httpResponse = (HttpServletResponse) response;
664+
// set the default to UTF-8 so that we don't need to worry about IE7
665+
// choosing to interpret the special characters as UTF-7
666+
httpResponse.setContentType("text/html;charset=utf-8");
644667
chain.doFilter(quoted, response);
645668
}
646669

0 commit comments

Comments
 (0)