Return .ignore() for unknown message types per RFC 4253#224
Open
jeffellin wants to merge 1 commit intoapple:mainfrom
Open
Return .ignore() for unknown message types per RFC 4253#224jeffellin wants to merge 1 commit intoapple:mainfrom
jeffellin wants to merge 1 commit intoapple:mainfrom
Conversation
Motivation: RFC 4253 Section 11.1 requires: "An implementation MUST be able to process all message types, though it need not ACT on them" and "An implementation MAY ignore an unrecognized message." NIOSSH currently violates this requirement by throwing ParsingError.unknownType for unknown message types. This causes parser state corruption through buffer rewind over already-decrypted data, and prevents interoperability with SSH implementations using protocol extensions (OpenSSH extensions, vendor-specific message types). Modifications: - readSSHMessage(): Return .ignore() for unknown message types instead of throwing, consuming remaining bytes to prevent corruption - Add testUnknownMessageTypeReturnsIgnore to verify RFC compliance - Add testParserStateAfterUnknownMessageType to verify parser continuity - Update testTypeError to expect .ignore() instead of throw Result: NIOSSH now follows RFC 4253 by gracefully ignoring unknown message types. Connections continue normally when encountering extensions, enabling interoperability with OpenSSH extensions and vendor-specific message types. Breaking Change: ParsingError.unknownType is no longer thrown for unknown message types. Connections that previously failed will now continue normally per RFC requirements.
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.
Fixes #223
Summary
This PR fixes the RFC 4253 violation where NIOSSH throws errors for unknown SSH message types instead of gracefully ignoring them. See #223 for detailed problem analysis and reproduction steps.
Changes
readSSHMessage(): Return.ignore()for unknown message types instead of throwing, consuming remaining bytes to prevent parser corruptiontestUnknownMessageTypeReturnsIgnoreto verify RFC 4253 compliancetestParserStateAfterUnknownMessageTypeto verify parser state continuitytestTypeErrorto expect.ignore()instead of throw (reflects RFC-compliant behavior)Motivation
RFC 4253 Section 11.1 explicitly requires:
NIOSSH currently violates this by throwing
ParsingError.unknownType, which:Root Cause
When the parser encountered an unknown message type (e.g., reserved IDs 192-255 for local use), it would:
ParsingError.unknownTyperewindOnNilOrErrorto rewind the buffer readerSolution
Follow RFC 4253 by returning
.ignore()for unknown message types:This matches how all other major SSH implementations handle unknown messages:
Test Results
Before fix:
testTypeError: ✅ Passes (but expects wrong behavior - throw instead of ignore)testUnknownMessageTypeReturnsIgnore: ❌ FAILS - throwsunknownType(127)testParserStateAfterUnknownMessageType: ❌ FAILS - throwsunknownType(125)After fix:
testTypeError: ✅ Passes (now expects correct RFC behavior - ignore)testUnknownMessageTypeReturnsIgnore: ✅ Passes - returns.ignore()testParserStateAfterUnknownMessageType: ✅ Passes - parser continues normallyFull test suite:
Breaking Changes
Before:
ParsingError.unknownTypeerrorCaughthandlersAfter:
.ignore()Rationale for Breaking Change
While this changes observable behavior, it's necessary because:
Migration Guide
If you were catching
ParsingError.unknownType:After this fix:
.ignore()messagesImpact: Connections that previously failed will now succeed. This is the desired RFC-compliant behavior.
Impact
This fix enables NIOSSH to interoperate with:
hostkeys-00@openssh.com)Relationship to PR #222 (Issue #221)
This PR shares the same root cause pattern as PR #222:
rewindOnNilOrErrormoveReaderIndex(to: writerIndex)However, they can be merged independently:
Checklist