GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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.

Sign up for GitHub

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

Merged
chrisvest merged 16 commits into netty:4.2 from chrisvest:4.2-sec-merge
Aug 4, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Merge changes from forks #17213

Show file tree
Hide file tree
Changes from 3 commits
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

Clear filters
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
Diff view

There are no files selected for viewing

100 changes: 62 additions & 38 deletions 100 handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public abstract class SslClientHelloHandler<T> extends ByteToMessageDecoder impl
private boolean suppressRead;
private boolean readPending;
private ByteBuf handshakeBuffer;
private int aggregatedBytes;
private int handshakeLength = -1;

public SslClientHelloHandler() {
this(DEFAULT_MAX_CLIENT_HELLO_LENGTH);
Expand All @@ -72,9 +74,8 @@ protected SslClientHelloHandler(int maxClientHelloLength) {
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!suppressRead && !handshakeFailed) {
try {
int readerIndex = in.readerIndex();
int readableBytes = in.readableBytes();
int handshakeLength = -1;
int readerIndex = in.readerIndex() + aggregatedBytes;
int readableBytes = in.readableBytes() - aggregatedBytes;

// Check if we have enough data to determine the record type and length.
while (readableBytes >= SslUtils.SSL_RECORD_HEADER_LENGTH) {
Expand Down Expand Up @@ -121,13 +122,62 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t

// Let's check if we already parsed the handshake length or not.
if (handshakeLength == -1) {
if (readerIndex + 4 > endOffset) {
// Need more data to read HandshakeType and handshakeLength (4 bytes)
return;
if (handshakeBuffer == null &&
readerIndex + SslUtils.SSL_RECORD_HEADER_LENGTH + 4 <= endOffset) {
final int handshakeType = in.getUnsignedByte(readerIndex +
SslUtils.SSL_RECORD_HEADER_LENGTH);

// Check if this is a clientHello(1)
// See https://tools.ietf.org/html/rfc5246#section-7.4
if (handshakeType != 1) {
select(ctx, null);
return;
}

// Read the length of the handshake as it may arrive in fragments
// See https://tools.ietf.org/html/rfc5246#section-7.4
handshakeLength = in.getUnsignedMedium(readerIndex +
SslUtils.SSL_RECORD_HEADER_LENGTH + 1);

if (handshakeLength > maxClientHelloLength && maxClientHelloLength != 0) {
TooLongFrameException e = new TooLongFrameException(
"ClientHello length exceeds " + maxClientHelloLength +
": " + handshakeLength);
in.skipBytes(in.readableBytes());
ctx.fireUserEventTriggered(new SniCompletionEvent(e));
SslUtils.handleHandshakeFailure(ctx, e, true);
throw e;
}

if (handshakeLength + 4 + SslUtils.SSL_RECORD_HEADER_LENGTH <= packetLength) {
// We have everything we need in one packet.
// Skip the record header and handshake header (this sums up as 4 bytes)
readerIndex += SslUtils.SSL_RECORD_HEADER_LENGTH + 4;
final int clientHelloLength = handshakeLength;
handshakeLength = -1;
select(ctx, in.retainedSlice(readerIndex, clientHelloLength));
return;
}
}
}

final int handshakeType = in.getUnsignedByte(readerIndex +
SslUtils.SSL_RECORD_HEADER_LENGTH);
if (handshakeBuffer == null) {
handshakeBuffer = ctx.alloc().buffer();
}

// Combine the encapsulated data in one buffer but not include the SSL_RECORD_HEADER
handshakeBuffer.writeBytes(in, readerIndex + SslUtils.SSL_RECORD_HEADER_LENGTH,
packetLength - SslUtils.SSL_RECORD_HEADER_LENGTH);
readerIndex += packetLength;
readableBytes -= packetLength;
aggregatedBytes += packetLength;
if (handshakeLength == -1) {
if (handshakeBuffer.readableBytes() < 4) {
continue;
}

final int handshakeType = handshakeBuffer.getUnsignedByte(0);
handshakeLength = handshakeBuffer.getUnsignedMedium(1);

// Check if this is a clientHello(1)
// See https://tools.ietf.org/html/rfc5246#section-7.4
Expand All @@ -136,11 +186,6 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
return;
}

// Read the length of the handshake as it may arrive in fragments
// See https://tools.ietf.org/html/rfc5246#section-7.4
handshakeLength = in.getUnsignedMedium(readerIndex +
SslUtils.SSL_RECORD_HEADER_LENGTH + 1);

if (handshakeLength > maxClientHelloLength && maxClientHelloLength != 0) {
TooLongFrameException e = new TooLongFrameException(
"ClientHello length exceeds " + maxClientHelloLength +
Expand All @@ -150,34 +195,12 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
SslUtils.handleHandshakeFailure(ctx, e, true);
throw e;
}
// Consume handshakeType and handshakeLength (this sums up as 4 bytes)
readerIndex += 4;
packetLength -= 4;

if (handshakeLength + 4 + SslUtils.SSL_RECORD_HEADER_LENGTH <= packetLength) {
// We have everything we need in one packet.
// Skip the record header
readerIndex += SslUtils.SSL_RECORD_HEADER_LENGTH;
select(ctx, in.retainedSlice(readerIndex, handshakeLength));
return;
} else {
if (handshakeBuffer == null) {
handshakeBuffer = ctx.alloc().buffer(handshakeLength);
} else {
// Clear the buffer so we can aggregate into it again.
handshakeBuffer.clear();
}
}
}

// Combine the encapsulated data in one buffer but not include the SSL_RECORD_HEADER
handshakeBuffer.writeBytes(in, readerIndex + SslUtils.SSL_RECORD_HEADER_LENGTH,
packetLength - SslUtils.SSL_RECORD_HEADER_LENGTH);
readerIndex += packetLength;
readableBytes -= packetLength;
if (handshakeLength <= handshakeBuffer.readableBytes()) {
ByteBuf clientHello = handshakeBuffer.setIndex(0, handshakeLength);
if (handshakeBuffer.readableBytes() >= handshakeLength + 4) {
ByteBuf clientHello = handshakeBuffer.setIndex(4, handshakeLength + 4).slice();
handshakeBuffer = null;
handshakeLength = -1;

select(ctx, clientHello);
return;
Expand Down Expand Up @@ -210,6 +233,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
private void releaseHandshakeBuffer() {
releaseIfNotNull(handshakeBuffer);
handshakeBuffer = null;
handshakeLength = -1;
}

private static void releaseIfNotNull(ByteBuf buffer) {
Expand Down
93 changes: 88 additions & 5 deletions 93 handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.AbstractByteBufAllocator;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.buffer.WrappedByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
Expand Down Expand Up @@ -56,6 +58,7 @@
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.File;
Expand All @@ -65,7 +68,9 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;

Expand Down Expand Up @@ -656,7 +661,83 @@ public void testFragmented(SslProvider provider) throws Exception {
testWithFragmentSize(provider, 50);
}

static Stream<Arguments> tinyFragmentData() {
List<Arguments> args = new ArrayList<Arguments>();
for (Object provider : data()) {
// Fragment sizes smaller than the 4-byte handshake header, so the header itself is
// split across multiple TLS records.
for (int size = 1; size <= 4; size++) {
args.add(Arguments.of(provider, size));
}
}
return args.stream();
}

@ParameterizedTest(name = "{index}: sslProvider={0}, fragmentSize={1}")
@MethodSource("tinyFragmentData")
public void testTinyFragments(SslProvider provider, int fragmentSize) throws Exception {
testWithFragmentSize(provider, fragmentSize);
}

@ParameterizedTest(name = "{index}: sslProvider={0}")
@MethodSource("data")
@SuppressWarnings("unchecked")
public void testTinyFragmentsAreAggregatedOnlyOnce(SslProvider provider) throws Exception {
AtomicLong copiedBytes = new AtomicLong();
EmbeddedChannel server = new EmbeddedChannel(new SniHandler(mock(DomainNameMapping.class)));
server.config().setAllocator(new AbstractByteBufAllocator() {
@Override
public boolean isDirectBufferPooled() {
return false;
}

@Override
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {
return countingBuffer(Unpooled.buffer(initialCapacity, maxCapacity), copiedBytes);
}

@Override
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) {
return countingBuffer(Unpooled.directBuffer(initialCapacity, maxCapacity), copiedBytes);
}
});

try {
List<ByteBuf> fragments = clientHelloInMultipleFragments(provider, "netty.io", 1, 1);
// Hold back the last fragment on purpose, so the handler keeps aggregating the ClientHello.
ReferenceCountUtil.release(fragments.remove(fragments.size() - 1));
for (ByteBuf fragment : fragments) {
assertFalse(server.writeInbound(fragment));
}

assertEquals(fragments.size(), copiedBytes.get());
} finally {
server.finishAndReleaseAll();
}
}

private static ByteBuf countingBuffer(ByteBuf buffer, AtomicLong copiedBytes) {
return new WrappedByteBuf(buffer) {
@Override
public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) {
copiedBytes.addAndGet(length);
return super.writeBytes(src, srcIndex, length);
}
};
}

@ParameterizedTest(name = "{index}: sslProvider={0}")
@MethodSource("data")
public void testTinyFirstFragment(SslProvider provider) throws Exception {
testWithFragmentSize(provider, 1, Integer.MAX_VALUE);
}

private void testWithFragmentSize(SslProvider provider, final int maxFragmentSize) throws Exception {
testWithFragmentSize(provider, maxFragmentSize, maxFragmentSize);
}

private void testWithFragmentSize(SslProvider provider, final int firstFragmentSize, final int maxFragmentSize)
throws Exception {
final String sni = "netty.io";
SelfSignedCertificate cert = CachedSelfSignedCertificate.getCachedCertificate();
final SslContext context = SslContextBuilder.forServer(cert.key(), cert.cert())
Expand All @@ -672,7 +753,8 @@ protected Future<SslContext> lookup(final ChannelHandlerContext ctx, final Strin
}
});

final List<ByteBuf> buffers = clientHelloInMultipleFragments(provider, sni, maxFragmentSize);
final List<ByteBuf> buffers =
clientHelloInMultipleFragments(provider, sni, firstFragmentSize, maxFragmentSize);
for (ByteBuf buffer : buffers) {
server.writeInbound(buffer);
}
Expand All @@ -683,7 +765,8 @@ protected Future<SslContext> lookup(final ChannelHandlerContext ctx, final Strin
}

private static List<ByteBuf> clientHelloInMultipleFragments(
SslProvider provider, String hostname, int maxTlsPlaintextSize) throws SSLException {
SslProvider provider, String hostname, int firstTlsPlaintextSize, int maxTlsPlaintextSize)
throws SSLException {
final EmbeddedChannel client = new EmbeddedChannel();
final SslContext ctx = SslContextBuilder.forClient()
.sslProvider(provider)
Expand All @@ -693,23 +776,23 @@ private static List<ByteBuf> clientHelloInMultipleFragments(
final SslHandler sslHandler = ctx.newHandler(client.alloc(), hostname, -1);
client.pipeline().addLast(sslHandler);
final ByteBuf clientHello = client.readOutbound();
List<ByteBuf> buffers = split(clientHello, maxTlsPlaintextSize);
List<ByteBuf> buffers = split(clientHello, firstTlsPlaintextSize, maxTlsPlaintextSize);
assertTrue(client.finishAndReleaseAll());
return buffers;
} finally {
releaseAll(ctx);
}
}

private static List<ByteBuf> split(ByteBuf clientHello, int maxSize) {
private static List<ByteBuf> split(ByteBuf clientHello, int firstSize, int maxSize) {
final int type = clientHello.readUnsignedByte();
final int version = clientHello.readUnsignedShort();
final int length = clientHello.readUnsignedShort();
assertEquals(length, clientHello.readableBytes());

final List<ByteBuf> result = new ArrayList<ByteBuf>();
while (clientHello.readableBytes() > 0) {
final int toRead = Math.min(maxSize, clientHello.readableBytes());
final int toRead = Math.min(result.isEmpty() ? firstSize : maxSize, clientHello.readableBytes());
final ByteBuf bb = clientHello.alloc().buffer(SslUtils.SSL_RECORD_HEADER_LENGTH + toRead);
bb.writeByte(type);
bb.writeShort(version);
Expand Down
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.