Skip to content

Fix DoGlobalRequestFwd() so that it rejects the port forwarding if no fwdCb is set.#918

Open
yosuke-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
yosuke-wolfssl:f_2867
Open

Fix DoGlobalRequestFwd() so that it rejects the port forwarding if no fwdCb is set.#918
yosuke-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
yosuke-wolfssl:f_2867

Conversation

@yosuke-wolfssl
Copy link
Copy Markdown
Contributor

Background
When WOLFSSH_FWD is compiled in, the server-side handler for tcpip-forward global requests sends SSH_MSG_REQUEST_SUCCESS (via SendGlobalRequestFwdSuccess at line 8500) before invoking the fwdCb policy callback (line 8504). This has two consequences: (1) If no fwdCb is registered (the default), all remote port forwarding requests are silently accepted because the success reply has already been sent. (2) Even if fwdCb IS registered and rejects the request, the client has already received the approval response.

Changes
This PR fixes it so that DoGlobalRequestFwd() rejects the forwarding if no fwdCb is set.
Also, the new regression tests are added.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Apr 15, 2026
Copilot AI review requested due to automatic review settings April 15, 2026 02:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts server-side handling of tcpip-forward / cancel-tcpip-forward global requests (when WOLFSSH_FWD is enabled) to avoid approving port forwarding before the forwarding-policy callback is consulted, and adds regression tests around the new behavior.

Changes:

  • Move the global-request success reply so it is only sent after the forwarding callback accepts the request.
  • Reject remote port forwarding requests when no forwarding callback (fwdCb) is registered.
  • Add regression tests covering success/failure replies for forward/cancel requests with and without fwdCb.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/internal.c Reorders DoGlobalRequestFwd() reply/decision flow and adds explicit rejection when fwdCb is not set.
tests/regress.c Adds packet builder + assertions and new regress tests for global forwarding request replies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.c Outdated
Comment thread src/internal.c Outdated
Comment thread tests/regress.c Outdated
Comment thread tests/regress.c Outdated
@JacobBarthelmeh
Copy link
Copy Markdown
Contributor

@yosuke-wolfssl , please resolve the merge conflict

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/regress.c Outdated
Comment thread src/internal.c
Comment thread src/internal.c Outdated
Comment thread tests/regress.c Outdated
Copilot AI review requested due to automatic review settings April 16, 2026 00:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.c
@yosuke-wolfssl
Copy link
Copy Markdown
Contributor Author

Hi @JacobBarthelmeh ,
I resolved the conflict. Could you please review it again ?

Comment thread src/internal.c
}
else if (ret != WS_SUCCESS) {
/* No reply expected; silently reject without terminating connection. */
ret = WS_SUCCESS;
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.

Overriding all non WS_SUCCESS ret values when wantReply is not set could mask returns like WS_BAD_ARGUMENT.

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.

4 participants