Skip to content

Commit 3d9861a

Browse files
authored
MqttConnectPayload.toString() includes password (#15547) (#15548)
Motivation: See #15547 for the motivation for this change. Modification: 1-line change to `MqttConnectPayload.toString()` so that the `password` field is no longer included. Result: Password is no longer part of `toString()` which means it won't potentially be included in log files. Fixes #15547.
1 parent 8ca0f96 commit 3d9861a

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectPayload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public String toString() {
130130
.append(", willTopic=").append(willTopic)
131131
.append(", willMessage=").append(Arrays.toString(willMessage))
132132
.append(", userName=").append(userName)
133-
.append(", password=").append(Arrays.toString(password))
133+
.append(", password=").append("****")
134134
.append(']')
135135
.toString();
136136
}

codec-mqtt/src/test/java/io/netty/handler/codec/mqtt/MqttCodecTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.mockito.stubbing.Answer;
3737

3838
import java.util.ArrayList;
39+
import java.util.Arrays;
3940
import java.util.LinkedList;
4041
import java.util.List;
4142

@@ -57,6 +58,7 @@
5758
import static org.assertj.core.api.Assertions.assertThat;
5859
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
5960
import static org.junit.jupiter.api.Assertions.assertEquals;
61+
import static org.junit.jupiter.api.Assertions.assertFalse;
6062
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
6163
import static org.junit.jupiter.api.Assertions.assertNull;
6264
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -79,6 +81,7 @@ public class MqttCodecTest {
7981
private static final String WILL_MESSAGE = "gone";
8082
private static final String USER_NAME = "happy_user";
8183
private static final String PASSWORD = "123_or_no_pwd";
84+
private static final byte[] PASSWORD_BYTES = PASSWORD.getBytes(CharsetUtil.UTF_8);
8285

8386
private static final int KEEP_ALIVE_SECONDS = 600;
8487

@@ -216,6 +219,16 @@ public void testConnectMessageNonZeroReservedBit3Mqtt311() throws Exception {
216219
checkForSingleDecoderException(out);
217220
}
218221

222+
@Test
223+
public void testConnectMessageForPassword311() throws Exception {
224+
assertFalse(createConnectMessage(MqttVersion.MQTT_3_1).toString().contains(Arrays.toString(PASSWORD_BYTES)));
225+
}
226+
227+
@Test
228+
public void testConnectMessageForPassword5() throws Exception {
229+
assertFalse(createConnectMessage(MqttVersion.MQTT_5).toString().contains(Arrays.toString(PASSWORD_BYTES)));
230+
}
231+
219232
@Test
220233
public void testSubscribeMessageNonZeroReservedBit0Mqtt311() throws Exception {
221234
final MqttSubscribeMessage message = createSubscribeMessage();

0 commit comments

Comments
 (0)