Commit 57a07150 authored by Guus der Kinderen's avatar Guus der Kinderen

Merge pull request #570 from surevine/dwd/of-836

OF-836 / OF-941 / OF-777
parents 130fc97e 7c49987e
...@@ -126,6 +126,7 @@ public class CookieUtils { ...@@ -126,6 +126,7 @@ public class CookieUtils {
Cookie cookie = new Cookie(name, value); Cookie cookie = new Cookie(name, value);
cookie.setMaxAge(maxAge); cookie.setMaxAge(maxAge);
cookie.setPath(path); cookie.setPath(path);
cookie.setHttpOnly(true);
response.addCookie(cookie); response.addCookie(cookie);
} }
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
--%> --%>
<%@ page import="org.jivesoftware.util.ParamUtils, <%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.openfire.XMPPServer, org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.audit.AuditManager, org.jivesoftware.openfire.audit.AuditManager,
org.jivesoftware.openfire.user.UserNotFoundException, org.jivesoftware.openfire.user.UserNotFoundException,
...@@ -60,6 +61,18 @@ ...@@ -60,6 +61,18 @@
AuditManager auditManager = XMPPServer.getInstance().getAuditManager(); AuditManager auditManager = XMPPServer.getInstance().getAuditManager();
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) {
auditManager.setEnabled(auditEnabled); auditManager.setEnabled(auditEnabled);
auditManager.setAuditMessage(auditMessages); auditManager.setAuditMessage(auditMessages);
...@@ -187,6 +200,7 @@ ...@@ -187,6 +200,7 @@
<!-- BEGIN 'Set Message Audit Policy' --> <!-- BEGIN 'Set Message Audit Policy' -->
<form action="audit-policy.jsp" name="f"> <form action="audit-policy.jsp" name="f">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="audit.policy.policytitle" /> <fmt:message key="audit.policy.policytitle" />
</div> </div>
...@@ -245,7 +259,7 @@ ...@@ -245,7 +259,7 @@
</td> </td>
<td width="99%"> <td width="99%">
<input type="text" size="15" maxlength="50" name="maxTotalSize" <input type="text" size="15" maxlength="50" name="maxTotalSize"
value="<%= ((maxTotalSize != null) ? maxTotalSize : "") %>"> value="<%= ((maxTotalSize != null) ? StringUtils.escapeForXML(maxTotalSize) : "") %>">
<% if (errors.get("maxTotalSize") != null) { %> <% if (errors.get("maxTotalSize") != null) { %>
...@@ -263,7 +277,7 @@ ...@@ -263,7 +277,7 @@
</td> </td>
<td width="99%"> <td width="99%">
<input type="text" size="15" maxlength="50" name="maxFileSize" <input type="text" size="15" maxlength="50" name="maxFileSize"
value="<%= ((maxFileSize != null) ? maxFileSize : "") %>"> value="<%= ((maxFileSize != null) ? StringUtils.escapeForXML(maxFileSize) : "") %>">
<% if (errors.get("maxFileSize") != null) { %> <% if (errors.get("maxFileSize") != null) { %>
...@@ -281,7 +295,7 @@ ...@@ -281,7 +295,7 @@
</td> </td>
<td width="99%"> <td width="99%">
<input type="text" size="15" maxlength="50" name="maxDays" <input type="text" size="15" maxlength="50" name="maxDays"
value="<%= ((maxDays != null) ? maxDays : "") %>"> value="<%= ((maxDays != null) ? StringUtils.escapeForXML(maxDays) : "") %>">
<% if (errors.get("maxDays") != null) { %> <% if (errors.get("maxDays") != null) { %>
...@@ -299,7 +313,7 @@ ...@@ -299,7 +313,7 @@
</td> </td>
<td width="99%"> <td width="99%">
<input type="text" size="15" maxlength="50" name="logTimeout" <input type="text" size="15" maxlength="50" name="logTimeout"
value="<%= ((logTimeout != null) ? logTimeout : "") %>"> value="<%= ((logTimeout != null) ? StringUtils.escapeForXML(logTimeout) : "") %>">
<% if (errors.get("logTimeout") != null) { %> <% if (errors.get("logTimeout") != null) { %>
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
<%@ page import="java.util.Comparator" %> <%@ page import="java.util.Comparator" %>
<%@ page import="java.util.List" %> <%@ page import="java.util.List" %>
<%@ page import="org.jivesoftware.util.JiveGlobals"%> <%@ page import="org.jivesoftware.util.JiveGlobals"%>
<%@ page import="org.jivesoftware.util.StringUtils"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.util.CookieUtils"%>
<%@ page import="java.util.Date"%> <%@ page import="java.util.Date"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...@@ -39,6 +42,17 @@ ...@@ -39,6 +42,17 @@
<% <%
boolean downloadRequested = request.getParameter("download") != null; boolean downloadRequested = request.getParameter("download") != null;
String url = request.getParameter("url"); String url = request.getParameter("url");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (downloadRequested) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
downloadRequested = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager(); UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();
List<AvailablePlugin> plugins = updateManager.getNotInstalledPlugins(); List<AvailablePlugin> plugins = updateManager.getNotInstalledPlugins();
......
...@@ -57,6 +57,18 @@ ...@@ -57,6 +57,18 @@
HistoryStrategy historyStrat = muc.getHistoryStrategy(); HistoryStrategy historyStrat = muc.getHistoryStrategy();
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) {
if (policy != ALL && policy != NONE && policy != NUMBER) { if (policy != ALL && policy != NONE && policy != NUMBER) {
errors.put("general", "Please choose a valid chat history policy."); errors.put("general", "Please choose a valid chat history policy.");
...@@ -116,6 +128,7 @@ ...@@ -116,6 +128,7 @@
</p> </p>
<form action="chatroom-history-settings.jsp" method="post"> <form action="chatroom-history-settings.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<fieldset> <fieldset>
<legend><fmt:message key="chatroom.history.settings.policy" /></legend> <legend><fmt:message key="chatroom.history.settings.policy" /></legend>
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ 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" %>
...@@ -43,6 +45,17 @@ ...@@ -43,6 +45,17 @@
boolean serverEnabled = ParamUtils.getBooleanParameter(request, "serverEnabled"); boolean serverEnabled = ParamUtils.getBooleanParameter(request, "serverEnabled");
final ConnectionManagerImpl connectionManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager(); final ConnectionManagerImpl connectionManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
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) {
// Update c2s compression policy // Update c2s compression policy
...@@ -86,6 +99,7 @@ ...@@ -86,6 +99,7 @@
<!-- BEGIN compression settings --> <!-- BEGIN compression settings -->
<form action="compression-settings.jsp"> <form action="compression-settings.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBox" style="-moz-border-radius: 3px;"> <div class="jive-contentBox" style="-moz-border-radius: 3px;">
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
org.jivesoftware.openfire.multiplex.ConnectionMultiplexerManager, org.jivesoftware.openfire.multiplex.ConnectionMultiplexerManager,
org.jivesoftware.openfire.session.ConnectionMultiplexerSession, org.jivesoftware.openfire.session.ConnectionMultiplexerSession,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.StringUtils" org.jivesoftware.util.StringUtils"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -58,6 +59,18 @@ ...@@ -58,6 +59,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 (managerEnabled) { if (managerEnabled) {
...@@ -167,6 +180,7 @@ ...@@ -167,6 +180,7 @@
<% } %> <% } %>
<form action="connection-managers-settings.jsp" method="post"> <form action="connection-managers-settings.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<fieldset> <fieldset>
<div> <div>
......
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ 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.openfire.Connection" %> <%@ page import="org.jivesoftware.openfire.Connection" %>
<%@ page import="org.jivesoftware.openfire.spi.*" %> <%@ page import="org.jivesoftware.openfire.spi.*" %>
<%@ page import="java.util.*" %> <%@ page import="java.util.*" %>
...@@ -12,9 +14,21 @@ ...@@ -12,9 +14,21 @@
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" /> <jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out ); %> <% webManager.init(request, response, session, application, out ); %>
<% <%
final boolean update = request.getParameter( "update" ) != null; boolean update = request.getParameter( "update" ) != null;
final Map<String, String> errors = new HashMap<>(); final Map<String, String> errors = new HashMap<>();
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);
pageContext.setAttribute( "errors", errors ); pageContext.setAttribute( "errors", errors );
ConnectionType connectionType = null; ConnectionType connectionType = null;
...@@ -281,6 +295,7 @@ ...@@ -281,6 +295,7 @@
</p> </p>
<form action="connection-settings-advanced.jsp?connectionType=${connectionType}&connectionMode=${connectionMode}" onsubmit="selectAllOptions('cipherSuitesEnabled')" method="post"> <form action="connection-settings-advanced.jsp?connectionType=${connectionType}&connectionMode=${connectionMode}" onsubmit="selectAllOptions('cipherSuitesEnabled')" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="update" value="true" /> <input type="hidden" name="update" value="true" />
<fmt:message key="connection.advanced.settings.tcp.boxtitle" var="tcpboxtitle"/> <fmt:message key="connection.advanced.settings.tcp.boxtitle" var="tcpboxtitle"/>
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %>
<%@ page import="org.jivesoftware.util.ModificationNotAllowedException" %> <%@ page import="org.jivesoftware.util.ModificationNotAllowedException" %>
<%@ 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.xmpp.packet.JID" %>
<%@ page import="gnu.inet.encoding.StringprepException" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
<%@ page errorPage="error.jsp" %> <%@ page errorPage="error.jsp" %>
...@@ -26,8 +30,29 @@ ...@@ -26,8 +30,29 @@
final ConnectionConfiguration legacymodeConfiguration = manager.getListener( connectionType, true ).generateConnectionConfiguration(); final ConnectionConfiguration legacymodeConfiguration = manager.getListener( connectionType, true ).generateConnectionConfiguration();
final Map<String, String> errors = new HashMap<>(); final Map<String, String> errors = new HashMap<>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
boolean update = request.getParameter( "update" ) != null;
boolean permissionUpdate = request.getParameter( "permissionUpdate" ) != null;
String configToDelete = ParamUtils.getParameter( request, "deleteConf" );
boolean componentAllowed = request.getParameter( "componentAllowed" ) != null;
boolean componentBlocked = request.getParameter( "componentBlocked" ) != null;
if (update || permissionUpdate || configToDelete != null || componentAllowed || componentBlocked) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
update = false;
permissionUpdate = false;
configToDelete = null;
componentAllowed = false;
componentBlocked = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
final boolean update = request.getParameter( "update" ) != null;
if ( update && errors.isEmpty() ) if ( update && errors.isEmpty() )
{ {
...@@ -55,7 +80,6 @@ ...@@ -55,7 +80,6 @@
} }
// Process Permission update configuration change. // Process Permission update configuration change.
final boolean permissionUpdate = request.getParameter( "permissionUpdate" ) != null;
if ( permissionUpdate && errors.isEmpty() ) if ( permissionUpdate && errors.isEmpty() )
{ {
...@@ -85,7 +109,6 @@ ...@@ -85,7 +109,6 @@
} }
// Process removal of a blacklist or whitelist item. // Process removal of a blacklist or whitelist item.
final String configToDelete = ParamUtils.getParameter( request, "deleteConf" );
if ( configToDelete != null && !configToDelete.trim().isEmpty() && errors.isEmpty() ) if ( configToDelete != null && !configToDelete.trim().isEmpty() && errors.isEmpty() )
{ {
...@@ -105,12 +128,17 @@ ...@@ -105,12 +128,17 @@
} }
// Process addition to whitelist. // Process addition to whitelist.
final boolean componentAllowed = request.getParameter( "componentAllowed" ) != null;
String subdomain = ParamUtils.getParameter( request, "subdomain" ); // shared with blacklist. String subdomain = ParamUtils.getParameter( request, "subdomain" ); // shared with blacklist.
if ( subdomain != null ) if ( subdomain != null )
{ {
// Remove the hostname if the user is not sending just the subdomain. subdomain = subdomain.trim();
subdomain = subdomain.replace( "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain(), "" ); try {
subdomain = JID.domainprep(subdomain);
// Remove the hostname if the user is not sending just the subdomain.
subdomain = subdomain.replace( "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain(), "" );
} catch (Exception e) {
errors.put("subdomain", e.getMessage());
}
} }
if ( componentAllowed && errors.isEmpty() ) if ( componentAllowed && errors.isEmpty() )
{ {
...@@ -147,7 +175,6 @@ ...@@ -147,7 +175,6 @@
} }
// Process addition to blacklist. // Process addition to blacklist.
final boolean componentBlocked = request.getParameter( "componentBlocked" ) != null;
if ( componentBlocked && errors.isEmpty() ) if ( componentBlocked && errors.isEmpty() )
{ {
...@@ -259,6 +286,7 @@ ...@@ -259,6 +286,7 @@
</p> </p>
<form action="connection-settings-external-components.jsp" method="post"> <form action="connection-settings-external-components.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<fmt:message key="component.settings.plaintext.boxtitle" var="plaintextboxtitle"/> <fmt:message key="component.settings.plaintext.boxtitle" var="plaintextboxtitle"/>
<admin:contentBox title="${plaintextboxtitle}"> <admin:contentBox title="${plaintextboxtitle}">
...@@ -307,6 +335,7 @@ ...@@ -307,6 +335,7 @@
<fmt:message key="component.settings.allowed" var="allowedTitle" /> <fmt:message key="component.settings.allowed" var="allowedTitle" />
<admin:contentBox title="${allowedTitle}"> <admin:contentBox title="${allowedTitle}">
<form action="connection-settings-external-components.jsp" method="post"> <form action="connection-settings-external-components.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<table cellpadding="3" cellspacing="0" border="0" width="100%" > <table cellpadding="3" cellspacing="0" border="0" width="100%" >
<tr valign="top"> <tr valign="top">
<td colspan="2"> <td colspan="2">
...@@ -364,7 +393,11 @@ ...@@ -364,7 +393,11 @@
<td><c:out value="${component.subdomain}"/></td> <td><c:out value="${component.subdomain}"/></td>
<td><c:out value="${component.secret}"/></td> <td><c:out value="${component.secret}"/></td>
<td align="center" style="border-right:1px #ccc solid;"> <td align="center" style="border-right:1px #ccc solid;">
<a href="#" onclick="if (confirm('<fmt:message key="component.settings.confirm_delete" />')) { location.replace('connection-settings-external-components.jsp?deleteConf=${component.subdomain}'); } " <c:url var="deleteurl" value="connection-settings-external-components.jsp">
<c:param name="deleteConf" value="${component.subdomain}"/>
<c:param name="csrf" value="${csrf}"/>
</c:url>
<a href="#" onclick="if (confirm('<fmt:message key="component.settings.confirm_delete" />')) { location.replace('${deleteurl}'); } "
title="<fmt:message key="global.click_delete" />"><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a> title="<fmt:message key="global.click_delete" />"><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
</td> </td>
</tr> </tr>
...@@ -376,6 +409,7 @@ ...@@ -376,6 +409,7 @@
<br/> <br/>
<form action="connection-settings-external-components.jsp" method="post"> <form action="connection-settings-external-components.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<table cellpadding="3" cellspacing="1" border="0"> <table cellpadding="3" cellspacing="1" border="0">
<tr> <tr>
<td nowrap width="1%"> <td nowrap width="1%">
...@@ -423,7 +457,11 @@ ...@@ -423,7 +457,11 @@
<td>${ status.index + 1}</td> <td>${ status.index + 1}</td>
<td><c:out value="${component.subdomain}"/></td> <td><c:out value="${component.subdomain}"/></td>
<td align="center" style="border-right:1px #ccc solid;"> <td align="center" style="border-right:1px #ccc solid;">
<a href="#" onclick="if (confirm('<fmt:message key="component.settings.confirm_delete" />')) { location.replace('connection-settings-external-components.jsp?deleteConf=${component.subdomain}'); } " <c:url var="deleteurl" value="connection-settings-external-components.jsp">
<c:param name="deleteConf" value="${component.subdomain}"/>
<c:param name="csrf" value="${csrf}"/>
</c:url>
<a href="#" onclick="if (confirm('<fmt:message key="component.settings.confirm_delete" />')) { location.replace('${deleteurl}'); } "
title="<fmt:message key="global.click_delete" />"><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a> title="<fmt:message key="global.click_delete" />"><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
</td> </td>
</tr> </tr>
...@@ -435,6 +473,7 @@ ...@@ -435,6 +473,7 @@
<br/> <br/>
<form action="connection-settings-external-components.jsp" method="post"> <form action="connection-settings-external-components.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<table cellpadding="3" cellspacing="1" border="0"> <table cellpadding="3" cellspacing="1" border="0">
<tr> <tr>
<td nowrap width="1%"> <td nowrap width="1%">
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %>
<%@ page import="org.jivesoftware.openfire.spi.ConnectionListener" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionListener" %>
<%@ 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.JiveGlobals" %> <%@ page import="org.jivesoftware.util.JiveGlobals" %>
<%@ page import="org.jivesoftware.openfire.session.ConnectionSettings" %> <%@ page import="org.jivesoftware.openfire.session.ConnectionSettings" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
...@@ -22,8 +24,20 @@ ...@@ -22,8 +24,20 @@
final ConnectionConfiguration plaintextConfiguration = manager.getListener( connectionType, false ).generateConnectionConfiguration(); final ConnectionConfiguration plaintextConfiguration = manager.getListener( connectionType, false ).generateConnectionConfiguration();
final ConnectionConfiguration legacymodeConfiguration = manager.getListener( connectionType, true ).generateConnectionConfiguration(); final ConnectionConfiguration legacymodeConfiguration = manager.getListener( connectionType, true ).generateConnectionConfiguration();
final boolean update = request.getParameter( "update" ) != null; boolean update = request.getParameter( "update" ) != null;
final Map<String, String> errors = new HashMap<>(); final Map<String, String> errors = new HashMap<>();
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 && errors.isEmpty() ) if ( update && errors.isEmpty() )
{ {
...@@ -126,6 +140,7 @@ ...@@ -126,6 +140,7 @@
</p> </p>
<form action="connection-settings-socket-c2s.jsp" method="post"> <form action="connection-settings-socket-c2s.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<fmt:message key="ssl.settings.client.plaintext.boxtitle" var="plaintextboxtitle"/> <fmt:message key="ssl.settings.client.plaintext.boxtitle" var="plaintextboxtitle"/>
<admin:contentBox title="${plaintextboxtitle}"> <admin:contentBox title="${plaintextboxtitle}">
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %>
<%@ page import="org.jivesoftware.openfire.spi.ConnectionListener" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionListener" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
<%@ page import="org.jivesoftware.openfire.server.RemoteServerManager" %> <%@ page import="org.jivesoftware.openfire.server.RemoteServerManager" %>
...@@ -22,13 +23,29 @@ ...@@ -22,13 +23,29 @@
final ConnectionConfiguration plaintextConfiguration = manager.getListener( connectionType, false ).generateConnectionConfiguration(); final ConnectionConfiguration plaintextConfiguration = manager.getListener( connectionType, false ).generateConnectionConfiguration();
final boolean update = request.getParameter( "update" ) != null; boolean update = request.getParameter( "update" ) != null;
final boolean closeSettings = request.getParameter( "closeSettings" ) != null; boolean closeSettings = request.getParameter( "closeSettings" ) != null;
final boolean serverAllowed = request.getParameter( "serverAllowed" ) != null; boolean serverAllowed = request.getParameter( "serverAllowed" ) != null;
final boolean serverBlocked = request.getParameter( "serverBlocked" ) != null; boolean serverBlocked = request.getParameter( "serverBlocked" ) != null;
final String configToDelete = ParamUtils.getParameter( request, "deleteConf" ); String configToDelete = ParamUtils.getParameter( request, "deleteConf" );
final Map<String, String> errors = new HashMap<>(); final Map<String, String> errors = new HashMap<>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (update || closeSettings || serverAllowed || serverBlocked || configToDelete != null) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
update = false;
closeSettings = false;
serverAllowed = false;
serverBlocked = false;
configToDelete = null;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if ( update && errors.isEmpty() ) if ( update && errors.isEmpty() )
{ {
...@@ -262,6 +279,7 @@ ...@@ -262,6 +279,7 @@
</p> </p>
<form action="connection-settings-socket-s2s.jsp" method="post"> <form action="connection-settings-socket-s2s.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<fmt:message key="server2server.settings.boxtitle" var="boxtitle"/> <fmt:message key="server2server.settings.boxtitle" var="boxtitle"/>
<admin:contentBox title="${boxtitle}"> <admin:contentBox title="${boxtitle}">
...@@ -290,6 +308,7 @@ ...@@ -290,6 +308,7 @@
<!-- BEGIN 'Idle Connection Settings' --> <!-- BEGIN 'Idle Connection Settings' -->
<form action="connection-settings-socket-s2s.jsp?closeSettings" method="post"> <form action="connection-settings-socket-s2s.jsp?closeSettings" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<fmt:message key="server2server.settings.close_settings" var="idleTitle"/> <fmt:message key="server2server.settings.close_settings" var="idleTitle"/>
<admin:contentBox title="${idleTitle}"> <admin:contentBox title="${idleTitle}">
<table cellpadding="3" cellspacing="0" border="0"> <table cellpadding="3" cellspacing="0" border="0">
...@@ -329,6 +348,7 @@ ...@@ -329,6 +348,7 @@
<fmt:message key="server2server.settings.allowed" var="allowedTitle"/> <fmt:message key="server2server.settings.allowed" var="allowedTitle"/>
<admin:contentBox title="${allowedTitle}"> <admin:contentBox title="${allowedTitle}">
<form action="connection-settings-socket-s2s.jsp" method="post"> <form action="connection-settings-socket-s2s.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<table cellpadding="3" cellspacing="0" border="0"> <table cellpadding="3" cellspacing="0" border="0">
<tr valign="top"> <tr valign="top">
<td width="1%" nowrap> <td width="1%" nowrap>
...@@ -357,6 +377,7 @@ ...@@ -357,6 +377,7 @@
</form> </form>
<form action="connection-settings-socket-s2s.jsp" method="post"> <form action="connection-settings-socket-s2s.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%"> <table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr> <tr>
<th width="1%">&nbsp;</th> <th width="1%">&nbsp;</th>
...@@ -377,7 +398,11 @@ ...@@ -377,7 +398,11 @@
<td><c:out value="${server.domain}"/></td> <td><c:out value="${server.domain}"/></td>
<td><c:out value="${server.remotePort}"/></td> <td><c:out value="${server.remotePort}"/></td>
<td align="center" style="border-right:1px #ccc solid;"> <td align="center" style="border-right:1px #ccc solid;">
<a href="#" onclick="if (confirm('<fmt:message key="server2server.settings.confirm_delete" />')) { location.replace('connection-settings-socket-s2s.jsp?deleteConf=${server.domain}'); } " <c:url var="deleteurl" value="connection-settings-socket-s2s.jsp">
<c:param name="deleteConf" value="${server.domain}"/>
<c:param name="csrf" value="${csrf}"/>
</c:url>
<a href="#" onclick="if (confirm('<fmt:message key="server2server.settings.confirm_delete" />')) { location.replace('${deleteurl}'); } "
title="<fmt:message key="global.click_delete" />" title="<fmt:message key="global.click_delete" />"
><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>
</td> </td>
...@@ -429,7 +454,11 @@ ...@@ -429,7 +454,11 @@
<td>${ status.index + 1}</td> <td>${ status.index + 1}</td>
<td><c:out value="${server.domain}"/></td> <td><c:out value="${server.domain}"/></td>
<td align="center" style="border-right:1px #ccc solid;"> <td align="center" style="border-right:1px #ccc solid;">
<a href="#" onclick="if (confirm('<fmt:message key="server2server.settings.confirm_delete" />')) { location.replace('connection-settings-socket-s2s.jsp?deleteConf=${server.domain}'); } " <c:url var="deleteurl" value="connection-settings-socket-s2s.jsp">
<c:param name="deleteConf" value="${server.domain}"/>
<c:param name="csrf" value="${csrf}"/>
</c:url>
<a href="#" onclick="if (confirm('<fmt:message key="server2server.settings.confirm_delete" />')) { location.replace('${deleteurl}'); } "
title="<fmt:message key="global.click_delete" />" title="<fmt:message key="global.click_delete" />"
><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>
</td> </td>
...@@ -440,6 +469,7 @@ ...@@ -440,6 +469,7 @@
</table> </table>
<br> <br>
<form action="connection-settings-socket-s2s.jsp" method="post"> <form action="connection-settings-socket-s2s.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<table cellpadding="3" cellspacing="1" border="0" width="100%"> <table cellpadding="3" cellspacing="1" border="0" width="100%">
<tr> <tr>
<td nowrap width="1%"> <td nowrap width="1%">
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
- limitations under the License. - limitations under the License.
--%> --%>
<%@ 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.openfire.filetransfer.proxy.FileTransferProxy" %> <%@ page import="org.jivesoftware.openfire.filetransfer.proxy.FileTransferProxy" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
...@@ -35,6 +37,18 @@ ...@@ -35,6 +37,18 @@
boolean isUpdated = request.getParameter("update") != null; boolean isUpdated = request.getParameter("update") != null;
boolean isProxyEnabled = ParamUtils.getBooleanParameter(request, "proxyEnabled"); boolean isProxyEnabled = ParamUtils.getBooleanParameter(request, "proxyEnabled");
int port = ParamUtils.getIntParameter(request, "port", 0); int port = ParamUtils.getIntParameter(request, "port", 0);
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (isUpdated) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
isUpdated = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (isUpdated) { if (isUpdated) {
if (isProxyEnabled) { if (isProxyEnabled) {
...@@ -114,6 +128,7 @@ else { %> ...@@ -114,6 +128,7 @@ else { %>
<!-- BEGIN 'Proxy Service' --> <!-- BEGIN 'Proxy Service' -->
<form action="file-transfer-proxy.jsp" method="post"> <form action="file-transfer-proxy.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="filetransferproxy.settings.enabled.legend"/> <fmt:message key="filetransferproxy.settings.enabled.legend"/>
</div> </div>
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
errorPage="error.jsp" errorPage="error.jsp"
%> %>
<%@ page import="org.jivesoftware.util.ParamUtils"%> <%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.util.CookieUtils"%>
<%@ page import="java.net.URLEncoder"%> <%@ page import="java.net.URLEncoder"%>
<%@ page import="java.util.HashMap"%> <%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
...@@ -45,6 +46,19 @@ ...@@ -45,6 +46,19 @@
String description = ParamUtils.getParameter(request, "description", true); String description = ParamUtils.getParameter(request, "description", true);
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 (create || edit) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
create = false;
edit = false;
errors.put("csrf", "CSRF Failure!");
}
}
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) {
...@@ -187,6 +201,7 @@ ...@@ -187,6 +201,7 @@
</p> </p>
<form name="f" action="group-create.jsp" method="post"> <form name="f" action="group-create.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<% if (groupName != null) { %> <% if (groupName != null) { %>
<input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>" id="existingName"> <input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>" id="existingName">
......
...@@ -35,6 +35,17 @@ ...@@ -35,6 +35,17 @@
boolean cancel = request.getParameter("cancel") != null; boolean cancel = request.getParameter("cancel") != null;
boolean delete = request.getParameter("delete") != null; boolean delete = request.getParameter("delete") != null;
String groupName = ParamUtils.getParameter(request,"group"); String groupName = ParamUtils.getParameter(request,"group");
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) {
...@@ -81,6 +92,7 @@ ...@@ -81,6 +92,7 @@
</p> </p>
<form action="group-delete.jsp"> <form action="group-delete.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>"> <input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>">
<input type="submit" name="delete" value="<fmt:message key="group.delete.delete" />"> <input type="submit" name="delete" value="<fmt:message key="group.delete.delete" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />"> <input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,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"%>
...@@ -71,6 +72,21 @@ ...@@ -71,6 +72,21 @@
Group group = groupManager.getGroup(groupName); Group group = groupManager.getGroup(groupName);
boolean success; boolean success;
StringBuffer errorBuf = new StringBuffer(); StringBuffer errorBuf = new StringBuffer();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (add || delete || updateMember || update) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
add = false;
delete = false;
update = false;
updateMember = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (cancel) { if (cancel) {
response.sendRedirect("group-summary.jsp"); response.sendRedirect("group-summary.jsp");
...@@ -325,6 +341,8 @@ ...@@ -325,6 +341,8 @@
<div class="jive-horizontalRule"></div> <div class="jive-horizontalRule"></div>
<form name="ff" action="group-edit.jsp"> <form name="ff" action="group-edit.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>"/> <input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>"/>
...@@ -478,6 +496,7 @@ ...@@ -478,6 +496,7 @@
</p> </p>
<form action="group-edit.jsp" method="post" name="f"> <form action="group-edit.jsp" method="post" name="f">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>"> <input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>">
<input type="hidden" name="add" value="Add"/> <input type="hidden" name="add" value="Add"/>
<table cellpadding="3" cellspacing="1" border="0" style="margin: 0 0 8px 0;"> <table cellpadding="3" cellspacing="1" border="0" style="margin: 0 0 8px 0;">
...@@ -496,6 +515,7 @@ ...@@ -496,6 +515,7 @@
<% } %> <% } %>
<form action="group-edit.jsp" method="post" name="main"> <form action="group-edit.jsp" method="post" name="main">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>"> <input type="hidden" name="group" value="<%= StringUtils.escapeForXML(groupName) %>">
<table class="jive-table" cellpadding="3" cellspacing="0" border="0" width="435"> <table class="jive-table" cellpadding="3" cellspacing="0" border="0" width="435">
<tr> <tr>
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="org.jivesoftware.util.Log" %> <%@ page import="org.jivesoftware.util.Log" %>
<%@ page import="org.jivesoftware.util.StringUtils" %> <%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.openfire.http.FlashCrossDomainServlet" %> <%@ page import="org.jivesoftware.openfire.http.FlashCrossDomainServlet" %>
<%@ page import="org.jivesoftware.openfire.http.HttpBindManager" %> <%@ page import="org.jivesoftware.openfire.http.HttpBindManager" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
...@@ -83,12 +83,21 @@ ...@@ -83,12 +83,21 @@
<% <%
Map<String, String> errorMap = new HashMap<String, String>(); Map<String, String> errorMap = new HashMap<String, String>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (request.getParameter("update") != null) { if (request.getParameter("update") != null) {
errorMap = handleUpdate(request); if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
// Log the event errorMap.put("csrf", "CSRF Failure!");
webManager.logEvent("updated HTTP bind settings", null); } else {
errorMap = handleUpdate(request);
// Log the event
webManager.logEvent("updated HTTP bind settings", null);
}
} }
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
boolean isHttpBindEnabled = serverManager.isHttpBindEnabled(); boolean isHttpBindEnabled = serverManager.isHttpBindEnabled();
int port = serverManager.getHttpBindUnsecurePort(); int port = serverManager.getHttpBindUnsecurePort();
int securePort = serverManager.getHttpBindSecurePort(); int securePort = serverManager.getHttpBindSecurePort();
...@@ -148,6 +157,7 @@ ...@@ -148,6 +157,7 @@
} %> } %>
<form action="http-bind.jsp" method="post"> <form action="http-bind.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBox" style="-moz-border-radius: 3px;"> <div class="jive-contentBox" style="-moz-border-radius: 3px;">
<table cellpadding="3" cellspacing="0" border="0"> <table cellpadding="3" cellspacing="0" border="0">
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
<%@ page import="org.jivesoftware.openfire.keystore.IdentityStore" %> <%@ page import="org.jivesoftware.openfire.keystore.IdentityStore" %>
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
...@@ -14,7 +16,7 @@ ...@@ -14,7 +16,7 @@
<% webManager.init(request, response, session, application, out ); %> <% webManager.init(request, response, session, application, out ); %>
<% // Get parameters: <% // Get parameters:
final boolean save = ParamUtils.getParameter(request, "save") != null; boolean save = ParamUtils.getParameter(request, "save") != null;
final String privateKey = ParamUtils.getParameter(request, "privateKey"); final String privateKey = ParamUtils.getParameter(request, "privateKey");
final String passPhrase = ParamUtils.getParameter(request, "passPhrase"); final String passPhrase = ParamUtils.getParameter(request, "passPhrase");
final String certificate = ParamUtils.getParameter(request, "certificate"); final String certificate = ParamUtils.getParameter(request, "certificate");
...@@ -30,6 +32,18 @@ ...@@ -30,6 +32,18 @@
errors.put( "connectionType", ex.getMessage() ); errors.put( "connectionType", ex.getMessage() );
connectionType = null; connectionType = null;
} }
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 (privateKey == null || privateKey.trim().isEmpty() ) { if (privateKey == null || privateKey.trim().isEmpty() ) {
...@@ -107,6 +121,7 @@ ...@@ -107,6 +121,7 @@
<!-- BEGIN 'Import Private Key and Certificate' --> <!-- BEGIN 'Import Private Key and Certificate' -->
<form action="import-keystore-certificate.jsp?connectionType=${connectionType}" method="post"> <form action="import-keystore-certificate.jsp?connectionType=${connectionType}" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<c:set var="title"><fmt:message key="ssl.import.certificate.keystore.private-key.title"/></c:set> <c:set var="title"><fmt:message key="ssl.import.certificate.keystore.private-key.title"/></c:set>
<admin:contentBox title="${title}"> <admin:contentBox title="${title}">
...@@ -117,7 +132,7 @@ ...@@ -117,7 +132,7 @@
<label for="passPhrase"><fmt:message key="ssl.import.certificate.keystore.pass-phrase" /></label> <label for="passPhrase"><fmt:message key="ssl.import.certificate.keystore.pass-phrase" /></label>
</td> </td>
<td width="99%"> <td width="99%">
<input type="text" size="60" maxlength="200" name="passPhrase" id="passPhrase" value="${param.passPhrase}"> <input type="text" size="60" maxlength="200" name="passPhrase" id="passPhrase" value="<c:out value="${param.passPhrase}"/>">
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
<%@ page import="org.jivesoftware.openfire.keystore.TrustStore"%> <%@ page import="org.jivesoftware.openfire.keystore.TrustStore"%>
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType"%> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType"%>
<%@ 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="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
...@@ -14,12 +16,24 @@ ...@@ -14,12 +16,24 @@
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"/> <jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"/>
<% webManager.init(request, response, session, application, out ); %> <% webManager.init(request, response, session, application, out ); %>
<% final boolean save = ParamUtils.getParameter(request, "save") != null; <% boolean save = ParamUtils.getParameter(request, "save") != null;
final String alias = ParamUtils.getParameter(request, "alias"); final String alias = ParamUtils.getParameter(request, "alias");
final String certificate = ParamUtils.getParameter(request, "certificate"); final String certificate = ParamUtils.getParameter(request, "certificate");
final String storePurposeText = ParamUtils.getParameter(request, "connectionType"); final String storePurposeText = ParamUtils.getParameter(request, "connectionType");
final Map<String, String> errors = new HashMap<String, String>(); final 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);
ConnectionType connectionType; ConnectionType connectionType;
try try
......
...@@ -86,7 +86,21 @@ ...@@ -86,7 +86,21 @@
Map<String, String> errors = new HashMap<String, String>(); Map<String, String> errors = new HashMap<String, String>();
if (ParamUtils.getBooleanParameter(request, "login")) { Boolean login = ParamUtils.getBooleanParameter(request, "login");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (login) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
login = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (login) {
String loginUsername = username; String loginUsername = username;
if (loginUsername != null) { if (loginUsername != null) {
loginUsername = JID.escapeNode(loginUsername); loginUsername = JID.escapeNode(loginUsername);
...@@ -182,6 +196,7 @@ ...@@ -182,6 +196,7 @@
<% } catch (Exception e) { Log.error(e); } } %> <% } catch (Exception e) { Log.error(e); } } %>
<input type="hidden" name="login" value="true"> <input type="hidden" name="login" value="true">
<input type="hidden" name="csrf" value="${csrf}">
<div align="center"> <div align="center">
<!-- BEGIN login box --> <!-- BEGIN login box -->
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,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.XMPPServer, org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.update.UpdateManager, org.jivesoftware.openfire.update.UpdateManager,
java.util.HashMap, java.util.HashMap,
...@@ -54,6 +55,18 @@ ...@@ -54,6 +55,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
...@@ -130,6 +143,7 @@ else if (updateSucess) { %> ...@@ -130,6 +143,7 @@ else if (updateSucess) { %>
<!-- BEGIN manage updates settings --> <!-- BEGIN manage updates settings -->
<form action="manage-updates.jsp" method="post"> <form action="manage-updates.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<!--<div class="jive-contentBoxHeader"> <!--<div class="jive-contentBoxHeader">
</div>--> </div>-->
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<%@ page import="org.jivesoftware.util.JiveGlobals" %> <%@ page import="org.jivesoftware.util.JiveGlobals" %>
<%@ 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.StringUtils" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
<%@ page import="org.jivesoftware.openfire.mediaproxy.MediaProxyService" %> <%@ page import="org.jivesoftware.openfire.mediaproxy.MediaProxyService" %>
...@@ -37,10 +38,6 @@ ...@@ -37,10 +38,6 @@
MediaProxyService mediaProxyService = XMPPServer.getInstance().getMediaProxyService(); MediaProxyService mediaProxyService = XMPPServer.getInstance().getMediaProxyService();
boolean stop = request.getParameter("stop") != null; boolean stop = request.getParameter("stop") != null;
if (stop) {
mediaProxyService.stopAgents();
}
boolean save = request.getParameter("update") != null; boolean save = request.getParameter("update") != null;
boolean success = false; boolean success = false;
...@@ -50,6 +47,22 @@ ...@@ -50,6 +47,22 @@
int maxPort = mediaProxyService.getMaxPort(); int maxPort = mediaProxyService.getMaxPort();
int echoPort = mediaProxyService.getEchoPort(); int echoPort = mediaProxyService.getEchoPort();
boolean enabled = mediaProxyService.isEnabled(); boolean enabled = mediaProxyService.isEnabled();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save || stop) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
stop = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (stop) {
mediaProxyService.stopAgents();
}
if (save) { if (save) {
keepAliveDelay = ParamUtils.getLongParameter(request, "idleTimeout", keepAliveDelay); keepAliveDelay = ParamUtils.getLongParameter(request, "idleTimeout", keepAliveDelay);
...@@ -128,6 +141,7 @@ ...@@ -128,6 +141,7 @@
<% } %> <% } %>
<form action="media-proxy.jsp" method="post"> <form action="media-proxy.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="mediaproxy.form.label"/> <fmt:message key="mediaproxy.form.label"/>
</div> </div>
...@@ -322,6 +336,7 @@ ...@@ -322,6 +336,7 @@
</tbody> </tbody>
</table> </table>
<form action=""> <form action="">
<input type="hidden" name="csrf" value="${csrf}">
<input type="submit" name="stop" value="<fmt:message key="mediaproxy.summary.stopbutton" />"/> <input type="submit" name="stop" value="<fmt:message key="mediaproxy.summary.stopbutton" />"/>
</form> </form>
</div> </div>
......
...@@ -52,6 +52,19 @@ ...@@ -52,6 +52,19 @@
return; return;
} }
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save || add || delete) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
add = false;
delete = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Get muc server // Get muc server
MultiUserChatService mucService = webManager.getMultiUserChatManager().getMultiUserChatService(mucname); MultiUserChatService mucService = webManager.getMultiUserChatManager().getMultiUserChatService(mucname);
...@@ -192,6 +205,7 @@ ...@@ -192,6 +205,7 @@
<!-- BEGIN 'Permission Policy' --> <!-- BEGIN 'Permission Policy' -->
<form action="muc-create-permission.jsp?save" method="post"> <form action="muc-create-permission.jsp?save" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" /> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="muc.create.permission.policy" /> <fmt:message key="muc.create.permission.policy" />
...@@ -231,6 +245,7 @@ ...@@ -231,6 +245,7 @@
<% if (mucService.isRoomCreationRestricted()) { %> <% if (mucService.isRoomCreationRestricted()) { %>
<!-- BEGIN 'Allowed Users' --> <!-- BEGIN 'Allowed Users' -->
<form action="muc-create-permission.jsp?add" method="post"> <form action="muc-create-permission.jsp?add" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" /> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="muc.create.permission.allowed_users" /> <fmt:message key="muc.create.permission.allowed_users" />
...@@ -288,7 +303,7 @@ ...@@ -288,7 +303,7 @@
<%= jidDisplay %></a> <%= jidDisplay %></a>
</td> </td>
<td width="1%" align="center"> <td width="1%" align="center">
<a href="muc-create-permission.jsp?userJID=<%= jid.toString() %>&delete=true&mucname=<%= URLEncoder.encode(mucname, "UTF-8") %>" <a href="muc-create-permission.jsp?userJID=<%= jid.toString() %>&delete=true&csrf=${csrf}&mucname=<%= URLEncoder.encode(mucname, "UTF-8") %>"
title="<fmt:message key="muc.create.permission.click_title" />" title="<fmt:message key="muc.create.permission.click_title" />"
onclick="return confirm('<fmt:message key="muc.create.permission.confirm_remove" />');" onclick="return confirm('<fmt:message key="muc.create.permission.confirm_remove" />');"
><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>
......
...@@ -56,6 +56,18 @@ ...@@ -56,6 +56,18 @@
// Handle a save // Handle a save
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) {
try { try {
int max = Integer.parseInt(maxUsers); int max = Integer.parseInt(maxUsers);
...@@ -182,6 +194,7 @@ ...@@ -182,6 +194,7 @@
<!-- BEGIN 'Default Room Settings' --> <!-- BEGIN 'Default Room Settings' -->
<form action="muc-default-settings.jsp?save" method="post"> <form action="muc-default-settings.jsp?save" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" /> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="muc.default.settings.title" /> <fmt:message key="muc.default.settings.title" />
......
...@@ -58,6 +58,18 @@ ...@@ -58,6 +58,18 @@
HistoryStrategy historyStrat = mucService.getHistoryStrategy(); HistoryStrategy historyStrat = mucService.getHistoryStrategy();
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) {
if (policy != ALL && policy != NONE && policy != NUMBER) { if (policy != ALL && policy != NONE && policy != NUMBER) {
errors.put("general", "Please choose a valid chat history policy."); errors.put("general", "Please choose a valid chat history policy.");
...@@ -135,6 +147,7 @@ ...@@ -135,6 +147,7 @@
<!-- BEGIN 'History Settings' --> <!-- BEGIN 'History Settings' -->
<form action="muc-history-settings.jsp" method="post"> <form action="muc-history-settings.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" /> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="groupchat.history.settings.legend" /> <fmt:message key="groupchat.history.settings.legend" />
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
org.jivesoftware.openfire.group.GroupJID, org.jivesoftware.openfire.group.GroupJID,
org.jivesoftware.openfire.group.GroupManager, org.jivesoftware.openfire.group.GroupManager,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.StringUtils, org.jivesoftware.util.StringUtils,
org.xmpp.packet.IQ" org.xmpp.packet.IQ"
errorPage="error.jsp" errorPage="error.jsp"
...@@ -66,6 +67,18 @@ ...@@ -66,6 +67,18 @@
} }
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 (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 an add // Handle an add
if (add) { if (add) {
// do validation // do validation
...@@ -214,6 +227,7 @@ ...@@ -214,6 +227,7 @@
<% } %> <% } %>
<form action="muc-room-affiliations.jsp?add" method="post"> <form action="muc-room-affiliations.jsp?add" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="roomJID" value="<%= roomJID.toBareJID() %>"> <input type="hidden" name="roomJID" value="<%= roomJID.toBareJID() %>">
<fieldset> <fieldset>
...@@ -282,7 +296,7 @@ ...@@ -282,7 +296,7 @@
<%= StringUtils.escapeHTMLTags(userDisplay) %></a> <%= StringUtils.escapeHTMLTags(userDisplay) %></a>
</td> </td>
<td width="1%" align="center"> <td width="1%" align="center">
<a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=owner" <a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=owner&csrf=${csrf}"
title="<fmt:message key="global.click_delete" />" title="<fmt:message key="global.click_delete" />"
onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');" onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
><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>
...@@ -321,7 +335,7 @@ ...@@ -321,7 +335,7 @@
<%= StringUtils.escapeHTMLTags(userDisplay) %></a> <%= StringUtils.escapeHTMLTags(userDisplay) %></a>
</td> </td>
<td width="1%" align="center"> <td width="1%" align="center">
<a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=admin" <a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=admin&csrf=${csrf}"
title="<fmt:message key="global.click_delete" />" title="<fmt:message key="global.click_delete" />"
onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');" onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
><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>
...@@ -362,7 +376,7 @@ ...@@ -362,7 +376,7 @@
<%= StringUtils.escapeHTMLTags(userDisplay) %></a><%= StringUtils.escapeHTMLTags(nickname) %> <%= StringUtils.escapeHTMLTags(userDisplay) %></a><%= StringUtils.escapeHTMLTags(nickname) %>
</td> </td>
<td width="1%" align="center"> <td width="1%" align="center">
<a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=member" <a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=member&csrf=${csrf}"
title="<fmt:message key="global.click_delete" />" title="<fmt:message key="global.click_delete" />"
onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');" onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
><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>
...@@ -401,7 +415,7 @@ ...@@ -401,7 +415,7 @@
<%= StringUtils.escapeHTMLTags(userDisplay) %></a> <%= StringUtils.escapeHTMLTags(userDisplay) %></a>
</td> </td>
<td width="1%" align="center"> <td width="1%" align="center">
<a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=outcast" <a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= URLEncoder.encode(user.toString()) %>&delete=true&affiliation=outcast&csrf=${csrf}"
title="<fmt:message key="global.click_delete" />" title="<fmt:message key="global.click_delete" />"
onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');" onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
><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>
......
...@@ -33,6 +33,17 @@ ...@@ -33,6 +33,17 @@
<% // Get parameters // <% // Get parameters //
boolean cancel = request.getParameter("cancel") != null; boolean cancel = request.getParameter("cancel") != null;
boolean delete = request.getParameter("delete") != null; boolean delete = request.getParameter("delete") != null;
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);
JID roomJID = new JID(ParamUtils.getParameter(request,"roomJID")); JID roomJID = new JID(ParamUtils.getParameter(request,"roomJID"));
String alternateJIDString = ParamUtils.getParameter(request,"alternateJID"); String alternateJIDString = ParamUtils.getParameter(request,"alternateJID");
...@@ -93,6 +104,7 @@ ...@@ -93,6 +104,7 @@
</p> </p>
<form action="muc-room-delete.jsp"> <form action="muc-room-delete.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="roomJID" value="<%= StringUtils.escapeForXML(roomJID.toBareJID()) %>"> <input type="hidden" name="roomJID" value="<%= StringUtils.escapeForXML(roomJID.toBareJID()) %>">
<fieldset> <fieldset>
......
...@@ -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.text.DateFormat, java.text.DateFormat,
java.util.*, java.util.*,
org.jivesoftware.openfire.muc.MUCRoom, org.jivesoftware.openfire.muc.MUCRoom,
...@@ -105,6 +106,18 @@ ...@@ -105,6 +106,18 @@
// Handle an save // Handle an save
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) {
// do validation // do validation
...@@ -445,6 +458,7 @@ ...@@ -445,6 +458,7 @@
<% if (!create) { %> <% if (!create) { %>
<input type="hidden" name="roomJID" value="<%= StringUtils.escapeForXML(roomJID.toBareJID()) %>"> <input type="hidden" name="roomJID" value="<%= StringUtils.escapeForXML(roomJID.toBareJID()) %>">
<% } %> <% } %>
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="save" value="true"> <input type="hidden" name="save" value="true">
<input type="hidden" name="create" value="<%= create %>"> <input type="hidden" name="create" value="<%= create %>">
<input type="hidden" name="roomconfig_persistentroom" value="<%= persistentRoom %>"> <input type="hidden" name="roomconfig_persistentroom" value="<%= persistentRoom %>">
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
org.jivesoftware.openfire.muc.MUCRoom, org.jivesoftware.openfire.muc.MUCRoom,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils, org.jivesoftware.util.StringUtils,
org.jivesoftware.util.CookieUtils,
java.net.URLEncoder, java.net.URLEncoder,
java.text.DateFormat" java.text.DateFormat"
errorPage="error.jsp" errorPage="error.jsp"
...@@ -39,6 +40,17 @@ ...@@ -39,6 +40,17 @@
String nickName = ParamUtils.getParameter(request,"nickName"); String nickName = ParamUtils.getParameter(request,"nickName");
String kick = ParamUtils.getParameter(request,"kick"); String kick = ParamUtils.getParameter(request,"kick");
String roomName = roomJID.getNode(); String roomName = roomJID.getNode();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (kick != null) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
kick = null;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Load the room object // Load the room object
MUCRoom room = webManager.getMultiUserChatManager().getMultiUserChatService(roomJID).getChatRoom(roomName); MUCRoom room = webManager.getMultiUserChatManager().getMultiUserChatService(roomJID).getChatRoom(roomName);
...@@ -162,7 +174,7 @@ ...@@ -162,7 +174,7 @@
<td><%= StringUtils.escapeHTMLTags(role.getNickname().toString()) %></td> <td><%= StringUtils.escapeHTMLTags(role.getNickname().toString()) %></td>
<td><%= StringUtils.escapeHTMLTags(role.getRole().toString()) %></td> <td><%= StringUtils.escapeHTMLTags(role.getRole().toString()) %></td>
<td><%= StringUtils.escapeHTMLTags(role.getAffiliation().toString()) %></td> <td><%= StringUtils.escapeHTMLTags(role.getAffiliation().toString()) %></td>
<td><a href="muc-room-occupants.jsp?roomJID=<%= URLEncoder.encode(room.getJID().toBareJID(), "UTF-8") %>&nickName=<%= URLEncoder.encode(role.getNickname(), "UTF-8") %>&kick=1" title="<fmt:message key="muc.room.occupants.kick"/>"><img src="images/delete-16x16.gif" alt="<fmt:message key="muc.room.occupants.kick"/>" border="0" width="16" height="16"/></a></td> <td><a href="muc-room-occupants.jsp?roomJID=<%= URLEncoder.encode(room.getJID().toBareJID(), "UTF-8") %>&nickName=<%= URLEncoder.encode(role.getNickname(), "UTF-8") %>&kick=1&csrf=${csrf}" title="<fmt:message key="muc.room.occupants.kick"/>"><img src="images/delete-16x16.gif" alt="<fmt:message key="muc.room.occupants.kick"/>" border="0" width="16" height="16"/></a></td>
</tr> </tr>
<% } %> <% } %>
</tbody> </tbody>
......
...@@ -34,6 +34,17 @@ ...@@ -34,6 +34,17 @@
boolean delete = request.getParameter("delete") != null; boolean delete = request.getParameter("delete") != null;
String mucname = ParamUtils.getParameter(request,"mucname"); String mucname = ParamUtils.getParameter(request,"mucname");
String reason = ParamUtils.getParameter(request,"reason"); String reason = ParamUtils.getParameter(request,"reason");
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) {
...@@ -78,6 +89,7 @@ ...@@ -78,6 +89,7 @@
</p> </p>
<form action="muc-service-delete.jsp"> <form action="muc-service-delete.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>"> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>">
<fieldset> <fieldset>
......
...@@ -19,11 +19,13 @@ ...@@ -19,11 +19,13 @@
<%@ page import="org.jivesoftware.util.StringUtils, <%@ page import="org.jivesoftware.util.StringUtils,
org.jivesoftware.util.ParamUtils, org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.AlreadyExistsException, org.jivesoftware.util.AlreadyExistsException,
java.util.*" java.util.*"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
<%@ page import="java.net.URLEncoder" %> <%@ page import="java.net.URLEncoder" %>
<%@ page import="org.xmpp.packet.JID" %>
<%@ 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 @@
boolean success = request.getParameter("success") != null; boolean success = request.getParameter("success") != null;
String mucname = ParamUtils.getParameter(request,"mucname"); String mucname = ParamUtils.getParameter(request,"mucname");
String mucdesc = ParamUtils.getParameter(request,"mucdesc"); String mucdesc = ParamUtils.getParameter(request,"mucdesc");
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);
// Load the service object // Load the service object
if (!create && !webManager.getMultiUserChatManager().isServiceRegistered(mucname)) { if (!create && !webManager.getMultiUserChatManager().isServiceRegistered(mucname)) {
...@@ -66,6 +79,12 @@ ...@@ -66,6 +79,12 @@
// do validation // do validation
if (mucname == null || mucname.indexOf('.') >= 0 || mucname.length() < 1) { if (mucname == null || mucname.indexOf('.') >= 0 || mucname.length() < 1) {
errors.put("mucname","mucname"); errors.put("mucname","mucname");
} else {
try {
mucname = JID.domainprep(mucname);
} catch (Exception e) {
errors.put("mucname", e.getMessage());
}
} }
if (errors.size() == 0) { if (errors.size() == 0) {
if (!create) { if (!create) {
...@@ -146,6 +165,7 @@ ...@@ -146,6 +165,7 @@
<!-- BEGIN 'Service Name'--> <!-- BEGIN 'Service Name'-->
<form action="muc-service-edit-form.jsp" method="post"> <form action="muc-service-edit-form.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="save" value="true"> <input type="hidden" name="save" value="true">
<% if (!create) { %> <% if (!create) { %>
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>"> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>">
......
...@@ -200,7 +200,7 @@ ...@@ -200,7 +200,7 @@
<a href="muc-service-edit-form.jsp?mucname=<%= URLEncoder.encode(service.getServiceName(), "UTF-8") %>"><%= StringUtils.escapeHTMLTags(JID.unescapeNode(service.getServiceName())) %></a> <a href="muc-service-edit-form.jsp?mucname=<%= URLEncoder.encode(service.getServiceName(), "UTF-8") %>"><%= StringUtils.escapeHTMLTags(JID.unescapeNode(service.getServiceName())) %></a>
</td> </td>
<td width="33%"> <td width="33%">
<%= service.getDescription() %> &nbsp; <%= StringUtils.escapeHTMLTags(service.getDescription()) %> &nbsp;
</td> </td>
<td width="5%"> <td width="5%">
<a href="muc-room-summary.jsp?mucname==<%= URLEncoder.encode(service.getServiceName(), "UTF-8") %>"><%= service.getNumberChatRooms() %></a> <a href="muc-room-summary.jsp?mucname==<%= URLEncoder.encode(service.getServiceName(), "UTF-8") %>"><%= service.getNumberChatRooms() %></a>
......
...@@ -52,6 +52,19 @@ ...@@ -52,6 +52,19 @@
// Handle a save // Handle a save
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 (add || delete) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
add = false;
delete = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
List<JID> allowedJIDs = new ArrayList<JID>(); List<JID> allowedJIDs = new ArrayList<JID>();
try { try {
if (userJID != null && userJID.trim().length() > 0) { if (userJID != null && userJID.trim().length() > 0) {
...@@ -163,6 +176,7 @@ ...@@ -163,6 +176,7 @@
<!-- BEGIN 'Administrators' --> <!-- BEGIN 'Administrators' -->
<form action="muc-sysadmins.jsp?add" method="post"> <form action="muc-sysadmins.jsp?add" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" /> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="groupchat.admins.legend" /> <fmt:message key="groupchat.admins.legend" />
......
...@@ -51,6 +51,19 @@ ...@@ -51,6 +51,19 @@
MultiUserChatService mucService = webManager.getMultiUserChatManager().getMultiUserChatService(mucname); MultiUserChatService mucService = webManager.getMultiUserChatManager().getMultiUserChatService(mucname);
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 (kickSettings || logSettings) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
kickSettings = false;
logSettings = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle an update of the kicking task settings // Handle an update of the kicking task settings
if (kickSettings) { if (kickSettings) {
if (!kickEnabled) { if (!kickEnabled) {
...@@ -187,6 +200,7 @@ ...@@ -187,6 +200,7 @@
<!-- BEGIN 'Idle User Settings' --> <!-- BEGIN 'Idle User Settings' -->
<form action="muc-tasks.jsp?kickSettings" method="post"> <form action="muc-tasks.jsp?kickSettings" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" /> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="muc.tasks.user_setting" /> <fmt:message key="muc.tasks.user_setting" />
...@@ -228,6 +242,7 @@ ...@@ -228,6 +242,7 @@
<!-- BEGIN 'Conversation Logging' --> <!-- BEGIN 'Conversation Logging' -->
<form action="muc-tasks.jsp?logSettings" method="post"> <form action="muc-tasks.jsp?logSettings" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" /> <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="muc.tasks.conversation.logging" /> <fmt:message key="muc.tasks.conversation.logging" />
......
...@@ -62,6 +62,18 @@ ...@@ -62,6 +62,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 (strategy != BOUNCE && strategy != DROP && strategy != STORE) { if (strategy != BOUNCE && strategy != DROP && strategy != STORE) {
...@@ -199,6 +211,7 @@ ...@@ -199,6 +211,7 @@
<!-- BEGIN 'Offline Message Policy' --> <!-- BEGIN 'Offline Message Policy' -->
<form action="offline-messages.jsp"> <form action="offline-messages.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="offline.messages.policy" /> <fmt:message key="offline.messages.policy" />
</div> </div>
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
--%> --%>
<%@ page import="org.jivesoftware.util.ParamUtils, <%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.StringUtils,
org.jivesoftware.openfire.XMPPServer, org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.container.Plugin, org.jivesoftware.openfire.container.Plugin,
org.jivesoftware.openfire.container.PluginManager, org.jivesoftware.openfire.container.PluginManager,
...@@ -50,12 +52,22 @@ ...@@ -50,12 +52,22 @@
boolean uploadPlugin = request.getParameter("uploadplugin") != null; boolean uploadPlugin = request.getParameter("uploadplugin") != null;
String url = request.getParameter("url"); String url = request.getParameter("url");
Boolean uploadEnabled = JiveGlobals.getBooleanProperty("plugins.upload.enabled", true); Boolean uploadEnabled = JiveGlobals.getBooleanProperty("plugins.upload.enabled", true);
boolean csrf_check = true;
final PluginManager pluginManager = webManager.getXMPPServer().getPluginManager(); final PluginManager pluginManager = webManager.getXMPPServer().getPluginManager();
List<Plugin> plugins = new ArrayList<Plugin>(pluginManager.getPlugins()); List<Plugin> plugins = new ArrayList<Plugin>(pluginManager.getPlugins());
UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager(); UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
csrf_check = false;
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
if (plugins != null) { if (plugins != null) {
Collections.sort(plugins, new Comparator<Plugin>() { Collections.sort(plugins, new Comparator<Plugin>() {
...@@ -65,14 +77,14 @@ ...@@ -65,14 +77,14 @@
}); });
} }
if (downloadRequested) { if (csrf_check && downloadRequested) {
// Download and install new version of plugin // Download and install new version of plugin
updateManager.downloadPlugin(url); updateManager.downloadPlugin(url);
// Log the event // Log the event
webManager.logEvent("downloaded plugin from "+url, null); webManager.logEvent("downloaded plugin from "+url, null);
} }
if (deletePlugin != null) { if (csrf_check && deletePlugin != null) {
File pluginDir = pluginManager.getPluginDirectory(pluginManager.getPlugin(deletePlugin)); File pluginDir = pluginManager.getPluginDirectory(pluginManager.getPlugin(deletePlugin));
File pluginJar = new File(pluginDir.getParent(), pluginDir.getName() + ".jar"); File pluginJar = new File(pluginDir.getParent(), pluginDir.getName() + ".jar");
// Also try the .war extension. // Also try the .war extension.
...@@ -87,7 +99,7 @@ ...@@ -87,7 +99,7 @@
return; return;
} }
if (reloadPlugin != null) { if (csrf_check && reloadPlugin != null) {
for (Plugin plugin : plugins) { for (Plugin plugin : plugins) {
File pluginDir = pluginManager.getPluginDirectory(plugin); File pluginDir = pluginManager.getPluginDirectory(plugin);
if (reloadPlugin.equals(pluginDir.getName())) { if (reloadPlugin.equals(pluginDir.getName())) {
...@@ -100,7 +112,7 @@ ...@@ -100,7 +112,7 @@
} }
} }
if (uploadEnabled && uploadPlugin) { if (csrf_check && uploadEnabled && uploadPlugin) {
Boolean installed = false; Boolean installed = false;
// Create a factory for disk-based file items // Create a factory for disk-based file items
...@@ -557,7 +569,7 @@ else if ("false".equals(request.getParameter("uploadsuccess"))) { %> ...@@ -557,7 +569,7 @@ else if ("false".equals(request.getParameter("uploadsuccess"))) { %>
><img src="images/refresh-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.refresh" />"></a> ><img src="images/refresh-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.refresh" />"></a>
</td> </td>
<td width="1%" align="center" valign="top" class="<%= update != null ? "update-right" : "line-bottom-border"%>"> <td width="1%" align="center" valign="top" class="<%= update != null ? "update-right" : "line-bottom-border"%>">
<a href="#" onclick="if (confirm('<fmt:message key="plugin.admin.confirm" />')) { location.replace('plugin-admin.jsp?deleteplugin=<%= dirName %>'); } " <a href="#" onclick="if (confirm('<fmt:message key="plugin.admin.confirm" />')) { location.replace('plugin-admin.jsp?csrf=${csrf}&deleteplugin=<%= dirName %>'); } "
title="<fmt:message key="global.click_delete" />" title="<fmt:message key="global.click_delete" />"
><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.delete" />"></a> ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.delete" />"></a>
</td> </td>
...@@ -570,7 +582,7 @@ else if ("false".equals(request.getParameter("uploadsuccess"))) { %> ...@@ -570,7 +582,7 @@ else if ("false".equals(request.getParameter("uploadsuccess"))) { %>
String updateURL = update.getURL(); String updateURL = update.getURL();
if (updateURL.endsWith(".jar") || updateURL.endsWith(".zip") || updateURL.endsWith(".war")) { if (updateURL.endsWith(".jar") || updateURL.endsWith(".zip") || updateURL.endsWith(".war")) {
// Change it so that the server downloads and installs the new version of the plugin // Change it so that the server downloads and installs the new version of the plugin
updateURL = "plugin-admin.jsp?download=true&url=" + updateURL; updateURL = "plugin-admin.jsp?csrf=" + csrfParam + "download=true&url=" + updateURL;
} }
%> %>
<tr id="<%= update.hashCode() %>-row"> <tr id="<%= update.hashCode() %>-row">
...@@ -633,6 +645,7 @@ else if ("false".equals(request.getParameter("uploadsuccess"))) { %> ...@@ -633,6 +645,7 @@ else if ("false".equals(request.getParameter("uploadsuccess"))) { %>
<h3><fmt:message key="plugin.admin.upload_plugin" /></h3> <h3><fmt:message key="plugin.admin.upload_plugin" /></h3>
<p><fmt:message key="plugin.admin.upload_plugin.info" /></p> <p><fmt:message key="plugin.admin.upload_plugin.info" /></p>
<form action="plugin-admin.jsp?uploadplugin" enctype="multipart/form-data" method="post"> <form action="plugin-admin.jsp?uploadplugin" enctype="multipart/form-data" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="file" name="uploadfile" /> <input type="file" name="uploadfile" />
<input type="submit" value="<fmt:message key="plugin.admin.upload_plugin" />" /> <input type="submit" value="<fmt:message key="plugin.admin.upload_plugin" />" />
</form> </form>
......
...@@ -39,6 +39,17 @@ ...@@ -39,6 +39,17 @@
<% // Get parameters: <% // Get parameters:
boolean update = request.getParameter("update") != null; boolean update = request.getParameter("update") != null;
boolean privateEnabled = ParamUtils.getBooleanParameter(request,"privateEnabled"); boolean privateEnabled = ParamUtils.getBooleanParameter(request,"privateEnabled");
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);
// Get an audit manager: // Get an audit manager:
PrivateStorage privateStorage = webManager.getPrivateStore(); PrivateStorage privateStorage = webManager.getPrivateStore();
...@@ -72,6 +83,7 @@ ...@@ -72,6 +83,7 @@
<!-- BEGIN 'Set Private Data Policy' --> <!-- BEGIN 'Set Private Data Policy' -->
<form action="private-data-settings.jsp"> <form action="private-data-settings.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="private.data.settings.policy" /> <fmt:message key="private.data.settings.policy" />
</div> </div>
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
<%@ page import="org.jivesoftware.openfire.XMPPServer, <%@ page import="org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.handler.IQRegisterHandler, org.jivesoftware.openfire.handler.IQRegisterHandler,
org.jivesoftware.openfire.session.LocalClientSession, org.jivesoftware.openfire.session.LocalClientSession,
org.jivesoftware.util.CookieUtils,
org.jivesoftware.util.StringUtils,
org.jivesoftware.util.ParamUtils" org.jivesoftware.util.ParamUtils"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -51,6 +53,17 @@ ...@@ -51,6 +53,17 @@
String blockedIPs = request.getParameter("blockedIPs"); String blockedIPs = request.getParameter("blockedIPs");
// Get an IQRegisterHandler: // Get an IQRegisterHandler:
IQRegisterHandler regHandler = XMPPServer.getInstance().getIQRegisterHandler(); IQRegisterHandler regHandler = XMPPServer.getInstance().getIQRegisterHandler();
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);
if (save) { if (save) {
regHandler.setInbandRegEnabled(inbandEnabled); regHandler.setInbandRegEnabled(inbandEnabled);
...@@ -138,6 +151,7 @@ ...@@ -138,6 +151,7 @@
</p> </p>
<form action="reg-settings.jsp"> <form action="reg-settings.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<% if (save) { %> <% if (save) { %>
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
<%@ page import="org.jivesoftware.openfire.keystore.CertificateStoreConfiguration" %> <%@ page import="org.jivesoftware.openfire.keystore.CertificateStoreConfiguration" %>
<%@ page import="java.io.File" %> <%@ page import="java.io.File" %>
<%@ page import="org.jivesoftware.util.Log" %> <%@ page import="org.jivesoftware.util.Log" %>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ taglib uri="admin" prefix="admin" %> <%@ taglib uri="admin" prefix="admin" %>
<%@ 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" %>
...@@ -23,7 +26,19 @@ ...@@ -23,7 +26,19 @@
pageContext.setAttribute( "connectionTypes", ConnectionType.values() ); pageContext.setAttribute( "connectionTypes", ConnectionType.values() );
pageContext.setAttribute( "certificateStoreManager", certificateStoreManager ); pageContext.setAttribute( "certificateStoreManager", certificateStoreManager );
final boolean update = request.getParameter("update") != null; boolean update = request.getParameter("update") != null;
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 ) {
ConnectionType connectionType = null; ConnectionType connectionType = null;
try { try {
...@@ -130,6 +145,7 @@ ...@@ -130,6 +145,7 @@
</c:set> </c:set>
<form action="security-certificate-store-management.jsp" method="post"> <form action="security-certificate-store-management.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="connectionType" value="${connectionType}"/> <input type="hidden" name="connectionType" value="${connectionType}"/>
<admin:contentBox title="${title}"> <admin:contentBox title="${title}">
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<%@page import="org.bouncycastle.asn1.x509.Extension"%> <%@page import="org.bouncycastle.asn1.x509.Extension"%>
<%@page import="org.bouncycastle.asn1.x500.X500NameBuilder"%> <%@page import="org.bouncycastle.asn1.x500.X500NameBuilder"%>
<%@page import="org.jivesoftware.util.CertificateManager"%> <%@page import="org.jivesoftware.util.CertificateManager"%>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ 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="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
...@@ -27,7 +28,7 @@ ...@@ -27,7 +28,7 @@
String domain = XMPPServer.getInstance().getServerInfo().getXMPPDomain(); String domain = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
// Get parameters: // Get parameters:
final boolean save = ParamUtils.getParameter(request, "save") != null; boolean save = ParamUtils.getParameter(request, "save") != null;
final String name = domain; final String name = domain;
final String organizationalUnit = ParamUtils.getParameter(request, "ou"); final String organizationalUnit = ParamUtils.getParameter(request, "ou");
final String organization = ParamUtils.getParameter(request, "o"); final String organization = ParamUtils.getParameter(request, "o");
...@@ -37,6 +38,18 @@ ...@@ -37,6 +38,18 @@
final String connectionTypeText = ParamUtils.getParameter( request, "connectionType" ); final String connectionTypeText = ParamUtils.getParameter( request, "connectionType" );
final Map<String, String> errors = new HashMap<String, String>(); final 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);
ConnectionType connectionType = null; ConnectionType connectionType = null;
IdentityStore identityStore = null; IdentityStore identityStore = null;
...@@ -160,6 +173,7 @@ ...@@ -160,6 +173,7 @@
<!-- BEGIN 'Issuer information form' --> <!-- BEGIN 'Issuer information form' -->
<form action="security-keystore-signing-request.jsp" method="post"> <form action="security-keystore-signing-request.jsp" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="save" value="true"> <input type="hidden" name="save" value="true">
<input type="hidden" name="connectionType" value="${connectionType}"> <input type="hidden" name="connectionType" value="${connectionType}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
<%@page import="java.util.LinkedHashMap"%> <%@page import="java.util.LinkedHashMap"%>
<%@page import="java.security.PrivateKey"%> <%@page import="java.security.PrivateKey"%>
<%@page import="org.jivesoftware.util.CertificateManager"%> <%@page import="org.jivesoftware.util.CertificateManager"%>
<%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ page errorPage="error.jsp" %> <%@ page errorPage="error.jsp" %>
<%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %>
...@@ -25,13 +27,27 @@ ...@@ -25,13 +27,27 @@
<% webManager.init(request, response, session, application, out); %> <% webManager.init(request, response, session, application, out); %>
<% // Get parameters: <% // Get parameters:
final boolean generate = ParamUtils.getBooleanParameter(request, "generate"); boolean generate = ParamUtils.getBooleanParameter(request, "generate");
final boolean delete = ParamUtils.getBooleanParameter(request, "delete"); boolean delete = ParamUtils.getBooleanParameter(request, "delete");
final boolean importReply = ParamUtils.getBooleanParameter(request, "importReply"); boolean importReply = ParamUtils.getBooleanParameter(request, "importReply");
final String alias = ParamUtils.getParameter( request, "alias" ); final String alias = ParamUtils.getParameter( request, "alias" );
final String connectionTypeText = ParamUtils.getParameter( request, "connectionType" ); final String connectionTypeText = ParamUtils.getParameter( request, "connectionType" );
final Map<String, String> errors = new HashMap<>(); final Map<String, String> errors = new HashMap<>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (generate | delete | importReply) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
generate = false;
delete = false;
importReply = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
ConnectionType connectionType = null; ConnectionType connectionType = null;
IdentityStore identityStore = null; IdentityStore identityStore = null;
...@@ -174,7 +190,7 @@ ...@@ -174,7 +190,7 @@
<c:if test="${not validDSACert or not validRSACert}"> <c:if test="${not validDSACert or not validRSACert}">
<admin:infobox type="warning"> <admin:infobox type="warning">
<fmt:message key="ssl.certificates.keystore.no_installed"> <fmt:message key="ssl.certificates.keystore.no_installed">
<fmt:param value="<a href='security-keystore.jsp?generate=true&connectionType=${connectionType}'>"/> <fmt:param value="<a href='security-keystore.jsp?csrf=${csrf}&generate=true&connectionType=${connectionType}'>"/>
<fmt:param value="</a>"/> <fmt:param value="</a>"/>
<fmt:param value="<a href='import-keystore-certificate.jsp?connectionType=${connectionType}'>"/> <fmt:param value="<a href='import-keystore-certificate.jsp?connectionType=${connectionType}'>"/>
<fmt:param value="</a>"/> <fmt:param value="</a>"/>
...@@ -305,7 +321,7 @@ ...@@ -305,7 +321,7 @@
<c:out value="${certificate.publicKey.algorithm}"/> <c:out value="${certificate.publicKey.algorithm}"/>
</td> </td>
<td width="1" align="center"> <td width="1" align="center">
<a href="security-keystore.jsp?alias=${alias}&connectionType=${connectionType}&delete=true" <a href="security-keystore.jsp?csrf=${csrf}&alias=${alias}&connectionType=${connectionType}&delete=true"
title="<fmt:message key="global.click_delete"/>" title="<fmt:message key="global.click_delete"/>"
onclick="return confirm('<fmt:message key="ssl.certificates.confirm_delete"/>');" onclick="return confirm('<fmt:message key="ssl.certificates.confirm_delete"/>');"
><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>
...@@ -314,6 +330,7 @@ ...@@ -314,6 +330,7 @@
<% if (isSigningPending) { %> <% if (isSigningPending) { %>
<form action="security-keystore.jsp?connectionType=${connectionType}" method="post"> <form action="security-keystore.jsp?connectionType=${connectionType}" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="importReply" value="true"> <input type="hidden" name="importReply" value="true">
<input type="hidden" name="alias" value="${alias}"> <input type="hidden" name="alias" value="${alias}">
<tr> <tr>
......
<%@ page errorPage="error.jsp"%> <%@ page errorPage="error.jsp"%>
<%@ page import="org.jivesoftware.openfire.keystore.TrustStore"%> <%@ page import="org.jivesoftware.openfire.keystore.TrustStore"%>
<%@ page import="org.jivesoftware.openfire.spi.ConnectionType"%> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%> <%@ page import="org.jivesoftware.util.CookieUtils" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.util.StringUtils" %>
<%@ page import="java.util.Collections" %> <%@ page import="java.util.Collections" %>
<%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %> <%@ page import="java.util.Map" %>
...@@ -17,12 +19,24 @@ ...@@ -17,12 +19,24 @@
<jsp:useBean id="now" class="java.util.Date"/> <jsp:useBean id="now" class="java.util.Date"/>
<% webManager.init(request, response, session, application, out ); <% webManager.init(request, response, session, application, out );
final boolean delete = ParamUtils.getBooleanParameter( request, "delete" ); boolean delete = ParamUtils.getBooleanParameter( request, "delete" );
final String alias = ParamUtils.getParameter( request, "alias" ); final String alias = ParamUtils.getParameter( request, "alias" );
final String connectionTypeText = ParamUtils.getParameter( request, "connectionType" ); final String connectionTypeText = ParamUtils.getParameter( request, "connectionType" );
final Map<String, String> errors = new HashMap<>(); final Map<String, String> errors = new HashMap<>();
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;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
ConnectionType connectionType = null; ConnectionType connectionType = null;
TrustStore trustStore = null; TrustStore trustStore = null;
...@@ -207,7 +221,7 @@ ...@@ -207,7 +221,7 @@
<c:out value="${certificate.publicKey.algorithm}"/> <c:out value="${certificate.publicKey.algorithm}"/>
</td> </td>
<td width="1" align="center"> <td width="1" align="center">
<a href="security-truststore.jsp?connectionType=${connectionType}&alias=${alias}&delete=true" <a href="security-truststore.jsp?connectionType=${connectionType}&alias=${alias}&delete=true&csrf=csrf"
title="<fmt:message key="global.click_delete"/>" title="<fmt:message key="global.click_delete"/>"
onclick="return confirm('<fmt:message key="ssl.certificates.confirm_delete"/>');" onclick="return confirm('<fmt:message key="ssl.certificates.confirm_delete"/>');"
><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>
......
...@@ -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>
......
...@@ -45,8 +45,20 @@ ...@@ -45,8 +45,20 @@
String password = ParamUtils.getParameter(request,"password"); String password = ParamUtils.getParameter(request,"password");
String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm"); String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm");
boolean isAdmin = ParamUtils.getBooleanParameter(request,"isadmin"); boolean isAdmin = ParamUtils.getBooleanParameter(request,"isadmin");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
Map<String, String> errors = new HashMap<String, String>(); Map<String, String> errors = new HashMap<String, String>();
if (create) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
create = false;
errors.put("csrf", "CSRF Failure!");
}
}
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-summary.jsp"); response.sendRedirect("user-summary.jsp");
...@@ -203,6 +215,7 @@ ...@@ -203,6 +215,7 @@
<% } %> <% } %>
<form name="f" action="user-create.jsp" method="get"> <form name="f" action="user-create.jsp" method="get">
<input type="hidden" name="csrf" value="${csrf}">
<div class="jive-contentBoxHeader"> <div class="jive-contentBoxHeader">
<fmt:message key="user.create.new_user" /> <fmt:message key="user.create.new_user" />
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<%@ page import="org.jivesoftware.openfire.user.UserManager" %> <%@ page import="org.jivesoftware.openfire.user.UserManager" %>
<%@ 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.StreamError" %> <%@ page import="org.xmpp.packet.StreamError" %>
<%@ page import="java.net.URLEncoder" %> <%@ page import="java.net.URLEncoder" %>
...@@ -39,6 +40,17 @@ ...@@ -39,6 +40,17 @@
boolean cancel = request.getParameter("cancel") != null; boolean cancel = request.getParameter("cancel") != null;
boolean delete = request.getParameter("delete") != null; boolean delete = request.getParameter("delete") != null;
String username = ParamUtils.getParameter(request,"username"); String username = ParamUtils.getParameter(request,"username");
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) {
...@@ -107,6 +119,7 @@ ...@@ -107,6 +119,7 @@
</c:if> </c:if>
<form action="user-delete.jsp"> <form action="user-delete.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="submit" name="delete" value="<fmt:message key="user.delete.delete" />"> <input type="submit" name="delete" value="<fmt:message key="user.delete.delete" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />"> <input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
......
...@@ -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,
org.jivesoftware.openfire.user.*, org.jivesoftware.openfire.user.*,
java.net.URLEncoder" java.net.URLEncoder"
errorPage="error.jsp" errorPage="error.jsp"
...@@ -42,6 +43,17 @@ ...@@ -42,6 +43,17 @@
String email = ParamUtils.getParameter(request,"email"); String email = ParamUtils.getParameter(request,"email");
boolean isAdmin = ParamUtils.getBooleanParameter(request,"isadmin"); boolean isAdmin = ParamUtils.getBooleanParameter(request,"isadmin");
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);
// Handle a cancel // Handle a cancel
if (request.getParameter("cancel") != null) { if (request.getParameter("cancel") != null) {
...@@ -113,6 +125,8 @@ ...@@ -113,6 +125,8 @@
<fmt:message key="user.create.invalid_name" /> <fmt:message key="user.create.invalid_name" />
<% } else if (errors.get("email") != null) { %> <% } else if (errors.get("email") != null) { %>
<fmt:message key="user.create.invalid_email" /> <fmt:message key="user.create.invalid_email" />
<% } else if (errors.get("csrf") != null) { %>
CSRF Failure!
<% } %> <% } %>
</td> </td>
</tr> </tr>
...@@ -142,6 +156,7 @@ ...@@ -142,6 +156,7 @@
<form action="user-edit-form.jsp"> <form action="user-edit-form.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="save" value="true"> <input type="hidden" name="save" value="true">
......
...@@ -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>
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<%@ page import="org.jivesoftware.openfire.session.ClientSession" %> <%@ page import="org.jivesoftware.openfire.session.ClientSession" %>
<%@ 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.StreamError" %> <%@ page import="org.xmpp.packet.StreamError" %>
<%@ page import="java.net.URLEncoder" %> <%@ page import="java.net.URLEncoder" %>
...@@ -50,6 +51,17 @@ ...@@ -50,6 +51,17 @@
if (duration == -2) { if (duration == -2) {
duration = ParamUtils.getIntParameter(request,"duration_custom", -1); duration = ParamUtils.getIntParameter(request,"duration_custom", -1);
} }
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (lock || unlock) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
lock = false;
unlock = 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) {
...@@ -146,6 +158,7 @@ ...@@ -146,6 +158,7 @@
<form action="user-lockout.jsp"> <form action="user-lockout.jsp">
<input type="hidden" name="username" value="${usernameHtmlEscaped}"> <input type="hidden" name="username" value="${usernameHtmlEscaped}">
<input type="hidden" name="csrf" value="${csrf}">
<input type="submit" name="unlock" value="<fmt:message key="user.lockout.unlock" />"> <input type="submit" name="unlock" value="<fmt:message key="user.lockout.unlock" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />"> <input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
</form> </form>
...@@ -169,6 +182,7 @@ ...@@ -169,6 +182,7 @@
</c:if> </c:if>
<form action="user-lockout.jsp"> <form action="user-lockout.jsp">
<input type="hidden" name="csrf" value="${csrf}">
<% if (LockOutManager.getLockOutProvider().isDelayedStartSupported()) { %> <% if (LockOutManager.getLockOutProvider().isDelayedStartSupported()) { %>
<b><fmt:message key="user.lockout.time.startdelay" /></b><br /> <b><fmt:message key="user.lockout.time.startdelay" /></b><br />
<input type="radio" name="startdelay" value="-1" checked="checked" /> <fmt:message key="user.lockout.time.immediate" /><br /> <input type="radio" name="startdelay" value="-1" checked="checked" /> <fmt:message key="user.lockout.time.immediate" /><br />
......
...@@ -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) %>">
<% } %> <% } %>
......
...@@ -35,6 +35,17 @@ ...@@ -35,6 +35,17 @@
String username = ParamUtils.getParameter(request,"username"); String username = ParamUtils.getParameter(request,"username");
String password = ParamUtils.getParameter(request,"password"); String password = ParamUtils.getParameter(request,"password");
String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm"); String passwordConfirm = ParamUtils.getParameter(request,"passwordConfirm");
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);
// Handle a cancel // Handle a cancel
if (cancel) { if (cancel) {
...@@ -133,6 +144,7 @@ ...@@ -133,6 +144,7 @@
<form action="user-password.jsp" name="passform" method="post"> <form action="user-password.jsp" name="passform" method="post">
<input type="hidden" name="username" value="<%=StringUtils.escapeForXML(username) %>"> <input type="hidden" name="username" value="<%=StringUtils.escapeForXML(username) %>">
<input type="hidden" name="csrf" value="${csrf}">
<fieldset> <fieldset>
<legend><fmt:message key="user.password.change" /></legend> <legend><fmt:message key="user.password.change" /></legend>
......
...@@ -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