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 — Bound the SNI host name by the server_name extension by Marti2203 · Pull Request #18121 · netty/netty

Conversation

@Marti2203

@Marti2203 Marti2203 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Motivation:

AbstractSniHandler.extractSniHostname(...) bounds the host_name length by extensionsLimit, the end of all extensions, not by the end of the server_name extension (AbstractSniHandler.java:109). RFC 6066 requires the ServerNameList to fill the extension data. As a result:

  1. A host_name whose length runs past the end of the server_name extension is accepted, and the name is read from the header and data of the following extension(s).
  2. The server_name_list length is skipped and never checked (0 or 0xFFFF are accepted).
  3. An empty host_name (opaque HostName<1..2^16-1>) is returned as "".

For example, a server_name extension with extension_length = 9, list length 0xFFFF, name_length = 13 and the bytes beta, followed by an extension whose header and data are .sni.test, makes extractSniHostname return beta.sni.test. SniHandler then selects that virtual host and fires SniCompletionEvent("beta.sni.test"). Both the JDK engine and BoringSSL reject the same hello afterwards with decode_error, so no handshake completes, but the mapping and SniCompletionEvent already ran with a name that is not in the server_name extension.

This is separate from #17532 / #17558 / #17559, which added checks before the session_id, cipher_suites and compression_methods reads; the line-109 comparison was not changed there.

Modification:

  • Bound the SNI parse by the end of the server_name extension.
  • Require the server_name_list length to match the extension data.
  • Reject an empty host_name.
  • Add four tests to AbstractSniHandlerTest: a well-formed server_name followed by another extension, a name crossing the extension boundary, a list-length mismatch, and an empty name.

Result:

Only host names contained in the server_name extension are returned; malformed server_name extensions are ignored like other malformed input.

Tests (4.2 head b6fad79c6a, JDK 21): without the change three of the new tests fail (expected: <null> but was: <beta.sni.test>, <netty.io>, <>). With it, AbstractSniHandlerTest 8/8, SniHandlerTest 19/19, SniClientTest 3/3 and SslClientHelloHandlerTest 4/4 pass, and checkstyle passes for handler. AbstractSniHandler.java is identical on 4.1, so the change should apply there as is.

Host-name syntax checks (LDH, trailing dot) are deliberately not added; underscore names are in use (#8144) and that policy belongs in the mapping.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.

Sorry, something went wrong.

Uh oh!

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

All reactions
Marti2203 and others added 2 commits October 27, 2026 10:54
@Marti2203
Bound the SNI host name by the server_name extension
9157e05
Motivation:

AbstractSniHandler.extractSniHostname(...) checked the host_name length
against the end of all extensions instead of the end of the server_name
extension. A name whose length ran past the extension was read from the
following extension(s), the server_name_list length was never checked,
and an empty host_name was returned as "".

Modification:

Bound the parse by the end of the server_name extension, require the
server_name_list length to match the extension data and reject an
empty host_name. Add tests.

Result:

Only host names contained in the server_name extension are returned.
@normanmaurer
Add more AbstractSniHandler tests for server_name extension bounds
a46b301
Motivation:

The test for the host name not reading past the server_name extension used a
list length that was rejected by the list length check before the host name
bound was reached, so it did not cover that bound. Several other edge cases of
the new checks were not covered.

Modification:

Use a consistent list length in the bound test and add tests for oversized and
off-by-one list lengths, too short and empty server_name extensions, unknown
name types and server_name placed after another extension.

Result:

Reverting the host name bound to the end of all extensions now fails a test.
@normanmaurer

normanmaurer commented Oct 29, 2026

Copy link
Copy Markdown
Member

@Marti2203 I added some more tests. Beside this I wonder if it would be better to reject early and not depend on the SSLEngine implementation to handle this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Marti2203

Marti2203 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the extra tests! I kept null because that matches what SslClientHelloHandler.decode() does for other malformed hellos ("ignore sni and use default"), so the engine makes the final call. But I agree failing early is more consistent across engines, and the handler already fails closed for zero-length handshake records and oversized ClientHellos. I can change it so that extractSniHostname() distinguishes "no server_name" (still null) from "malformed server_name" and the handler then fails the handshake the same way as the zero-length record case (SniCompletionEvent with the cause, handleHandshakeFailure, close), instead of selecting the default context. Should that apply only to the server_name extension, or also to malformed lengths in the extensions block itself (the loop currently just stops)?

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Oct 29, 2026

Copy link
Copy Markdown
Member

Thanks for the extra tests! I kept null because that matches what SslClientHelloHandler.decode() does for other malformed hellos ("ignore sni and use default"), so the engine makes the final call. But I agree failing early is more consistent across engines, and the handler already fails closed for zero-length handshake records and oversized ClientHellos. I can change it so that extractSniHostname() distinguishes "no server_name" (still null) from "malformed server_name" and the handler then fails the handshake the same way as the zero-length record case (SniCompletionEvent with the cause, handleHandshakeFailure, close), instead of selecting the default context. Should that apply only to the server_name extension, or also to malformed lengths in the extensions block itself (the loop currently just stops)?

@yawkat @violetagg @chrisvest WDYT ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@chrisvest
chrisvest self-requested a review November 13, 2026 22:44
@chrisvest

chrisvest commented Nov 14, 2026

Copy link
Copy Markdown
Member

My thinking is its better to fail-closed, and distinguish no server name from malformed server name. The SSLEngine should fail similarly, I think, which is where we'd end up with the default context from null, but in case there's disagreement I'd rather we fail early.

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
Fail closed on a malformed server_name extension
0c2b72f
Motivation:

AbstractSniHandler.extractSniHostname(...) returned null for a malformed
server_name extension, which made SslClientHelloHandler select the default
context and leave the final decision to the SSLEngine. Engines may interpret
the same bytes differently, so a malformed server_name should be rejected
early rather than depend on the SSLEngine implementation.

Modification:

- Distinguish "no server_name extension" (still null) from "malformed
  server_name extension": extractSniHostname(...) now throws a
  NotSslRecordException for a too short extension, a server_name_list length
  that does not fill the extension, an empty or overlong host_name and a
  server_name extension that exceeds the extensions block.
- SslClientHelloHandler fails the handshake in that case the same way it does
  for zero-length handshake records: fire SniCompletionEvent with the cause,
  notify the handshake failure and close the channel.
- Update the tests and add a handler level test that checks the handshake
  fails closed and no context is selected.
- Fix testExtractSniHostnameRejectsTooShortServerNameExtension, which declared
  one byte more extension data than it wrote and so returned null before the
  server_name extension was ever parsed.

Result:

A ClientHello with a malformed server_name extension now fails the handshake
with a NotSslRecordException instead of falling back to the default context.
This is a behavior change: previously such a ClientHello was handed to the
default SslContext. Other malformed input (e.g. truncated extensions block)
keeps the "ignore sni and use default" behavior.
@normanmaurer

normanmaurer commented Nov 14, 2026

Copy link
Copy Markdown
Member

Pushed 0c2b72f to address the fail-closed feedback:

  • extractSniHostname still returns null when there is no server_name extension, but now throws NotSslRecordException when the extension is present and malformed (too short, list length not filling the extension, empty or overlong host_name, extension running past the extensions block).
  • SslClientHelloHandler handles that like the zero-length handshake record case: fires SniCompletionEvent with the cause, notifies the handshake failure and closes, so the default context is not selected.
  • Scope is the server_name extension only. Other malformed input (e.g. a truncated extensions block) and an unknown name_type keep the "ignore sni and use default" behavior.
  • Added a handler-level test for the fail-closed path and updated the unit tests. This also fixes testExtractSniHostnameRejectsTooShortServerNameExtension, which declared one byte more than it wrote and returned null before the extension was parsed.

Note this is a behavior change: a ClientHello with a malformed server_name previously got the default SslContext, now it fails the handshake. The PR description should be updated to reflect that.

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer normanmaurer added this to the 4.2.21.Final milestone Nov 14, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Nov 14, 2026
@testlens-app

testlens-app Bot commented Nov 14, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 0c2b72f
▶️ Tests: 146002 executed
⚪️ Checks: 30/30 completed


Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

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

yawkat
yawkat approved these changes Nov 16, 2026
View reviewed changes
@chrisvest chrisvest modified the milestones: 4.2.21.Final, 4.2.22.Final Nov 16, 2026
chrisvest
chrisvest approved these changes Nov 17, 2026
View reviewed changes
@chrisvest
chrisvest merged commit 20dd973 into netty:4.2 Nov 17, 2026
31 checks passed

Uh oh!

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

@netty-project-bot

netty-project-bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 4.1.

All reactions

Sorry, something went wrong.

Uh oh!

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

@netty-project-bot

netty-project-bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

All reactions

Sorry, something went wrong.

Uh oh!

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

@chrisvest

chrisvest commented Nov 18, 2026

Copy link
Copy Markdown
Member

4.1 port #18448

All reactions

Sorry, something went wrong.

Uh oh!

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

@chrisvest chrisvest removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Nov 18, 2026
@chrisvest

chrisvest commented Nov 18, 2026

Copy link
Copy Markdown
Member

5.0 port #18449

All reactions

Sorry, something went wrong.

Uh oh!

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

@chrisvest chrisvest removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Nov 18, 2026
chrisvest added a commit that referenced this pull request Nov 18, 2026
@chrisvest @normanmaurer
Port 5.0: Bound the SNI host name by the server_name extension (#18121)…
119bc5f
… (#18449)

Motivation:

`AbstractSniHandler.extractSniHostname(...)` bounds the `host_name`
length by `extensionsLimit`, the end of all extensions, not by the end
of the `server_name` extension. RFC 6066 requires the `ServerNameList`
to fill the extension data. As a result a `host_name` could be read from
the header and data of the following extension(s), the
`server_name_list` length was never checked, and an empty `host_name`
was returned as `""`.

Modification:

- Bound the SNI parse by the end of the `server_name` extension.
- Require the `server_name_list` length to match the extension data.
- Reject an empty `host_name`.
- Throw NotSslRecordException for a malformed `server_name` extension
and fail closed in SslClientHelloHandler instead of selecting the
default.
- Add tests to `AbstractSniHandlerTest` and `SslClientHelloHandlerTest`.

Result:

Only host names contained in the `server_name` extension are returned;
malformed `server_name` extensions cause the handshake to fail closed.

(cherry picked from commit 20dd973)

Co-authored-by: Norman Maurer <[email protected]>
chrisvest added a commit that referenced this pull request Nov 18, 2026
@chrisvest @normanmaurer
Port 4.1: Bound the SNI host name by the server_name extension (#18121)…
d24cb13
… (#18448)

Motivation:

`AbstractSniHandler.extractSniHostname(...)` bounds the `host_name`
length by `extensionsLimit`, the end of all extensions, not by the end
of the `server_name` extension. RFC 6066 requires the `ServerNameList`
to fill the extension data. As a result a `host_name` could be read from
the following extension(s), the `server_name_list` length was never
checked, and an empty `host_name` was returned as `""`.

Modification:

- Bound the SNI parse by the end of the `server_name` extension.
- Require the `server_name_list` length to match the extension data.
- Reject an empty `host_name`.
- Throw NotSslRecordException for a malformed server_name extension and
fail closed in SslClientHelloHandler instead of selecting the default.
- Add tests.

Result:

Only host names contained in the `server_name` extension are returned;
malformed `server_name` extensions cause the handshake to fail closed.

(cherry picked from commit 20dd973)

Co-authored-by: Norman Maurer <[email protected]>
hellboy0621 pushed a commit to hellboy0621/netty that referenced this pull request Nov 23, 2026
@Marti2203 @normanmaurer @hellboy0621
Bound the SNI host name by the server_name extension (netty#18121)
ca8c68a
Motivation:

`AbstractSniHandler.extractSniHostname(...)` bounds the `host_name`
length by `extensionsLimit`, the end of all extensions, not by the end
of the `server_name` extension (`AbstractSniHandler.java:109`). RFC 6066
requires the `ServerNameList` to fill the extension data. As a result:

1. A `host_name` whose length runs past the end of the `server_name`
extension is accepted, and the name is read from the header and data of
the following extension(s).
2. The `server_name_list` length is skipped and never checked (0 or
0xFFFF are accepted).
3. An empty `host_name` (`opaque HostName<1..2^16-1>`) is returned as
`""`.

For example, a `server_name` extension with `extension_length = 9`, list
length `0xFFFF`, `name_length = 13` and the bytes `beta`, followed by an
extension whose header and data are `.sni.test`, makes
`extractSniHostname` return `beta.sni.test`. `SniHandler` then selects
that virtual host and fires `SniCompletionEvent("beta.sni.test")`. Both
the JDK engine and BoringSSL reject the same hello afterwards with
`decode_error`, so no handshake completes, but the mapping and
`SniCompletionEvent` already ran with a name that is not in the
`server_name` extension.

This is separate from netty#17532 / netty#17558 / netty#17559, which added checks
before the `session_id`, `cipher_suites` and `compression_methods`
reads; the line-109 comparison was not changed there.

Modification:

- Bound the SNI parse by the end of the `server_name` extension.
- Require the `server_name_list` length to match the extension data.
- Reject an empty `host_name`.
- Add four tests to `AbstractSniHandlerTest`: a well-formed
`server_name` followed by another extension, a name crossing the
extension boundary, a list-length mismatch, and an empty name.

Result:

Only host names contained in the `server_name` extension are returned;
malformed `server_name` extensions are ignored like other malformed
input.

Tests (4.2 head `b6fad79c6a`, JDK 21): without the change three of the
new tests fail (`expected: <null> but was: <beta.sni.test>`,
`<netty.io>`, `<>`). With it, `AbstractSniHandlerTest` 8/8,
`SniHandlerTest` 19/19, `SniClientTest` 3/3 and
`SslClientHelloHandlerTest` 4/4 pass, and checkstyle passes for
`handler`. `AbstractSniHandler.java` is identical on 4.1, so the change
should apply there as is.

Host-name syntax checks (LDH, trailing dot) are deliberately not added;
underscore names are in use (netty#8144) and that policy belongs in the
mapping.

This issue was found by an LLM-Enhanced Static Analysis Engine and
verified manually.

---------

Co-authored-by: Norman Maurer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chrisvest chrisvest chrisvest approved these changes
@yawkat yawkat yawkat approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.22.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

5 participants

@Marti2203 @normanmaurer @chrisvest @netty-project-bot @yawkat
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.