Skip to content

fix: skip message body for unknown types in AgentProtocol#1493

Open
rado0x54 wants to merge 1 commit intomscdex:masterfrom
rado0x54:fix/agent-protocol-extension-parse
Open

fix: skip message body for unknown types in AgentProtocol#1493
rado0x54 wants to merge 1 commit intomscdex:masterfrom
rado0x54:fix/agent-protocol-extension-parse

Conversation

@rado0x54
Copy link
Copy Markdown

@rado0x54 rado0x54 commented Apr 8, 2026

Summary

The default case in AgentProtocol'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 — specifically session-bind@openssh.com for host-key binding — to the agent before identity requests. Without this fix, the extension body bytes corrupt the following SSH_AGENTC_REQUEST_IDENTITIES parse, causing agent forwarding to fail silently.

See PROTOCOL.agent §4.7 in the OpenSSH source.

Changes

  • lib/agent.js: Add p += this[SYM_MSGLEN] - 1 in the default case 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:
    • Extension + identity request in a single write (combined buffer)
    • Extension + identity request in separate writes
    • Multiple extensions followed by an identity request

Test plan

  • All three new test cases pass (node test/test-agent-protocol-extension.js)
  • Verify with an OpenSSH >=8.9 client that agent forwarding works when session-bind@openssh.com is sent

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant