Commit 7c49987e authored by Dave Cridland's avatar Dave Cridland

OF-777 CVE-2015-6973 CSRF protection (part 4)

parent d17904be
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
<%@ page import="org.jivesoftware.util.JiveGlobals, <%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.LocaleUtils, org.jivesoftware.util.LocaleUtils,
org.jivesoftware.util.Log, org.jivesoftware.util.Log,
org.jivesoftware.util.StringUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.ParamUtils" org.jivesoftware.util.ParamUtils"
%> %>
<%@ page import="java.util.HashMap"%> <%@ page import="java.util.HashMap"%>
...@@ -40,6 +42,18 @@ ...@@ -40,6 +42,18 @@
// TODO: We're not displaying this error ever. // TODO: We're not displaying this error ever.
Map<String,String> errors = new HashMap<String,String>(); Map<String,String> errors = new HashMap<String,String>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (save) { if (save) {
// Set the timezeone // Set the timezeone
try { try {
...@@ -90,6 +104,7 @@ ...@@ -90,6 +104,7 @@
<!-- BEGIN locale settings --> <!-- BEGIN locale settings -->
<form action="server-locale.jsp" method="post" name="sform"> <form action="server-locale.jsp" method="post" name="sform">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="locale.system.set" /> <fmt:message key="locale.system.set" />
</div> </div>
......
...@@ -72,6 +72,21 @@ ...@@ -72,6 +72,21 @@
return; return;
} }
Map<String, String> errors = new HashMap<String, String>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (encrypt || save || delete) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
encrypt = false;
save = false;
delete = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (delete) { if (delete) {
if (propName != null) { if (propName != null) {
JiveGlobals.deleteProperty(propName); JiveGlobals.deleteProperty(propName);
...@@ -82,7 +97,6 @@ ...@@ -82,7 +97,6 @@
} }
} }
Map<String, String> errors = new HashMap<String, String>();
if (save) { if (save) {
if (propName == null || "".equals(propName.trim()) || propName.startsWith("\"")) { if (propName == null || "".equals(propName.trim()) || propName.startsWith("\"")) {
errors.put("propName",""); errors.put("propName","");
...@@ -254,6 +268,7 @@ function dodelete(propName) { ...@@ -254,6 +268,7 @@ function dodelete(propName) {
</script> </script>
<form action="server-properties.jsp" method="post" name="propform"> <form action="server-properties.jsp" method="post" name="propform">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="edit" value=""> <input type="hidden" name="edit" value="">
<input type="hidden" name="encrypt" value=""> <input type="hidden" name="encrypt" value="">
<input type="hidden" name="del" value=""> <input type="hidden" name="del" value="">
...@@ -346,6 +361,7 @@ function dodelete(propName) { ...@@ -346,6 +361,7 @@ function dodelete(propName) {
<a name="edit"></a> <a name="edit"></a>
<form action="server-properties.jsp" method="post" name="editform"> <form action="server-properties.jsp" method="post" name="editform">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-table"> <div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
<%@ page import="org.jivesoftware.util.JiveGlobals, <%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.StringUtils,
org.jivesoftware.openfire.ConnectionManager, org.jivesoftware.openfire.ConnectionManager,
org.jivesoftware.openfire.XMPPServer, org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.JMXManager, org.jivesoftware.openfire.JMXManager,
...@@ -76,6 +78,18 @@ ...@@ -76,6 +78,18 @@
XMPPServer server = webManager.getXMPPServer(); XMPPServer server = webManager.getXMPPServer();
ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager(); ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager();
Map<String, String> errors = new HashMap<String, String>(); Map<String, String> errors = new HashMap<String, String>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (save) { if (save) {
if (serverName == null) { if (serverName == null) {
errors.put("serverName", ""); errors.put("serverName", "");
...@@ -206,6 +220,7 @@ ...@@ -206,6 +220,7 @@
<% } %> <% } %>
<form action="server-props.jsp" name="editform" method="post"> <form action="server-props.jsp" name="editform" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-table"> <div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
</td> </td>
<td width="1%" nowrap align="center" style="border-right:1px #ccc solid;"> <td width="1%" nowrap align="center" style="border-right:1px #ccc solid;">
<a href="server-session-summary.jsp?hostname=<%= URLEncoder.encode(host, "UTF-8") %>&close=true" <a href="server-session-summary.jsp?hostname=<%= URLEncoder.encode(host, "UTF-8") %>&close=true&csrf=${csrf}"
title="<fmt:message key="session.row.cliked_kill_session" />" title="<fmt:message key="session.row.cliked_kill_session" />"
onclick="return confirm('<fmt:message key="session.row.confirm_close" />');" onclick="return confirm('<fmt:message key="session.row.confirm_close" />');"
><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a> ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
org.jivesoftware.openfire.session.OutgoingServerSession, org.jivesoftware.openfire.session.OutgoingServerSession,
org.jivesoftware.openfire.session.Session, org.jivesoftware.openfire.session.Session,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils,
org.jivesoftware.util.CookieUtils,
java.util.*" java.util.*"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -41,6 +43,17 @@ ...@@ -41,6 +43,17 @@
boolean close = ParamUtils.getBooleanParameter(request,"close"); boolean close = ParamUtils.getBooleanParameter(request,"close");
String hostname = ParamUtils.getParameter(request,"hostname"); String hostname = ParamUtils.getParameter(request,"hostname");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (close) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
close = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (request.getParameter("range") != null) { if (request.getParameter("range") != null) {
webManager.setRowsPerPage("server-session-summary", range); webManager.setRowsPerPage("server-session-summary", range);
} }
......
...@@ -49,6 +49,18 @@ ...@@ -49,6 +49,18 @@
// Update the session kick policy if requested // Update the session kick policy if requested
Map<String,String> errors = new HashMap<String,String>(); Map<String,String> errors = new HashMap<String,String>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (update) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
update = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (update) { if (update) {
// Validate params // Validate params
if (kickPolicy != 0 && kickPolicy != 1 && kickPolicy != SessionManager.NEVER_KICK) { if (kickPolicy != 0 && kickPolicy != 1 && kickPolicy != SessionManager.NEVER_KICK) {
...@@ -93,6 +105,7 @@ ...@@ -93,6 +105,7 @@
<!-- BEGIN 'Set Conflict Policy' --> <!-- BEGIN 'Set Conflict Policy' -->
<form action="session-conflict.jsp" method="post"> <form action="session-conflict.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="session.conflict.policy" /> <fmt:message key="session.conflict.policy" />
</div> </div>
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
org.jivesoftware.util.JiveGlobals, org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils, org.jivesoftware.util.StringUtils,
org.jivesoftware.util.CookieUtils,
java.text.NumberFormat, java.text.NumberFormat,
java.util.Collection" java.util.Collection"
errorPage="error.jsp" errorPage="error.jsp"
...@@ -41,7 +42,15 @@ ...@@ -41,7 +42,15 @@
<% // Get parameters <% // Get parameters
String jid = ParamUtils.getParameter(request, "jid"); String jid = ParamUtils.getParameter(request, "jid");
// Handle a "go back" click: Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
// ATTN: No check here, because no actions.
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle a "go back" click:
if (request.getParameter("back") != null) { if (request.getParameter("back") != null) {
response.sendRedirect("session-summary.jsp"); response.sendRedirect("session-summary.jsp");
return; return;
...@@ -71,8 +80,10 @@ ...@@ -71,8 +80,10 @@
// Handle a "message" click: // Handle a "message" click:
if (request.getParameter("message") != null) { if (request.getParameter("message") != null) {
response.sendRedirect("user-message.jsp?username=" + URLEncoder.encode(user.getUsername(), "UTF-8")); if (csrfCookie != null && csrfParam != null && csrfCookie.getValue().equals(csrfParam)) {
return; response.sendRedirect("user-message.jsp?username=" + URLEncoder.encode(user.getUsername(), "UTF-8"));
return;
}
} }
// See if there are multiple sessions for this user: // See if there are multiple sessions for this user:
......
...@@ -178,7 +178,7 @@ ...@@ -178,7 +178,7 @@
</td> </td>
<td width="1%" nowrap align="center" style="border-right:1px #ccc solid;"> <td width="1%" nowrap align="center" style="border-right:1px #ccc solid;">
<a href="session-summary.jsp?jid=<%= URLEncoder.encode(sess.getAddress().toString(), "UTF-8") %>&close=true" <a href="session-summary.jsp?jid=<%= URLEncoder.encode(sess.getAddress().toString(), "UTF-8") %>&close=true&csrf=${csrf}"
title="<fmt:message key="session.row.cliked_kill_session" />" title="<fmt:message key="session.row.cliked_kill_session" />"
onclick="return confirm('<fmt:message key="session.row.confirm_close" />');" onclick="return confirm('<fmt:message key="session.row.confirm_close" />');"
><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a> ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
org.jivesoftware.openfire.session.ClientSession, org.jivesoftware.openfire.session.ClientSession,
org.jivesoftware.util.JiveGlobals, org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.StringUtils,
java.util.Collection" java.util.Collection"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -68,6 +70,17 @@ ...@@ -68,6 +70,17 @@
// Get the session count // Get the session count
int sessionCount = sessionManager.getUserSessionsCount(false); int sessionCount = sessionManager.getUserSessionsCount(false);
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (close) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
close = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Close a connection if requested // Close a connection if requested
if (close) { if (close) {
JID address = new JID(jid); JID address = new JID(jid);
......
<%@ page import="org.jivesoftware.util.cache.Cache"%> <%@ page import="org.jivesoftware.util.cache.Cache"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%> <%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.util.StringUtils"%> <%@ page import="org.jivesoftware.util.StringUtils"%>
<%@ page import="org.jivesoftware.util.CookieUtils"%>
<%@ page import="java.text.DecimalFormat"%> <%@ page import="java.text.DecimalFormat"%>
<%-- <%--
- $RCSfile$ - $RCSfile$
...@@ -108,6 +109,17 @@ ...@@ -108,6 +109,17 @@
// Get the list of existing caches // Get the list of existing caches
Cache[] caches = webManager.getCaches(); Cache[] caches = webManager.getCaches();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (doClearCache) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
doClearCache = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Clear one or multiple caches if requested. // Clear one or multiple caches if requested.
if (doClearCache) { if (doClearCache) {
for (int cacheID : cacheIDs) { for (int cacheID : cacheIDs) {
...@@ -152,6 +164,7 @@ ...@@ -152,6 +164,7 @@
%> %>
<form action="system-cache.jsp" method="post" name="cacheForm"> <form action="system-cache.jsp" method="post" name="cacheForm">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-table"> <div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
<%@ page import="org.jivesoftware.util.JiveGlobals" %> <%@ page import="org.jivesoftware.util.JiveGlobals" %>
<%@ page import="org.jivesoftware.util.Log" %> <%@ page import="org.jivesoftware.util.Log" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ page import="org.jivesoftware.util.cache.CacheFactory" %> <%@ page import="org.jivesoftware.util.cache.CacheFactory" %>
<%@ page import="java.text.DecimalFormat" %> <%@ page import="java.text.DecimalFormat" %>
<%@ page import="java.util.Arrays" %> <%@ page import="java.util.Arrays" %>
...@@ -60,6 +62,17 @@ ...@@ -60,6 +62,17 @@
boolean clusteringEnabled = ParamUtils.getBooleanParameter(request, "clusteringEnabled"); boolean clusteringEnabled = ParamUtils.getBooleanParameter(request, "clusteringEnabled");
boolean updateSucess = false; boolean updateSucess = false;
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (update) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
update = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (update) { if (update) {
if (!clusteringEnabled) { if (!clusteringEnabled) {
ClusterManager.setClusteringEnabled(false); ClusterManager.setClusteringEnabled(false);
...@@ -187,6 +200,7 @@ ...@@ -187,6 +200,7 @@
<!-- BEGIN 'Clustering Enabled' --> <!-- BEGIN 'Clustering Enabled' -->
<form action="system-clustering.jsp" method="post"> <form action="system-clustering.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="system.clustering.enabled.legend" /> <fmt:message key="system.clustering.enabled.legend" />
</div> </div>
......
...@@ -36,6 +36,17 @@ ...@@ -36,6 +36,17 @@
boolean test = request.getParameter("test") != null; boolean test = request.getParameter("test") != null;
boolean debug = ParamUtils.getBooleanParameter(request, "debug"); boolean debug = ParamUtils.getBooleanParameter(request, "debug");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle a test request // Handle a test request
if (test) { if (test) {
response.sendRedirect("system-emailtest.jsp"); response.sendRedirect("system-emailtest.jsp");
......
...@@ -53,6 +53,18 @@ ...@@ -53,6 +53,18 @@
// Validate input // Validate input
Map<String, String> errors = new HashMap<String, String>(); Map<String, String> errors = new HashMap<String, String>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (doTest) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
doTest = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (doTest) { if (doTest) {
if (from == null) { if (from == null) {
errors.put("from", ""); errors.put("from", "");
...@@ -215,6 +227,7 @@ function checkClick(el) { ...@@ -215,6 +227,7 @@ function checkClick(el) {
<% } %> <% } %>
<form action="system-emailtest.jsp" method="post" name="f" onsubmit="return checkClick(this);"> <form action="system-emailtest.jsp" method="post" name="f" onsubmit="return checkClick(this);">
<input type="hidden" name="csrf" value="${csrf}">
<table cellpadding="3" cellspacing="0" border="0"> <table cellpadding="3" cellspacing="0" border="0">
<tbody> <tbody>
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
<%@ page import="org.jivesoftware.util.Log"%> <%@ page import="org.jivesoftware.util.Log"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%> <%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.util.StringUtils"%> <%@ page import="org.jivesoftware.util.StringUtils"%>
<%@ page import="org.jivesoftware.util.CookieUtils"%>
<%@ page import="org.xmpp.packet.JID"%> <%@ page import="org.xmpp.packet.JID"%>
<%@ page import="org.xmpp.packet.Presence"%> <%@ page import="org.xmpp.packet.Presence"%>
<%@ page import="java.io.UnsupportedEncodingException"%> <%@ page import="java.io.UnsupportedEncodingException"%>
...@@ -53,7 +54,21 @@ ...@@ -53,7 +54,21 @@
boolean success = ParamUtils.getBooleanParameter(request,"updatesuccess"); boolean success = ParamUtils.getBooleanParameter(request,"updatesuccess");
String username = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "username")); String username = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "username"));
JID jid = webManager.getXMPPServer().createJID(username, null); JID jid = webManager.getXMPPServer().createJID(username, null);
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (add != null || delete != null) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
add = null;
delete = null;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if(add != null) { if(add != null) {
try { try {
Group group = webManager.getGroupManager().getGroup(add); Group group = webManager.getGroupManager().getGroup(add);
...@@ -191,7 +206,7 @@ ...@@ -191,7 +206,7 @@
%></td> %></td>
<td width="5%"><a <td width="5%"><a
href="user-groups.jsp?username=<%=URLEncoder.encode(user.getUsername(), "UTF-8")%>&delete=<%=groupName%>" href="user-groups.jsp?username=<%=URLEncoder.encode(user.getUsername(), "UTF-8")%>&delete=<%=groupName%>&csrf=${csrf}"
title="<fmt:message key="global.click_delete" />"><img title="<fmt:message key="global.click_delete" />"><img
src="images/delete-16x16.gif" width="16" height="16" border="0" src="images/delete-16x16.gif" width="16" height="16" border="0"
alt="<fmt:message key="global.click_delete" />"></a></td> alt="<fmt:message key="global.click_delete" />"></a></td>
...@@ -319,7 +334,7 @@ ...@@ -319,7 +334,7 @@
%></td> %></td>
<td width="5%"><a <td width="5%"><a
href="user-groups.jsp?username=<%=URLEncoder.encode(user.getUsername(), "UTF-8")%>&add=<%=groupName%>" href="user-groups.jsp?username=<%=URLEncoder.encode(user.getUsername(), "UTF-8")%>&add=<%=groupName%>&csrf=${csrf}"
title="<fmt:message key="global.click_add" />"> <img title="<fmt:message key="global.click_add" />"> <img
src="images/add-16x16.gif" width="16" height="16" border="0" src="images/add-16x16.gif" width="16" height="16" border="0"
alt="<fmt:message key="global.click_add" />"></a></td> alt="<fmt:message key="global.click_add" />"></a></td>
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<%@ page import="org.jivesoftware.util.ParamUtils, <%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils, org.jivesoftware.util.StringUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.openfire.SessionManager, org.jivesoftware.openfire.SessionManager,
org.jivesoftware.openfire.session.ClientSession, org.jivesoftware.openfire.session.ClientSession,
org.jivesoftware.openfire.user.User, org.jivesoftware.openfire.user.User,
...@@ -71,6 +72,18 @@ ...@@ -71,6 +72,18 @@
// Handle the request to send a message: // Handle the request to send a message:
Map<String,String> errors = new HashMap<String,String>(); Map<String,String> errors = new HashMap<String,String>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (send) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
send = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (send) { if (send) {
// Validate the message and jid // Validate the message and jid
if (jid == null && !sendToAll && user != null) { if (jid == null && !sendToAll && user != null) {
...@@ -169,6 +182,7 @@ function updateSelect(el) { ...@@ -169,6 +182,7 @@ function updateSelect(el) {
</script> </script>
<form action="user-message.jsp" method="post" name="f"> <form action="user-message.jsp" method="post" name="f">
<input type="hidden" name="csrf" value="${csrf}">
<% if(username != null){ %> <% if(username != null){ %>
<input type="hidden" name="username" value="<%= StringUtils.escapeForXML(username) %>"> <input type="hidden" name="username" value="<%= StringUtils.escapeForXML(username) %>">
<% } %> <% } %>
......
...@@ -50,6 +50,18 @@ ...@@ -50,6 +50,18 @@
response.sendRedirect("user-roster.jsp?username=" + URLEncoder.encode(username, "UTF-8")); response.sendRedirect("user-roster.jsp?username=" + URLEncoder.encode(username, "UTF-8"));
return; return;
} }
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (add) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
add = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle a request to create a user: // Handle a request to create a user:
if (add) { if (add) {
...@@ -155,6 +167,7 @@ ...@@ -155,6 +167,7 @@
<% } %> <% } %>
<form name="f" action="user-roster-add.jsp" method="get"> <form name="f" action="user-roster-add.jsp" method="get">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="username" value="<%= StringUtils.escapeForXML(username) %>"> <input type="hidden" name="username" value="<%= StringUtils.escapeForXML(username) %>">
......
...@@ -42,6 +42,17 @@ ...@@ -42,6 +42,17 @@
pageContext.setAttribute( "usernameUrlEncoded", usernameUrlEncoded); pageContext.setAttribute( "usernameUrlEncoded", usernameUrlEncoded);
pageContext.setAttribute( "jid", jid); pageContext.setAttribute( "jid", jid);
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (delete) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
delete = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle a cancel // Handle a cancel
if (cancel) { if (cancel) {
response.sendRedirect("user-roster.jsp?username=" + usernameUrlEncoded); response.sendRedirect("user-roster.jsp?username=" + usernameUrlEncoded);
...@@ -79,6 +90,7 @@ ...@@ -79,6 +90,7 @@
</p> </p>
<form action="user-roster-delete.jsp"> <form action="user-roster-delete.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="username" value="${usernameUrlEncoded}"> <input type="hidden" name="username" value="${usernameUrlEncoded}">
<input type="hidden" name="jid" value="${jid}"> <input type="hidden" name="jid" value="${jid}">
<input type="submit" name="delete" value="<fmt:message key="user.roster.delete.delete" />"> <input type="submit" name="delete" value="<fmt:message key="user.roster.delete.delete" />">
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
<%@ page import="org.jivesoftware.util.ParamUtils, <%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils, org.jivesoftware.util.StringUtils,
org.jivesoftware.util.CookieUtils,
java.net.URLEncoder" java.net.URLEncoder"
errorPage="error.jsp" errorPage="error.jsp"
%><%@ page import="org.xmpp.packet.JID"%> %><%@ page import="org.xmpp.packet.JID"%>
...@@ -54,6 +55,17 @@ ...@@ -54,6 +55,17 @@
// Load the roster item from the user's roster. // Load the roster item from the user's roster.
RosterItem item = roster.getRosterItem(new JID(jid)); RosterItem item = roster.getRosterItem(new JID(jid));
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle a roster item delete: // Handle a roster item delete:
if (save) { if (save) {
...@@ -91,6 +103,7 @@ ...@@ -91,6 +103,7 @@
</p> </p>
<form action="user-roster-edit.jsp"> <form action="user-roster-edit.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="username" value="<%= StringUtils.escapeForXML(username) %>"> <input type="hidden" name="username" value="<%= StringUtils.escapeForXML(username) %>">
<input type="hidden" name="jid" value="<%= StringUtils.escapeForXML(jid) %>"> <input type="hidden" name="jid" value="<%= StringUtils.escapeForXML(jid) %>">
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
<%@ page import="org.jivesoftware.util.ParamUtils, <%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils, org.jivesoftware.util.StringUtils,
org.jivesoftware.util.CookieUtils,
java.net.URLEncoder" java.net.URLEncoder"
errorPage="error.jsp" errorPage="error.jsp"
%><%@ page import="org.xmpp.packet.JID"%> %><%@ page import="org.xmpp.packet.JID"%>
...@@ -54,6 +55,17 @@ ...@@ -54,6 +55,17 @@
// Load the roster item from the user's roster. // Load the roster item from the user's roster.
RosterItem item = roster.getRosterItem(new JID(jid)); RosterItem item = roster.getRosterItem(new JID(jid));
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle a roster item delete: // Handle a roster item delete:
if (save) { if (save) {
List<String> groupList = new ArrayList<String>(); List<String> groupList = new ArrayList<String>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment