Skip to content

echoserver: fix agent and port forwarding - #1336

Open
ejohnstown wants to merge 4 commits into
wolfSSL:masterfrom
ejohnstown:echo-agent
Open

ejohnstown wants to merge 4 commits into
wolfSSL:masterfrom
ejohnstown:echo-agent

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

Agent forwarding through the echoserver now works and cleans up after
itself, and port forwarding is off unless the server is started with
-F, since the forwards run with the server's own credentials.

  • The agent socket lives in a private mkdtemp() directory, removed at
    session end; the relay drains agent replies of any size.
  • -F enables forwarding; a remote forward to localhost binds loopback,
    and privileged or out-of-range ports are refused.
  • direct-tcpip opens go only to loopback, or to the -L allow-list.
  • A root-run server with -F drops to the -u user (default nobody, with
    a warning) before serving any peer.
  • openssh-interop.test covers ssh -A, -R with and without -F, and -L.

Issue: F-10553, F-11936, F-14396, F-11935

The forwarded agent socket now lives in a mkdtemp() directory, and the
session's end runs the agent cleanup, which the library never calls on
a server. The relay addresses the agent channel by its own id and
drains each agent reply in full.

- Set agentChannelId from ssh->agent once the agent channel is open
- Drop agent replies when no local agent client is connected
- Close the accepted agent client in WOLFSSH_AGENT_LOCAL_CLEANUP and
  remove the socket and its directory
- Print the socket path; openssh-interop.test forwards ssh-agent
  through the echoserver, lists a reply larger than the relay buffer,
  and checks the directory is private and removed

Issue: F-10553, F-11936, F-14396
The forwarding callback connects and binds with the server's own
credentials, so it is registered only with the new -F option. Without
it the library turns down every forwarding request.

- Bind a remote forward for localhost or 127.0.0.1 to the loopback
  address, not INADDR_ANY
- Refuse a remote forward to a privileged port or one over 65535
- Pass -F in fwd.test and fwd-bulk.test; document it in README.md
- openssh-interop.test checks a remote forward fails without -F, works
  with it, and is refused by the port check for port 80

Issue: F-11935
With -F a peer's direct-tcpip open is set up only for a loopback
destination. The new -L option replaces that default with a list of
allowed host or host:port entries. Any other open is refused, which
the library reports as administratively prohibited.

- Check the destination in the WOLFSSH_FWD_LOCAL_SETUP action
- Document -L in the usage text and README.md
- openssh-interop.test checks a non-loopback destination and one left
  out of -L are refused, and that host and host:port entries connect

Issue: F-11935
A root-run echoserver with -F now switches to an unprivileged user once
the listener is bound and the keys are loaded, before any peer is
served, so forwarded connects and binds no longer run as root. The new
-u option names the user; the default is nobody, with a warning. A
failed switch ends the server.

- Add DropPrivileges(): setgroups, setgid, setuid, then check root
  cannot be regained
- Build it only for the standalone POSIX echoserver with WOLFSSH_FWD,
  not for the tests that run echoserver_test() in-process
- Warn on stderr that -u is ignored in a build without it
- Document -u in the usage text and README.md

Issue: F-11935
Copilot AI balanced review requested due to automatic review settings October 22, 2026 20:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #1336

Scan targets checked: wolfssh-src, wolfssh-bugs
Not reviewed (no scan target covers them): README.md, scripts/fwd-bulk.test, scripts/fwd.test.expect, scripts/openssh-interop.test
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

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.

3 participants