#1104 Whitelist sensitive commands also when used with "authme:" prefix

This commit is contained in:
ljacqu
2017-02-21 22:51:45 +01:00
parent ee51bb3971
commit 4edb4e68c2
4 changed files with 40 additions and 18 deletions
@@ -3,6 +3,10 @@ package fr.xephi.authme.output;
import com.google.common.annotations.VisibleForTesting;
import fr.xephi.authme.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Service class for the log filters.
*/
@@ -11,11 +15,10 @@ final class LogFilterHelper {
private static final String ISSUED_COMMAND_TEXT = "issued server command:";
@VisibleForTesting
static final String[] COMMANDS_TO_SKIP = {
static final List<String> COMMANDS_TO_SKIP = withAndWithoutAuthMePrefix(
"/login ", "/l ", "/log ", "/register ", "/reg ", "/unregister ", "/unreg ",
"/changepassword ", "/cp ", "/changepass ", "/authme register ", "/authme reg ", "/authme r ",
"/authme changepassword ", "/authme password ", "/authme changepass ", "/authme cp "
};
"/authme changepassword ", "/authme password ", "/authme changepass ", "/authme cp ");
private LogFilterHelper() {
// Util class
@@ -35,4 +38,13 @@ final class LogFilterHelper {
String lowerMessage = message.toLowerCase();
return lowerMessage.contains(ISSUED_COMMAND_TEXT) && StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP);
}
private static List<String> withAndWithoutAuthMePrefix(String... commands) {
List<String> commandList = new ArrayList<>(commands.length * 2);
for (String command : commands) {
commandList.add(command);
commandList.add(command.substring(0, 1) + "authme:" + command.substring(1));
}
return Collections.unmodifiableList(commandList);
}
}
@@ -42,7 +42,7 @@ public final class StringUtils {
*
* @return True if the string contains at least one of the items
*/
public static boolean containsAny(String str, String... pieces) {
public static boolean containsAny(String str, Iterable<String> pieces) {
if (str == null) {
return false;
}