Skip to content

SSH transport: reject channels the server opens on its own (X11, agent, forwarded ports) #1721

Backlog

Description

@smart-ssh-planner

Goal

A server can no longer open channels towards the client that the client never asked for. The client never requests X11, agent or port forwarding, so every server-initiated channel open is refused, and a server cannot make the app hold an unbounded number of such channels.

Context

  • crates/ssh-transport/src/handler.rs:92-225: ClientHandler implements only disconnected, auth_banner, kex_done and check_server_key. All server_channel_open_* callbacks use the russh defaults.
  • The vendored russh (vendor/russh, 0.63.2) accepts these by default with reply.accept() (vendor/russh/src/client/mod.rs): server_channel_open_forwarded_tcpip (2472), server_channel_open_forwarded_streamlocal (2494), server_channel_open_agent_forward (2513), server_channel_open_session (2561), server_channel_open_direct_tcpip (2580), server_channel_open_direct_streamlocal (2602), server_channel_open_x11 (2621). Only unknown channel types are rejected (should_accept_unknown_server_channel returns false, mod.rs:2530).
  • An accepted channel gets an entry in the session's channel maps and its own message buffer; the default handler drops the Channel handle without closing it. There is no limit on the number.
  • Nothing in crates/ or apps/ requests forwarding (request_x11, agent_forward, tcpip_forward, streamlocal_forward are never called). The client only opens direct-tcpip itself for jump hosts (crates/ssh-transport/src/connect.rs:541), which is a client-initiated open and not affected.
  • Spec 0005 does not mention server-initiated channels.

Requirements

  • ClientHandler overrides all seven server_channel_open_* callbacks listed above and refuses each open with ChannelOpenFailure::AdministrativelyProhibited (reply.reject(...), or dropping reply, which sends the same failure — vendor/russh/src/lib_inner.rs:587-602).
  • should_accept_unknown_server_channel keeps returning false.
  • A refused open is logged at debug level with the channel type only (no addresses or data from the server at info level).
  • The refusal does not close or disturb the session: shell, exec, SFTP and jump-host connections keep working.
  • No change to the vendored russh sources.
  • Spec 0005 states in its security section (§9) that the client requests no forwarding and refuses every channel the server opens on its own.

Acceptance Criteria

  • Against the in-process test server (crates/ssh-transport/tests/fixtures/test_server.rs), a server that opens an X11 channel, an agent-forward channel and a forwarded-tcpip channel towards the client after authentication receives an open failure for each (one test per type)
  • After the refused opens, an exec command on the same connection still succeeds
  • A server opening 1000 channels in a row gets 1000 failures, and the same connection still runs an exec command afterwards
  • A jump-host connection (client-initiated direct-tcpip) still works (existing tests stay green)
  • Spec 0005 §9 describes the rule
  • Relevant automated tests pass

Technical Notes

  • Security-relevant module: SSH transport. No change to host key verification, authentication, the filter engine or credential handling.
  • If the in-process test server cannot open server-initiated channels, extend the fixture; the tests go into a new file crates/ssh-transport/tests/server_opened_channels.rs.
  • User-visible only as a security change: add a changelog fragment.

Files: crates/ssh-transport/src/handler.rs, crates/ssh-transport/tests/fixtures/test_server.rs, crates/ssh-transport/tests/ (new server_opened_channels.rs), docs/specs/0005-ssh-module.md, changelog.d/

Spec impact: update 0005

Open questions

  • Reject with reply.reject(AdministrativelyProhibited) explicitly or drop reply. Recommendation: the explicit call, so the intent is visible in the code.

Related Work

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsecurityssh

    Type

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions