Make console detection more resilient against spoofed UUIDs

This commit is contained in:
Luck 2021-03-13 14:25:33 +00:00
parent 53bb61f9b2
commit e3138eb94c
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
12 changed files with 55 additions and 11 deletions

View File

@ -94,6 +94,11 @@ public class BukkitSenderFactory extends SenderFactory<LPBukkitPlugin, CommandSe
getPlugin().getBootstrap().getServer().dispatchCommand(sender, command); getPlugin().getBootstrap().getServer().dispatchCommand(sender, command);
} }
@Override
protected boolean isConsole(CommandSender sender) {
return sender instanceof ConsoleCommandSender;
}
@Override @Override
public void close() { public void close() {
super.close(); super.close();

View File

@ -81,6 +81,11 @@ public class BungeeSenderFactory extends SenderFactory<LPBungeePlugin, CommandSe
getPlugin().getBootstrap().getProxy().getPluginManager().dispatchCommand(sender, command); getPlugin().getBootstrap().getProxy().getPluginManager().dispatchCommand(sender, command);
} }
@Override
protected boolean isConsole(CommandSender sender) {
return !(sender instanceof ProxiedPlayer);
}
@Override @Override
public void close() { public void close() {
super.close(); super.close();

View File

@ -52,6 +52,7 @@ public final class AbstractSender<T> implements Sender {
private final UUID uniqueId; private final UUID uniqueId;
private final String name; private final String name;
private final boolean isConsole;
AbstractSender(LuckPermsPlugin plugin, SenderFactory<?, T> factory, T sender) { AbstractSender(LuckPermsPlugin plugin, SenderFactory<?, T> factory, T sender) {
this.plugin = plugin; this.plugin = plugin;
@ -59,6 +60,7 @@ public final class AbstractSender<T> implements Sender {
this.sender = sender; this.sender = sender;
this.uniqueId = factory.getUniqueId(this.sender); this.uniqueId = factory.getUniqueId(this.sender);
this.name = factory.getName(this.sender); this.name = factory.getName(this.sender);
this.isConsole = this.factory.isConsole(this.sender);
} }
@Override @Override
@ -102,6 +104,11 @@ public final class AbstractSender<T> implements Sender {
this.factory.performCommand(this.sender, commandLine); this.factory.performCommand(this.sender, commandLine);
} }
@Override
public boolean isConsole() {
return this.isConsole;
}
@Override @Override
public boolean isValid() { public boolean isValid() {
return isConsole() || this.plugin.getBootstrap().isPlayerOnline(this.uniqueId); return isConsole() || this.plugin.getBootstrap().isPlayerOnline(this.uniqueId);

View File

@ -31,16 +31,16 @@ import net.luckperms.api.util.Tristate;
import java.util.UUID; import java.util.UUID;
public abstract class DummySender implements Sender { public abstract class DummyConsoleSender implements Sender {
private final LuckPermsPlugin platform; private final LuckPermsPlugin platform;
private final UUID uniqueId; private final UUID uniqueId;
private final String name; private final String name;
public DummySender(LuckPermsPlugin plugin, UUID uniqueId, String name) { public DummyConsoleSender(LuckPermsPlugin plugin) {
this.platform = plugin; this.platform = plugin;
this.uniqueId = uniqueId; this.uniqueId = Sender.CONSOLE_UUID;
this.name = name; this.name = Sender.CONSOLE_NAME;
} }
@Override @Override
@ -58,6 +58,11 @@ public abstract class DummySender implements Sender {
} }
@Override
public boolean isConsole() {
return true;
}
@Override @Override
public LuckPermsPlugin getPlugin() { public LuckPermsPlugin getPlugin() {
return this.platform; return this.platform;

View File

@ -149,9 +149,7 @@ public interface Sender {
* *
* @return if the sender is the console * @return if the sender is the console
*/ */
default boolean isConsole() { boolean isConsole();
return CONSOLE_UUID.equals(getUniqueId());
}
/** /**
* Gets whether this sender is still valid & receiving messages. * Gets whether this sender is still valid & receiving messages.

View File

@ -62,6 +62,8 @@ public abstract class SenderFactory<P extends LuckPermsPlugin, T> implements Aut
protected abstract void performCommand(T sender, String command); protected abstract void performCommand(T sender, String command);
protected abstract boolean isConsole(T sender);
public final Sender wrap(T sender) { public final Sender wrap(T sender) {
Objects.requireNonNull(sender, "sender"); Objects.requireNonNull(sender, "sender");
return new AbstractSender<>(this.plugin, this, sender); return new AbstractSender<>(this.plugin, this, sender);

View File

@ -104,6 +104,11 @@ public class FabricSenderFactory extends SenderFactory<LPFabricPlugin, ServerCom
sender.getMinecraftServer().getCommandManager().execute(sender, command); sender.getMinecraftServer().getCommandManager().execute(sender, command);
} }
@Override
protected boolean isConsole(ServerCommandSource sender) {
return sender.getEntity() == null;
}
public static Text toNativeText(Component component) { public static Text toNativeText(Component component) {
return Text.Serializer.fromJson(GsonComponentSerializer.gson().serialize(component)); return Text.Serializer.fromJson(GsonComponentSerializer.gson().serialize(component));
} }

View File

@ -38,7 +38,7 @@ import me.lucko.luckperms.common.model.manager.group.StandardGroupManager;
import me.lucko.luckperms.common.model.manager.track.StandardTrackManager; import me.lucko.luckperms.common.model.manager.track.StandardTrackManager;
import me.lucko.luckperms.common.model.manager.user.StandardUserManager; import me.lucko.luckperms.common.model.manager.user.StandardUserManager;
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin; import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
import me.lucko.luckperms.common.sender.DummySender; import me.lucko.luckperms.common.sender.DummyConsoleSender;
import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
@ -221,7 +221,7 @@ public class LPFabricPlugin extends AbstractLuckPermsPlugin {
public Sender getConsoleSender() { public Sender getConsoleSender() {
return this.bootstrap.getServer() return this.bootstrap.getServer()
.map(s -> this.senderFactory.wrap(s.getCommandSource())) .map(s -> this.senderFactory.wrap(s.getCommandSource()))
.orElseGet(() -> new DummySender(this, Sender.CONSOLE_UUID, Sender.CONSOLE_NAME) { .orElseGet(() -> new DummyConsoleSender(this) {
@Override @Override
public void sendMessage(Component message) { public void sendMessage(Component message) {
LPFabricPlugin.this.bootstrap.getPluginLogger().info(PlainComponentSerializer.plain().serialize(TranslationManager.render(message))); LPFabricPlugin.this.bootstrap.getPluginLogger().info(PlainComponentSerializer.plain().serialize(TranslationManager.render(message)));

View File

@ -35,6 +35,7 @@ import net.luckperms.api.util.Tristate;
import cn.nukkit.Player; import cn.nukkit.Player;
import cn.nukkit.command.CommandSender; import cn.nukkit.command.CommandSender;
import cn.nukkit.command.ConsoleCommandSender;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.UUID;
@ -92,4 +93,8 @@ public class NukkitSenderFactory extends SenderFactory<LPNukkitPlugin, CommandSe
getPlugin().getBootstrap().getServer().dispatchCommand(sender, command); getPlugin().getBootstrap().getServer().dispatchCommand(sender, command);
} }
@Override
protected boolean isConsole(CommandSender sender) {
return sender instanceof ConsoleCommandSender;
}
} }

View File

@ -38,7 +38,7 @@ import me.lucko.luckperms.common.messaging.MessagingFactory;
import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.manager.track.StandardTrackManager; import me.lucko.luckperms.common.model.manager.track.StandardTrackManager;
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin; import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
import me.lucko.luckperms.common.sender.DummySender; import me.lucko.luckperms.common.sender.DummyConsoleSender;
import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
@ -250,7 +250,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
if (this.bootstrap.getGame().isServerAvailable()) { if (this.bootstrap.getGame().isServerAvailable()) {
return this.senderFactory.wrap(this.bootstrap.getGame().getServer().getConsole()); return this.senderFactory.wrap(this.bootstrap.getGame().getServer().getConsole());
} else { } else {
return new DummySender(this, Sender.CONSOLE_UUID, Sender.CONSOLE_NAME) { return new DummyConsoleSender(this) {
@Override @Override
public void sendMessage(Component message) { public void sendMessage(Component message) {
LPSpongePlugin.this.getLogger().info(LegacyComponentSerializer.legacySection().serialize(TranslationManager.render(message))); LPSpongePlugin.this.getLogger().info(LegacyComponentSerializer.legacySection().serialize(TranslationManager.render(message)));

View File

@ -35,6 +35,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.luckperms.api.util.Tristate; import net.luckperms.api.util.Tristate;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.source.ConsoleSource;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text; import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
@ -89,6 +90,11 @@ public class SpongeSenderFactory extends SenderFactory<LPSpongePlugin, CommandSo
getPlugin().getBootstrap().getGame().getCommandManager().process(source, command); getPlugin().getBootstrap().getGame().getCommandManager().process(source, command);
} }
@Override
protected boolean isConsole(CommandSource sender) {
return sender instanceof ConsoleSource;
}
public static Text toNativeText(Component component) { public static Text toNativeText(Component component) {
return TextSerializers.JSON.deserialize(GsonComponentSerializer.gson().serialize(component)); return TextSerializers.JSON.deserialize(GsonComponentSerializer.gson().serialize(component));
} }

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.velocity; package me.lucko.luckperms.velocity;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import me.lucko.luckperms.common.locale.TranslationManager; import me.lucko.luckperms.common.locale.TranslationManager;
@ -85,4 +86,9 @@ public class VelocitySenderFactory extends SenderFactory<LPVelocityPlugin, Comma
protected void performCommand(CommandSource source, String command) { protected void performCommand(CommandSource source, String command) {
getPlugin().getBootstrap().getProxy().getCommandManager().executeAsync(source, command).join(); getPlugin().getBootstrap().getProxy().getCommandManager().executeAsync(source, command).join();
} }
@Override
protected boolean isConsole(CommandSource sender) {
return sender instanceof ConsoleCommandSource;
}
} }