Skip to content

Fix SSH agent forwarding handled in wrong request handler#46

Merged
JAORMX merged 1 commit intomainfrom
fix/agent-forwarding-channel-request
Mar 17, 2026
Merged

Fix SSH agent forwarding handled in wrong request handler#46
JAORMX merged 1 commit intomainfrom
fix/agent-forwarding-channel-request

Conversation

@JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Mar 17, 2026

Summary

  • Move auth-agent-req@openssh.com handling from handleGlobalRequests (SSH_MSG_GLOBAL_REQUEST) to handleSession (SSH_MSG_CHANNEL_REQUEST), matching the SSH spec and what real clients actually send
  • Remove dead code from handleGlobalRequests — no standard SSH client sends agent forwarding as a global request, so the old handler was never reached in practice
  • Fix tests to use agent.RequestAgentForwarding(session) instead of client.SendRequest(...), exercising the correct code path including a same-session end-to-end test verifying SSH_AUTH_SOCK is set

Context

Per the SSH spec and Go's agent.RequestAgentForwarding(session), the auth-agent-req@openssh.com request is sent as a session channel request (SSH_MSG_CHANNEL_REQUEST). It was incorrectly handled in handleGlobalRequests which processes SSH_MSG_GLOBAL_REQUEST packets. The request would arrive in handleSession, hit the default case, and get rejected — agent forwarding never worked for real clients.

The existing tests passed because they used client.SendRequest() (global request) instead of session.SendRequest() (channel request), exercising the wrong code path.

Test plan

  • go test -v -race ./guest/sshd/ — all 12 tests pass
  • CGO_ENABLED=0 go vet on non-CGO packages — clean
  • go fmt / go vet — clean
  • CI passes

🤖 Generated with Claude Code

Move auth-agent-req@openssh.com handling from handleGlobalRequests
(SSH_MSG_GLOBAL_REQUEST) to handleSession (SSH_MSG_CHANNEL_REQUEST),
matching the SSH spec and what real clients like Go's
agent.RequestAgentForwarding() actually send.

The old handler was dead code — real clients send this as a session
channel request, which hit the default reject case in handleSession.
Tests passed only because they used client.SendRequest() (global)
instead of session-scoped requests.

Tests now use agent.RequestAgentForwarding(session) to exercise the
correct code path, including a same-session end-to-end test that
verifies SSH_AUTH_SOCK is set.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JAORMX JAORMX merged commit 8a4bc2e into main Mar 17, 2026
7 checks passed
@JAORMX JAORMX deleted the fix/agent-forwarding-channel-request branch March 17, 2026 09:17
JAORMX added a commit that referenced this pull request Mar 17, 2026
Verify the full agent forwarding pipeline after the channel
request handler fix in #46: one test confirms a forwarded key
is visible via ssh-add, the other confirms graceful failure
when the client omits the channel handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants