Skip to content

internal: commit a session only once accepted - #1235

Merged
padelsbach merged 1 commit into
wolfSSL:masterfrom
ejohnstown:ccb-phase2-5
Sep 14, 2026
Merged

padelsbach merged 1 commit into
wolfSSL:masterfrom
ejohnstown:ccb-phase2-5

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

A shell, exec or subsystem request changes the channel only once the callback accepts it, so wolfSSH_accept() no longer reports an established session, or starts SFTP, on a request it answered CHANNEL_FAILURE.

  • DoChannelRequestSession() carries the three arms, which differed only in the type and the callback consulted.
  • The session type and command are set for the callback to read and put back if it refuses, and CLIENT_DONE follows acceptance alone.
  • unit.c drives a refused shell, exec and subsystem request; regress.c checks accept() stays at ACCEPT_SERVER_CHANNEL_ACCEPT_SENT.

Issue: F-8852

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.

🟡 Changes recommended

wolfSSH_AGENT_ChannelOpen() currently contradicts its “safe to poll” contract by returning WS_BAD_ARGUMENT in the pre-request state (and wolfSSH_SFTP_accept()’s appChannels gating can advance SFTP without a properly established subsystem), which can lead to incorrect/fragile runtime behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refines server-side channel/session handling so a shell/exec/subsystem request only “commits” the session (and advances accept/session state) after the relevant callback accepts it, preventing wolfSSH_accept() (and related entry points like SFTP) from reporting an established session after sending CHANNEL_FAILURE.

Changes:

  • Consolidates shell/exec/subsystem request handling into DoChannelRequestSession() and defers committing sessionType/command + CLIENT_DONE until acceptance.
  • Introduces “application-driven channels” mode (wolfSSH_{CTX_,}SetAppChannels) that stops wolfSSH_accept() after userauth.
  • Adds wolfSSH_AGENT_ChannelOpen() so app-driven servers can open the agent-forwarding channel after accept() returns early; adds unit/regression coverage for the new behaviors.
File summaries
File Description
wolfssh/ssh.h Documents and exposes application-driven channel mode APIs.
wolfssh/internal.h Adds appChannels flag to context/session internal structs.
wolfssh/agent.h Exposes wolfSSH_AGENT_ChannelOpen() for app-driven servers.
tests/unit.c Adds unit coverage for rejected session requests and appChannels “no callback” behavior.
tests/regress.c Adds regression coverage for accept stopping at userauth, callback/no-callback behavior, and rejected session requests not advancing accept state.
src/wolfsftp.c Adjusts SFTP accept preconditions when appChannels is enabled.
src/ssh.c Updates wolfSSH_accept() to stop at userauth in appChannels mode and factors agent channel opening into a helper.
src/internal.c Adds DoChannelRequestSession() and updates channel request processing to only commit on acceptance.
src/agent.c Implements wolfSSH_AGENT_ChannelOpen() helper.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/agent.c
Comment thread src/wolfsftp.c Outdated
Comment thread wolfssh/agent.h Outdated

@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 #1235

Scan targets checked: wolfssh-bugs, wolfssh-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread src/agent.c
@ejohnstown ejohnstown self-assigned this Sep 3, 2026
@ejohnstown
ejohnstown force-pushed the ccb-phase2-5 branch 3 times, most recently from cf9a26b to 5bdfaf9 Compare September 11, 2026 00:39
Comment thread src/agent.c
A shell, exec or subsystem request changes the channel only once the
callback accepts it. The session type and command are set for the
callback to read and put back if it refuses, and CLIENT_DONE follows
acceptance alone, so wolfSSH_accept() stays where it is rather than
reporting a session it answered CHANNEL_FAILURE as established.

- DoChannelRequestSession() carries the three arms, which differed only
  in the type and the callback consulted
- a refusal puts the type and command back, so a grant an earlier
  request won still stands
- FreeChannelCommand() wipes and releases a command line for both
  ChannelDelete() and the refusal path
- unit.c drives a refused shell, exec and subsystem request through
  DoChannelRequest() and checks nothing was committed, and that a
  refusal after a grant puts the earlier command back whole
- regress.c checks accept() stays at ACCEPT_SERVER_CHANNEL_ACCEPT_SENT
  on a refused shell, and that the sftp gate and both diverts ask for
  the grant alone

Issue: F-8852
@ejohnstown
ejohnstown marked this pull request as ready for review September 11, 2026 23:18

@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 #1235

Scan targets checked: wolfssh-src, wolfssh-bugs

Fenrir result: Approved ✅

No new issues found in the changed files.

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

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review September 11, 2026 23:24

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@ejohnstown ejohnstown assigned wolfSSL-Bot and unassigned ejohnstown Sep 12, 2026
@padelsbach
padelsbach merged commit 65802d4 into wolfSSL:master Sep 14, 2026
185 checks passed
@ejohnstown
ejohnstown deleted the ccb-phase2-5 branch September 14, 2026 21:57
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.

5 participants