fix: skip message body for unknown types in AgentProtocol#1493
Open
rado0x54 wants to merge 1 commit intomscdex:masterfrom
Open
fix: skip message body for unknown types in AgentProtocol#1493rado0x54 wants to merge 1 commit intomscdex:masterfrom
rado0x54 wants to merge 1 commit intomscdex:masterfrom
Conversation
The default case in the AgentProtocol message parser did not advance the read position past the message body for unrecognized message types. In server mode this left body bytes in the parse buffer, corrupting subsequent message parsing. Apply the same defensive skip in client mode where cb(error) aborts the stream but could leave a corrupted buffer if the caller catches and continues. OpenSSH >=8.9 sends SSH_AGENTC_EXTENSION (27) messages such as session-bind@openssh.com for host-key binding before identity requests, which is the real-world trigger for this bug. See PROTOCOL.agent §4.7 in the OpenSSH source.
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.
Summary
The
defaultcase inAgentProtocol's message parser does not advance the read position past the message body for unrecognized message types. In server mode, this leaves the body bytes in the parse buffer, corrupting all subsequent message parsing. This patch applies the same defensive skip in client mode as well.Real-world trigger: OpenSSH >=8.9 sends
SSH_AGENTC_EXTENSION(type 27) messages — specificallysession-bind@openssh.comfor host-key binding — to the agent before identity requests. Without this fix, the extension body bytes corrupt the followingSSH_AGENTC_REQUEST_IDENTITIESparse, causing agent forwarding to fail silently.See PROTOCOL.agent §4.7 in the OpenSSH source.
Changes
lib/agent.js: Addp += this[SYM_MSGLEN] - 1in thedefaultcase of both the server-mode and client-mode message parsers to skip past unrecognized message bodies.test/test-agent-protocol-extension.js: New test file covering:Test plan
node test/test-agent-protocol-extension.js)session-bind@openssh.comis sent