Skip to content

Commit

Permalink
OF-834: Close Open_redirect
Browse files Browse the repository at this point in the history
This now reassembles a URL from the path, query, and fragment supplied, and
ignores the scheme and network location portions entirely.

Thus http://www.google.com/foo redirects to /foo only.

Credit to Jonathan Bush, Security Consultant at
ProCheckUp http://www.procheckup.com
  • Loading branch information
Dave Cridland committed Aug 4, 2014
1 parent fad60d8 commit 549dc1a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/web/login.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<%@ page import="java.util.Map" %>
<%@ page import="org.jivesoftware.util.*" %>
<%@ page import="org.jivesoftware.admin.LoginLimitManager" %>
<%@ page import="java.net.URL" %>
<%@ page import="java.lang.StringBuilder" %>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Expand All @@ -31,7 +33,29 @@
return "index.jsp";
}
else {
return url;
if (url.startsWith("/")) {
return url;
}
try {
URL u = new URL(url);
StringBuilder s = new StringBuilder();
if (u.getPath().equals("")) {
s.append("/");
} else {
s.append(u.getPath());
}
if (u.getQuery() != null) {
s.append('?');
s.append(u.getQuery());
}
if (u.getRef() != null) {
s.append('#');
s.append(u.getRef());
}
return s.toString();
} catch(Exception e) {
return "index.jsp";
}
}
}
%>
Expand Down

0 comments on commit 549dc1a

Please sign in to comment.