From 9c73abd1ef69b4338bddc2004180bdab7bc558e0 Mon Sep 17 00:00:00 2001 From: touchfalls Date: Sat, 14 Nov 2026 16:40:27 +0400 Subject: [PATCH] security: drop any log line with a password command, warn about F3 + D The Paper log filter dropped only Paper's own 'issued server command' line, so plugins that log commands in their own format (command spies, chat loggers) could still write passwords to the console. Any line with a password command and an argument at the start of a word is now dropped. After /authadmin resetpassword, a player who ran it is told to clear the chat with F3 + D, since the temporary password stays in the chat history. --- CHANGELOG.md | 4 ++++ core/src/main/resources/lang/messages_en.yml | 1 + core/src/main/resources/lang/messages_es.yml | 1 + core/src/main/resources/lang/messages_fr.yml | 1 + core/src/main/resources/lang/messages_it.yml | 1 + core/src/main/resources/lang/messages_ru.yml | 1 + .../command/FabricCommandRegistration.java | 4 ++++ .../paper/command/AuthAdminCommand.java | 4 ++++ .../PaperSensitiveCommandLogFilter.java | 8 +++++--- .../logging/SensitiveCommandLogMatcher.java | 18 ++++++++++++++++++ .../PaperSensitiveCommandLogFilterTest.java | 18 ++++++++++++++++++ 11 files changed, 58 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6356209..505e18b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ All notable changes to this project will be documented in this file. - A warning is logged when the Redis connection is unencrypted and leaves the machine. - Fabric: a logged-in player is no longer kicked by a connection under the same name from another address on an offline-mode server; the new connection is refused, as on Paper. +- Paper: any console line with a password command and an argument is dropped, not only Paper's + own command line, so command-spy and chat-logging plugins no longer leak passwords. A chat line + such as "type /login to continue" is dropped too, as it cannot be told apart from a password. +- After `/authadmin resetpassword`, a player who ran it is reminded to clear the chat with F3 + D. ### Fixed - Paper: on an online-mode server the owner can again take over their own connection from diff --git a/core/src/main/resources/lang/messages_en.yml b/core/src/main/resources/lang/messages_en.yml index 0b14468..e5d3dc9 100644 --- a/core/src/main/resources/lang/messages_en.yml +++ b/core/src/main/resources/lang/messages_en.yml @@ -71,6 +71,7 @@ messages: admin-temporary-password-copy: "&b&n{password}" admin-temporary-password-hover: "&aClick to copy the temporary password." admin-temporary-password-expires: "&7Expires at: {expires}. The player must use /changepassword ." + admin-temporary-password-warning: "&cThe password stays in your chat history. Clear it with F3 + D, especially when streaming or recording." admin-player-usage: "&cUsage: /authadmin {operation} " admin-operation-failed: "&cOperation failed. Check the server log." admin-account-unlocked: "&aAccount unlocked." diff --git a/core/src/main/resources/lang/messages_es.yml b/core/src/main/resources/lang/messages_es.yml index ae40474..990b155 100644 --- a/core/src/main/resources/lang/messages_es.yml +++ b/core/src/main/resources/lang/messages_es.yml @@ -71,6 +71,7 @@ messages: admin-temporary-password-copy: "&b&n{password}" admin-temporary-password-hover: "&aHaz clic para copiar la contraseña temporal." admin-temporary-password-expires: "&7Caduca el: {expires}. El jugador debe usar /changepassword ." + admin-temporary-password-warning: "&cLa contraseña queda en el historial del chat. Bórralo con F3 + D, sobre todo si transmites o grabas." admin-player-usage: "&cUso: /authadmin {operation} " admin-operation-failed: "&cLa operación falló. Revisa el registro del servidor." admin-account-unlocked: "&aCuenta desbloqueada." diff --git a/core/src/main/resources/lang/messages_fr.yml b/core/src/main/resources/lang/messages_fr.yml index a11f830..a91cb39 100644 --- a/core/src/main/resources/lang/messages_fr.yml +++ b/core/src/main/resources/lang/messages_fr.yml @@ -71,6 +71,7 @@ messages: admin-temporary-password-copy: "&b&n{password}" admin-temporary-password-hover: "&aCliquez pour copier le mot de passe temporaire." admin-temporary-password-expires: "&7Expire le : {expires}. Le joueur doit utiliser /changepassword ." + admin-temporary-password-warning: "&cLe mot de passe reste dans l'historique du chat. Effacez-le avec F3 + D, surtout en stream ou en enregistrement." admin-player-usage: "&cUtilisation : /authadmin {operation} " admin-operation-failed: "&cL'opération a échoué. Consultez le journal du serveur." admin-account-unlocked: "&aCompte déverrouillé." diff --git a/core/src/main/resources/lang/messages_it.yml b/core/src/main/resources/lang/messages_it.yml index ec5215b..6938146 100644 --- a/core/src/main/resources/lang/messages_it.yml +++ b/core/src/main/resources/lang/messages_it.yml @@ -71,6 +71,7 @@ messages: admin-temporary-password-copy: "&b&n{password}" admin-temporary-password-hover: "&aFai clic per copiare la password temporanea." admin-temporary-password-expires: "&7Scade il: {expires}. Il giocatore deve usare /changepassword ." + admin-temporary-password-warning: "&cLa password resta nella cronologia della chat. Cancellala con F3 + D, soprattutto se trasmetti o registri." admin-player-usage: "&cUso: /authadmin {operation} " admin-operation-failed: "&cOperazione non riuscita. Controlla il log del server." admin-account-unlocked: "&aAccount sbloccato." diff --git a/core/src/main/resources/lang/messages_ru.yml b/core/src/main/resources/lang/messages_ru.yml index d976892..1582274 100644 --- a/core/src/main/resources/lang/messages_ru.yml +++ b/core/src/main/resources/lang/messages_ru.yml @@ -71,6 +71,7 @@ messages: admin-temporary-password-copy: "&b&n{password}" admin-temporary-password-hover: "&aНажмите ЛКМ, чтобы скопировать временный пароль." admin-temporary-password-expires: "&7Действует до: {expires}. Игрок должен выполнить /changepassword <временный> <новый>." + admin-temporary-password-warning: "&cПароль остался в истории чата. Очистите её через F3 + D, особенно на стриме или при записи." admin-player-usage: "&cИспользование: /authadmin {operation} <игрок>" admin-operation-failed: "&cНе удалось выполнить операцию. Проверьте журнал сервера." admin-account-unlocked: "&aАккаунт разблокирован." diff --git a/platform-fabric/src/main/java/io/github/touchfalls/authsecured/fabric/command/FabricCommandRegistration.java b/platform-fabric/src/main/java/io/github/touchfalls/authsecured/fabric/command/FabricCommandRegistration.java index 2802777..9444b5e 100644 --- a/platform-fabric/src/main/java/io/github/touchfalls/authsecured/fabric/command/FabricCommandRegistration.java +++ b/platform-fabric/src/main/java/io/github/touchfalls/authsecured/fabric/command/FabricCommandRegistration.java @@ -282,6 +282,10 @@ private static void deliverTemporaryPassword(AuthSecuredFabricMod mod, CommandSo send(source, message(mod, "messages.admin-temporary-password-expires", "&7Expires at: {expires}. The player must use /changepassword .", Map.of("expires", reset.getExpiresAt().toString()))); + if (source.isPlayer()) { + send(source, message(mod, "messages.admin-temporary-password-warning", + "&cThe password stays in your chat history. Clear it with F3 + D, especially when streaming or recording.")); + } } finally { Arrays.fill(password, '\0'); reset.destroy(); diff --git a/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/command/AuthAdminCommand.java b/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/command/AuthAdminCommand.java index c117c30..14877f8 100644 --- a/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/command/AuthAdminCommand.java +++ b/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/command/AuthAdminCommand.java @@ -182,6 +182,10 @@ private void deliverTemporaryPassword(CommandSender sender, String target, Tempo sender.sendMessage(message("messages.admin-temporary-password-expires", "&7Expires at: {expires}. The player must use /changepassword .", Map.of("expires", reset.getExpiresAt().toString()))); + if (sender instanceof org.bukkit.entity.Player) { + sender.sendMessage(message("messages.admin-temporary-password-warning", + "&cThe password stays in your chat history. Clear it with F3 + D, especially when streaming or recording.")); + } } finally { Arrays.fill(password, '\0'); reset.destroy(); diff --git a/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilter.java b/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilter.java index 98b3489..28dfbe5 100644 --- a/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilter.java +++ b/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilter.java @@ -11,7 +11,8 @@ import java.util.Locale; /** - * Drops Paper's built-in player-command log record before it is formatted. + * Drops Paper's built-in player-command log record before it is formatted, and any other log line + * that carries a password command with an argument (command spies, chat loggers). * Paper logs the raw command before firing PlayerCommandPreprocessEvent, so an * event listener alone cannot keep password arguments out of the console. */ @@ -46,9 +47,10 @@ public Result filter(LogEvent event) { static boolean containsSensitivePaperCommand(LogEvent event) { if (event == null) return false; Message message = event.getMessage(); - String format = message == null ? null : message.getFormat(); + if (message == null) return false; + String format = message.getFormat(); if (format == null || !format.toLowerCase(Locale.ROOT).contains(PAPER_COMMAND_MARKER)) { - return false; + return SensitiveCommandLogMatcher.containsCommandWithArgument(message.getFormattedMessage()); } Object[] parameters = message.getParameters(); diff --git a/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/SensitiveCommandLogMatcher.java b/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/SensitiveCommandLogMatcher.java index ab89a2c..7d935b4 100644 --- a/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/SensitiveCommandLogMatcher.java +++ b/platform-paper/src/main/java/io/github/touchfalls/authsecured/paper/logging/SensitiveCommandLogMatcher.java @@ -20,4 +20,22 @@ static boolean isSensitiveCommand(String rawCommand) { if (namespace >= 0) label = label.substring(namespace + 1); return SecretRedactor.isPasswordCommand(label); } + + /** + * A password command with an argument anywhere in a log line, such as {@code "[Spy] Steve: /login x"}: + * other plugins log commands in their own formats. The slash must start a word, so a path like + * {@code /home/l x} does not match the {@code l} alias. + */ + static boolean containsCommandWithArgument(String line) { + if (line == null) return false; + for (int slash = line.indexOf('/'); slash >= 0; slash = line.indexOf('/', slash + 1)) { + if (slash > 0 && !Character.isWhitespace(line.charAt(slash - 1)) + && "\"'([<{".indexOf(line.charAt(slash - 1)) < 0) continue; + int end = slash + 1; + while (end < line.length() && !Character.isWhitespace(line.charAt(end))) end++; + if (!isSensitiveCommand(line.substring(slash, end))) continue; + if (!line.substring(end).isBlank()) return true; + } + return false; + } } diff --git a/platform-paper/src/test/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilterTest.java b/platform-paper/src/test/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilterTest.java index ac6f3a6..78bc074 100644 --- a/platform-paper/src/test/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilterTest.java +++ b/platform-paper/src/test/java/io/github/touchfalls/authsecured/paper/logging/PaperSensitiveCommandLogFilterTest.java @@ -24,4 +24,22 @@ void allowsUnrelatedCommandsAndMessages() { assertTrue(SensitiveCommandLogMatcher.isSensitiveCommand(" /login secret")); assertFalse(SensitiveCommandLogMatcher.isSensitiveCommand("/loginhistory")); } + + @Test + void findsPasswordCommandsLoggedByOtherPlugins() { + for (String line : new String[]{ + "/login secret", "[Spy] Steve: /login secret", "Steve: /authsecured:register a a", + "Steve ran \"/cp old new\"", "(/l secret)", + // Indistinguishable from "/login to": a chat line like this is dropped on purpose. + "Type /login to continue" + }) { + assertTrue(SensitiveCommandLogMatcher.containsCommandWithArgument(line), line); + } + for (String line : new String[]{ + "Steve: /login", "Loaded /home/l x", "https://example.com/login x", + "Steve: /help login secret", null + }) { + assertFalse(SensitiveCommandLogMatcher.containsCommandWithArgument(line), String.valueOf(line)); + } + } }