Reject the KEX replies a server never receives - #1221
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is a small, targeted hardening in the server message gate and is backed by a focused regression test covering both initial key exchange and rekey behavior.
Pull request overview
This PR hardens the server receive path by rejecting server-only key exchange message IDs (31 and 33) at any point in a connection, preventing a peer from triggering expensive DH prime/group processing on attacker-controlled inputs.
Changes:
- Block server-only KEX messages (KEXDH_REPLY / KEXDH_GEX_GROUP and KEXDH_GEX_REPLY) in the server-side message-allowance gate.
- Add a regression test (
TestServerOnlyKexMsgsBlocked) validating the server rejects these messages both during initial keying and during rekey, while still accepting the expected client GEX request message.
File summaries
| File | Description |
|---|---|
| tests/regress.c | Adds regression coverage ensuring server-only KEX message IDs are rejected across relevant states. |
| src/internal.c | Extends server-side message filtering to refuse server-only KEX replies early in packet dispatch. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
gasbytes
marked this pull request as ready for review
September 2, 2026 08:59
ejohnstown
self-requested a review
September 2, 2026 15:13
ejohnstown
approved these changes
Sep 2, 2026
ejohnstown
pushed a commit
that referenced
this pull request
Sep 2, 2026
This is just a follow-up PR to (#1221), that mirrors pretty much the same changes for the client side too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refuse the two key exchange messages that only a server ever sends (31 and 33), at any point in the connection, so a peer cannot make the server run expensive prime-number checks on a value of its own choosing.
Also added a regression test called
TestServerOnlyKexMsgsBlockedintests/regress.c.