Commit 38afc3ca authored by Dave Cridland's avatar Dave Cridland Committed by Guus der Kinderen

OF-777 Close off CSRF issues

Note that audit-policy *is* covered, though appears not to be.

Several of these will re-present the form without processing now.
parent b91f85c9
<%@ page import="org.jivesoftware.openfire.plugin.spark.manager.FileTransferFilterManager" %> <%@ page import="org.jivesoftware.openfire.plugin.spark.manager.FileTransferFilterManager" %>
<%@ page import="org.jivesoftware.util.JiveGlobals"%> <%@ page import="org.jivesoftware.util.JiveGlobals"%>
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ page import="org.jivesoftware.openfire.plugin.ClientControlPlugin" %> <%@ page import="org.jivesoftware.openfire.plugin.ClientControlPlugin" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...@@ -34,7 +37,17 @@ ...@@ -34,7 +37,17 @@
String viewtasklistEnabledString = JiveGlobals.getProperty("viewtasklist.enabled", "true"); String viewtasklistEnabledString = JiveGlobals.getProperty("viewtasklist.enabled", "true");
boolean submit = request.getParameter("submit") != null; boolean submit = request.getParameter("submit") != null;
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
submit = false;
}
csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (submit) { if (submit) {
accountsEnabledString = request.getParameter("accountsEnabled"); accountsEnabledString = request.getParameter("accountsEnabled");
addcontactsEnabledString = request.getParameter("addcontactsEnabled"); addcontactsEnabledString = request.getParameter("addcontactsEnabled");
...@@ -149,6 +162,7 @@ ...@@ -149,6 +162,7 @@
</p> </p>
<form name="f" action="client-features.jsp" method="post"> <form name="f" action="client-features.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<div style="display:inline-block;width:600px;margin:10px;"> <div style="display:inline-block;width:600px;margin:10px;">
<table class="jive-table" cellspacing="0" width="600" > <table class="jive-table" cellspacing="0" width="600" >
<th><fmt:message key="client.feature"/></th> <th><fmt:message key="client.feature"/></th>
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
<%@ page import="java.util.ArrayList" %> <%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %> <%@ page import="java.util.List" %>
<%@ page import="java.util.StringTokenizer" %> <%@ page import="java.util.StringTokenizer" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ page import="org.jivesoftware.openfire.plugin.ClientControlPlugin" %> <%@ page import="org.jivesoftware.openfire.plugin.ClientControlPlugin" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...@@ -73,6 +76,20 @@ ...@@ -73,6 +76,20 @@
boolean submit = request.getParameter("submit") != null; boolean submit = request.getParameter("submit") != null;
boolean addOther = request.getParameter("addOther") != null; boolean addOther = request.getParameter("addOther") != null;
boolean remove = request.getParameter("removeClient") != null; boolean remove = request.getParameter("removeClient") != null;
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (submit || addOther || remove) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
submit = false;
addOther = false;
remove = false;
}
}
csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (submit) { if (submit) {
String[] cls = request.getParameterValues("client"); String[] cls = request.getParameterValues("client");
...@@ -267,7 +284,7 @@ ...@@ -267,7 +284,7 @@
<td valign="top" nowrap> <td valign="top" nowrap>
<div style="display: block; width: 205px;"> <div style="display: block; width: 205px;">
<% } %> <% } %>
<label for="<%= client.getName() %>"><input type="checkbox" name="client" value="<%= client.getName() %>" id="<%= client.getName() %>" <%= clients.contains(client.getName()) ? "checked" : ""%> /> <img src="<%= client.getImage() %>" width="16" height="16" border="0" alt=""> <strong><%= client.getName() %></strong></label><span>(<a href="<%= client.getURL() %>" target="_blank"><fmt:message key="permitted.client.website"/></a>)</span><br> <label for="<%= StringUtils.escapeForXML(client.getName()) %>"><input type="checkbox" name="client" value="<%= StringUtils.escapeForXML(client.getName()) %>" id="<%= StringUtils.escapeForXML(client.getName()) %>" <%= clients.contains(client.getName()) ? "checked" : ""%> /> <img src="<%= client.getImage() %>" width="16" height="16" border="0" alt=""> <strong><%= StringUtils.escapeHTMLTags(client.getName()) %></strong></label><span>(<a href="<%= client.getURL() %>" target="_blank"><fmt:message key="permitted.client.website"/></a>)</span><br>
<% } %> <% } %>
</div> </div>
</td> </td>
...@@ -278,9 +295,9 @@ ...@@ -278,9 +295,9 @@
<strong><fmt:message key="permitted.client.add.other.client" />:</strong> <strong><fmt:message key="permitted.client.add.other.client" />:</strong>
<a onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="permitted.client.tooltip" />', 'trail', true, 'direction', 'northeast', 'width', '220');"><img src="images/icon_help_14x14.gif" align="texttop" /></a><br> <a onmouseover="domTT_activate(this, event, 'content', '<fmt:message key="permitted.client.tooltip" />', 'trail', true, 'direction', 'northeast', 'width', '220');"><img src="images/icon_help_14x14.gif" align="texttop" /></a><br>
<input type="text" name="other" style="width: 160px;">&nbsp;<input type="submit" name="addOther" value="<fmt:message key="permitted.client.add" />"/><br> <input type="text" name="other" style="width: 160px;">&nbsp;<input type="hidden" value="${csrf}" name="csrf"><input type="submit" name="addOther" value="<fmt:message key="permitted.client.add" />"/><br>
<% for (String otherClient : otherClients) { %> <% for (String otherClient : otherClients) { %>
<%= otherClient%>&nbsp(<a href="permitted-clients.jsp?removeClient=<%=otherClient%>" name="removeClient" id="<%= otherClient %>"><fmt:message key="permitted.client.remove" /></a>)<br> <%= otherClient%>&nbsp(<a href="permitted-clients.jsp?csrf=${csrf}&removeClient=<%=StringUtils.escapeForXML(otherClient)%>" name="removeClient" id="<%= StringUtils.escapeForXML(otherClient) %>"><fmt:message key="permitted.client.remove" /></a>)<br>
<% } %> <% } %>
</div> </div>
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
<%@ page import="org.jivesoftware.openfire.archive.ConversationManager, org.jivesoftware.util.ByteFormat, org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.openfire.archive.ConversationManager, org.jivesoftware.util.ByteFormat, org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ page import="org.jivesoftware.util.StringUtils" %> <%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
...@@ -169,6 +171,16 @@ ...@@ -169,6 +171,16 @@
int maxRetrievable = ParamUtils.getIntParameter(request, "maxRetrievable", conversationManager.getMaxRetrievable()); int maxRetrievable = ParamUtils.getIntParameter(request, "maxRetrievable", conversationManager.getMaxRetrievable());
boolean rebuildIndex = request.getParameter("rebuild") != null; boolean rebuildIndex = request.getParameter("rebuild") != null;
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
rebuildIndex = false;
update = false;
}
csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (request.getParameter("cancel") != null) { if (request.getParameter("cancel") != null) {
response.sendRedirect("archiving-settings.jsp"); response.sendRedirect("archiving-settings.jsp");
...@@ -257,6 +269,7 @@ ...@@ -257,6 +269,7 @@
</p> </p>
<form action="archiving-settings.jsp" method="post"> <form action="archiving-settings.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<table class="settingsTable" cellpadding="3" cellspacing="0" border="0" width="90%"> <table class="settingsTable" cellpadding="3" cellspacing="0" border="0" width="90%">
<thead> <thead>
<tr> <tr>
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
errors.put("csrf", "CSRF Failure!"); errors.put("csrf", "CSRF Failure!");
} }
} }
csrfParam = StringUtils.randomString(15); csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1); CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam); pageContext.setAttribute("csrf", csrfParam);
if (update) { if (update) {
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
<% // Get parameters <% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0); int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("group-summary", 15)); int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("group-summary", 15));
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (request.getParameter("range") != null) { if (request.getParameter("range") != null) {
webManager.setRowsPerPage("group-summary", range); webManager.setRowsPerPage("group-summary", range);
...@@ -53,19 +55,27 @@ ...@@ -53,19 +55,27 @@
if (webManager.getGroupManager().isSearchSupported() && request.getParameter("search") != null if (webManager.getGroupManager().isSearchSupported() && request.getParameter("search") != null
&& !request.getParameter("search").trim().equals("")) && !request.getParameter("search").trim().equals(""))
{ {
search = request.getParameter("search"); if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
// Santize variables to prevent vulnerabilities
search = StringUtils.escapeHTMLTags(search); } else {
// Use the search terms to get the list of groups and group count. search = request.getParameter("search");
groups = webManager.getGroupManager().search(search, start, range); // Santize variables to prevent vulnerabilities
// Get the count as a search for *all* groups. That will let us do pagination even search = StringUtils.escapeForXML(search);
// though it's a bummer to execute the search twice. // Use the search terms to get the list of groups and group count.
groupCount = webManager.getGroupManager().search(search).size(); groups = webManager.getGroupManager().search(search, start, range);
// Get the count as a search for *all* groups. That will let us do pagination even
// though it's a bummer to execute the search twice.
groupCount = webManager.getGroupManager().search(search).size();
}
} }
// paginator vars // paginator vars
int numPages = (int)Math.ceil((double)groupCount/(double)range); int numPages = (int)Math.ceil((double)groupCount/(double)range);
int curPage = (start/range) + 1; int curPage = (start/range) + 1;
csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
%> %>
<% if (request.getParameter("deletesuccess") != null) { %> <% if (request.getParameter("deletesuccess") != null) { %>
...@@ -98,6 +108,7 @@ ...@@ -98,6 +108,7 @@
</td> </td>
<td align="right" valign="bottom"> <td align="right" valign="bottom">
<fmt:message key="group.summary.search" />: <input type="text" size="30" maxlength="150" name="search" value="<%= ((search!=null) ? search : "") %>"> <fmt:message key="group.summary.search" />: <input type="text" size="30" maxlength="150" name="search" value="<%= ((search!=null) ? search : "") %>">
<input type="hidden" name="csrf" value="${csrf}">
</td> </td>
</tr> </tr>
</table> </table>
......
...@@ -129,14 +129,19 @@ ...@@ -129,14 +129,19 @@
boolean saveLog = ParamUtils.getBooleanParameter(request,"saveLog"); boolean saveLog = ParamUtils.getBooleanParameter(request,"saveLog");
boolean emailLog = ParamUtils.getBooleanParameter(request,"emailLog"); boolean emailLog = ParamUtils.getBooleanParameter(request,"emailLog");
boolean debugEnabled = ParamUtils.getBooleanParameter(request,"debugEnabled"); boolean debugEnabled = ParamUtils.getBooleanParameter(request,"debugEnabled");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
// Enable/disable debugging // Enable/disable debugging
if (request.getParameter("debugEnabled") != null && debugEnabled != Log.isDebugEnabled()) { if (request.getParameter("debugEnabled") != null && debugEnabled != Log.isDebugEnabled()) {
JiveGlobals.setProperty(Log.LOG_DEBUG_ENABLED, String.valueOf(debugEnabled)); if (!(csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam))) {
// Log the event JiveGlobals.setProperty(Log.LOG_DEBUG_ENABLED, String.valueOf(debugEnabled));
admin.logEvent((debugEnabled ? "enabled" : "disabled")+" debug logging", null); // Log the event
response.sendRedirect("logviewer.jsp?log=debug"); admin.logEvent((debugEnabled ? "enabled" : "disabled")+" debug logging", null);
return; response.sendRedirect("logviewer.jsp?log=debug");
return;
}
} }
// Santize variables to prevent vulnerabilities // Santize variables to prevent vulnerabilities
...@@ -147,36 +152,40 @@ ...@@ -147,36 +152,40 @@
User pageUser = admin.getUser(); User pageUser = admin.getUser();
if (clearLog && log != null) { if (clearLog && log != null) {
if ("error".equals(log)) { if (!(csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam))) {
Log.rotateErrorLogFile(); if ("error".equals(log)) {
} Log.rotateErrorLogFile();
else if ("warn".equals(log)) { }
Log.rotateWarnLogFile(); else if ("warn".equals(log)) {
} Log.rotateWarnLogFile();
else if ("info".equals(log)) { }
Log.rotateInfoLogFile(); else if ("info".equals(log)) {
} Log.rotateInfoLogFile();
else if ("debug".equals(log)) { }
Log.rotateDebugLogFile(); else if ("debug".equals(log)) {
Log.rotateDebugLogFile();
}
response.sendRedirect("logviewer.jsp?log=" + log);
return;
} }
response.sendRedirect("logviewer.jsp?log=" + log);
return;
} }
else if (markLog && log != null) { else if (markLog && log != null) {
if ("error".equals(log)) { if (!(csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam))) {
Log.markErrorLogFile(pageUser.getUsername()); if ("error".equals(log)) {
} Log.markErrorLogFile(pageUser.getUsername());
else if ("warn".equals(log)) { }
Log.markWarnLogFile(pageUser.getUsername()); else if ("warn".equals(log)) {
} Log.markWarnLogFile(pageUser.getUsername());
else if ("info".equals(log)) { }
Log.markInfoLogFile(pageUser.getUsername()); else if ("info".equals(log)) {
} Log.markInfoLogFile(pageUser.getUsername());
else if ("debug".equals(log)) { }
Log.markDebugLogFile(pageUser.getUsername()); else if ("debug".equals(log)) {
Log.markDebugLogFile(pageUser.getUsername());
}
response.sendRedirect("logviewer.jsp?log=" + log);
return;
} }
response.sendRedirect("logviewer.jsp?log=" + log);
return;
} }
else if (saveLog && log != null) { else if (saveLog && log != null) {
saveLog = false; saveLog = false;
...@@ -206,6 +215,10 @@ ...@@ -206,6 +215,10 @@
// Determine if any of the log files contents have been updated: // Determine if any of the log files contents have been updated:
HashMap newlogs = getLogUpdate(request, response, logDir); HashMap newlogs = getLogUpdate(request, response, logDir);
csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
%> %>
<html> <html>
...@@ -360,6 +373,7 @@ IFRAME { ...@@ -360,6 +373,7 @@ IFRAME {
<input type="hidden" name="markLog" value="false"> <input type="hidden" name="markLog" value="false">
<input type="hidden" name="saveLog" value="false"> <input type="hidden" name="saveLog" value="false">
<input type="hidden" name="emailLog" value="false"> <input type="hidden" name="emailLog" value="false">
<input type="hidden" name="csrf" value="${csrf}">
<div class="buttons"> <div class="buttons">
<table cellpadding="0" cellspacing="0" border="0"> <table cellpadding="0" cellspacing="0" border="0">
<tbody> <tbody>
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
<%@ page import="org.jivesoftware.database.ProfiledConnection"%> <%@ page import="org.jivesoftware.database.ProfiledConnection"%>
<%@ page import="org.jivesoftware.database.ProfiledConnectionEntry"%> <%@ page import="org.jivesoftware.database.ProfiledConnectionEntry"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%> <%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.util.CookieUtils"%>
<%@ page import="org.jivesoftware.util.LocaleUtils"%> <%@ page import="org.jivesoftware.util.LocaleUtils"%>
<%@ page import="org.jivesoftware.util.StringUtils"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
...@@ -45,6 +47,17 @@ ...@@ -45,6 +47,17 @@
String enableStats = ParamUtils.getParameter(request,"enableStats"); String enableStats = ParamUtils.getParameter(request,"enableStats");
int refresh = ParamUtils.getIntParameter(request,"refresh", -1); int refresh = ParamUtils.getIntParameter(request,"refresh", -1);
boolean doSortByTime = ParamUtils.getBooleanParameter(request,"doSortByTime"); boolean doSortByTime = ParamUtils.getBooleanParameter(request,"doSortByTime");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
boolean csrf_check = true;
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
csrf_check = false;
doClear = false;
}
csrfParam = StringUtils.randomString(16);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Var for the alternating colors // Var for the alternating colors
int rowColor = 0; int rowColor = 0;
...@@ -56,16 +69,18 @@ ...@@ -56,16 +69,18 @@
response.sendRedirect("server-db-stats.jsp"); response.sendRedirect("server-db-stats.jsp");
} }
// Enable/disable stats if (csrf_check) {
if ("true".equals(enableStats) && ! DbConnectionManager.isProfilingEnabled()) { // Enable/disable stats
DbConnectionManager.setProfilingEnabled(true); if ("true".equals(enableStats) && ! DbConnectionManager.isProfilingEnabled()) {
// Log the event DbConnectionManager.setProfilingEnabled(true);
webManager.logEvent("enabled db profiling", null); // Log the event
} webManager.logEvent("enabled db profiling", null);
else if ("false".equals(enableStats) && DbConnectionManager.isProfilingEnabled()) { }
DbConnectionManager.setProfilingEnabled(false); else if ("false".equals(enableStats) && DbConnectionManager.isProfilingEnabled()) {
// Log the event DbConnectionManager.setProfilingEnabled(false);
webManager.logEvent("disabled db profiling", null); // Log the event
webManager.logEvent("disabled db profiling", null);
}
} }
boolean showQueryStats = DbConnectionManager.isProfilingEnabled(); boolean showQueryStats = DbConnectionManager.isProfilingEnabled();
......
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