GeezerVison is showing github.com — Merge changes from forks by chrisvest · Pull Request #17213 · netty/netty
Merge changes from forks
#17213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1a896eb
CORS: Don't override vary header if it already exists
normanmaurer Jul 1, 2026
9975553
Encoding-side validation of MQTT fields
chrisvest Jul 1, 2026
c07b97c
Bound SCTP fragmented message buffering
yawkat Jul 3, 2026
6b159a9
Apply suggestion from @yawkat
yawkat Jul 3, 2026
a8f53f2
Correctly handle ClientHello with a handshake header split across TLS…
violetagg Jul 16, 2026
b39650a
Fix NPE risk
chrisvest Jul 23, 2026
5dd41ea
Remove invalid user data from exception messages
chrisvest Jul 23, 2026
4625406
Harden the SOCKS4/5 input validation at encoding time
chrisvest Jul 25, 2026
bb74154
Do not re-aggregate the ClientHello on every received TLS record
violetagg Jul 28, 2026
5f1888e
Validate trust manager configuration
violetagg Aug 3, 2026
9a18e8d
Merge branch '4.2-83wf-socks-nul-byte-sec' into 4.2-sec-merge
chrisvest Aug 4, 2026
2f1ebab
Merge branch 'pr-ghsa-c4c3-7fpv-j4q5-2' into 4.2-sec-merge
chrisvest Aug 4, 2026
74d3007
Merge branch 'pr-ghsa-2qj4-mmr9-4v2f-1' into 4.2-sec-merge
chrisvest Aug 4, 2026
d997aab
Merge branch 'pr-ghsa-8c42-7qj2-3j46-1' into 4.2-sec-merge
chrisvest Aug 4, 2026
93340a5
Merge branch 'hf3j-mqtt-sec' into 4.2-sec-merge
chrisvest Aug 4, 2026
2b45fb0
Merge branch 'pr-ghsa-p85m-gvr3-788c-1' into 4.2-sec-merge
chrisvest Aug 4, 2026
File filter
Filter by extension
.java
(5)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
Encoding-side validation of MQTT fields
Motivation:
The MqttEncoder should not produce malformed messages if client id, topics, or usernames contain illegal characters.
Modification:
Add validation of client identifier, will topic, and username to the encoding path of CONNECT messages, and also to the topic name when encoding PUBLISH messages.
Result:
The encoder will now throw an exception if any of these fields contain a NUL byte.
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit 99755538744cee063b4e4dc18aa2e4eaa002c860
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -45,7 +45,7 @@ static boolean isValidPublishTopicName(String topicName) {
// publish topic name must not contain any wildcard
for (int i = 0; i < topicName.length(); i++) {
char c = topicName.charAt(i);
if (c == '#' || c == '+') {
if (c == '#' || c == '+' || c == '\0' ) {
return false;
}
}
Expand All
@@ -56,15 +56,31 @@ static boolean isValidMessageId(int messageId) {
return messageId != 0;
}
static boolean isValidClientId(MqttVersion mqttVersion, int maxClientIdLength, String clientId) {
static boolean isValidUserName(String userName) {
return userName == null || userName.indexOf('\0') == -1;
}
/**
* Determine if a client identifier is valid.
* @param mqttVersion The MQTT version semantics to use.
* @param maxClientIdLength The max client id length.
* @param clientId The client id value.
* @param acceptNulBytes MQTT normally does not allow NUL bytes in client identifiers.
* Set this to {@code true} to enable "legacy"/"lenient" mode, otherwise {@code false} for strict spec compliance.
* @return {@code true} if the client id is valid, otherwise {@code false}.
*/
static boolean isValidClientId(MqttVersion mqttVersion, int maxClientIdLength, String clientId,
boolean acceptNulBytes) {
if (clientId == null || (!acceptNulBytes && clientId.indexOf('\0') != -1)) {
return false;
}
if (mqttVersion == MqttVersion.MQTT_3_1) {
return clientId != null && clientId.length() >= MIN_CLIENT_ID_LENGTH &&
clientId.length() <= maxClientIdLength;
return clientId.length() >= MIN_CLIENT_ID_LENGTH && clientId.length() <= maxClientIdLength;
}
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.MQTT_5) {
// In 3.1.3.1 Client Identifier of MQTT 3.1.1 and 5.0 specifications, The Server MAY allow ClientId’s
// that contain more than 23 encoded bytes. And, The Server MAY allow zero-length ClientId.
return clientId != null ;
return true ;
}
throw new IllegalArgumentException(mqttVersion + " is unknown mqtt version");
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -584,7 +584,7 @@ private MqttConnectPayload decodeConnectionPayload(
final String decodedClientIdValue = decodedClientId.value;
final MqttVersion mqttVersion = MqttVersion.fromProtocolNameAndLevel(mqttConnectVariableHeader.name(),
(byte) mqttConnectVariableHeader.version());
if (!isValidClientId(mqttVersion, maxClientIdLength, decodedClientIdValue)) {
if (!isValidClientId(mqttVersion, maxClientIdLength, decodedClientIdValue, !strictUtf8Validation )) {
throw new MqttIdentifierRejectedException("invalid clientIdentifier: " + decodedClientIdValue);
}
int numberOfBytesConsumed = decodedClientId.numberOfBytesConsumed;
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -30,6 +30,8 @@
import static io.netty.buffer.ByteBufUtil.*;
import static io.netty.handler.codec.mqtt.MqttCodecUtil.getMqttVersion;
import static io.netty.handler.codec.mqtt.MqttCodecUtil.isValidClientId;
import static io.netty.handler.codec.mqtt.MqttCodecUtil.isValidPublishTopicName;
import static io.netty.handler.codec.mqtt.MqttCodecUtil.isValidUserName;
import static io.netty.handler.codec.mqtt.MqttCodecUtil.setMqttVersion;
import static io.netty.handler.codec.mqtt.MqttConstant.DEFAULT_MAX_CLIENT_ID_LENGTH;
import static io.netty.handler.codec.mqtt.MqttProperties.ASSIGNED_CLIENT_IDENTIFIER;
Expand Down
Expand Up
@@ -155,7 +157,7 @@ private static ByteBuf encodeConnectMessage(
// Client id
String clientIdentifier = payload.clientIdentifier();
if (!isValidClientId(mqttVersion, DEFAULT_MAX_CLIENT_ID_LENGTH, clientIdentifier)) {
if (!isValidClientId(mqttVersion, DEFAULT_MAX_CLIENT_ID_LENGTH, clientIdentifier, false )) {
throw new MqttIdentifierRejectedException("invalid clientIdentifier: " + clientIdentifier);
}
int clientIdentifierBytes = utf8Bytes(clientIdentifier);
Expand All
@@ -167,13 +169,19 @@ private static ByteBuf encodeConnectMessage(
byte[] willMessage = payload.willMessageInBytes();
byte[] willMessageBytes = willMessage != null ? willMessage : EmptyArrays.EMPTY_BYTES;
if (variableHeader.isWillFlag()) {
if (!isValidPublishTopicName(willTopic)) {
throw new MqttIdentifierRejectedException("invalid willTopic: " + willTopic);
}
payloadBufferSize += 2 + willTopicBytes;
payloadBufferSize += 2 + willMessageBytes.length;
}
String userName = payload.userName();
int userNameBytes = nullableUtf8Bytes(userName);
if (variableHeader.hasUserName()) {
if (!isValidUserName(userName)) {
throw new MqttIdentifierRejectedException("invalid userName: " + userName);
}
payloadBufferSize += 2 + userNameBytes;
}
Expand Down
Expand Up
@@ -457,6 +465,9 @@ private static ByteBuf encodePublishMessage(
ByteBuf payload = message.payload().duplicate();
String topicName = variableHeader.topicName();
if (!isValidPublishTopicName(topicName)) {
throw new MqttIdentifierRejectedException("invalid topicName: " + topicName);
}
int topicNameBytes = utf8Bytes(topicName);
ByteBuf propertiesBuf = encodePropertiesIfNeeded(mqttVersion,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -18,7 +18,8 @@
import io .netty .handler .codec .DecoderException ;
/**
* A {@link MqttIdentifierRejectedException} which is thrown when a CONNECT request contains invalid client identifier.
* A {@link MqttIdentifierRejectedException} which is thrown when a CONNECT request contains invalid client identifier,
* will topic name, or username, or when a PUBLISH message contains an invalid topic name.
*/
public final class MqttIdentifierRejectedException extends DecoderException {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -33,6 +33,8 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
Expand Down
Expand Up
@@ -1465,4 +1467,61 @@ public void legacyModeAcceptsEmbeddedNullCharacter() {
ReferenceCountUtil.release(msg);
}
}
@ParameterizedTest
@EnumSource(MqttVersion.class)
public void encodeConnectMessageWithNulInClientIdIsRejected(MqttVersion version) {
final MqttConnectMessage message = MqttMessageBuilders.connect()
.clientId("client\u0000id")
.protocolVersion(version)
.cleanSession(true)
.keepAlive(KEEP_ALIVE_SECONDS)
.build();
assertThrows(MqttIdentifierRejectedException.class, () -> MqttEncoder.doEncode(ctx, message));
}
@ParameterizedTest
@EnumSource(MqttVersion.class)
public void encodeConnectMessageWithNulInWillTopicIsRejected(MqttVersion version) {
final MqttConnectMessage message = MqttMessageBuilders.connect()
.clientId(CLIENT_ID)
.protocolVersion(version)
.willFlag(true)
.willQoS(MqttQoS.AT_LEAST_ONCE)
.willTopic("will\u0000topic")
.willMessage(WILL_MESSAGE.getBytes(CharsetUtil.UTF_8))
.cleanSession(true)
.keepAlive(KEEP_ALIVE_SECONDS)
.build();
assertThrows(MqttIdentifierRejectedException.class, () -> MqttEncoder.doEncode(ctx, message));
}
@ParameterizedTest
@EnumSource(MqttVersion.class)
public void encodeConnectMessageWithNulInUserNameIsRejected(MqttVersion version) {
final MqttConnectMessage message = MqttMessageBuilders.connect()
.clientId(CLIENT_ID)
.protocolVersion(version)
.username("user\u0000name")
.password(PASSWORD_BYTES)
.cleanSession(true)
.keepAlive(KEEP_ALIVE_SECONDS)
.build();
assertThrows(MqttIdentifierRejectedException.class, () -> MqttEncoder.doEncode(ctx, message));
}
@Test
public void encodePublishMessageWithNulInTopicIsRejected() {
MqttFixedHeader fixedHeader =
new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_LEAST_ONCE, false, 0);
MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader("home/\u0000/sensor", 1);
ByteBuf payload = ALLOCATOR.buffer();
payload.writeBytes("data".getBytes(CharsetUtil.UTF_8));
MqttPublishMessage message = new MqttPublishMessage(fixedHeader, variableHeader, payload);
try {
assertThrows(MqttIdentifierRejectedException.class, () -> MqttEncoder.doEncode(ctx, message));
} finally {
payload.release();
}
}
}
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.