Skip to content

Commit

Permalink
Use original address for forwarded channel. Fix antoniomika#237
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniomika committed Dec 20, 2022
1 parent c54d681 commit 62dec83
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sshmuxer/aliashandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func handleAliasListener(check *channelForwardMsg, stringPort string, requestMessages string, listenerHolder *utils.ListenerHolder, state *utils.State, sshConn *utils.SSHConnection) (*utils.AliasHolder, *url.URL, string, string, error) {
validAlias, aH := utils.GetOpenAlias(check.Addr, stringPort, state, sshConn)

if !strings.HasPrefix(validAlias, strings.ToLower(check.Addr)) && viper.GetBool("force-requested-aliases") || validAlias == "" {
if !strings.HasPrefix(validAlias, check.Addr) && viper.GetBool("force-requested-aliases") || validAlias == "" {
return nil, nil, "", "", fmt.Errorf("error assigning requested alias to tunnel")
}

Expand Down
2 changes: 2 additions & 0 deletions sshmuxer/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func handleAlias(newChannel ssh.NewChannel, sshConn *utils.SSHConnection, state
return
}

check.Addr = strings.ToLower(check.Addr)

tcpAliasToConnect := fmt.Sprintf("%s:%d", check.Addr, check.Port)
loc, ok := state.AliasListeners.Load(tcpAliasToConnect)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion sshmuxer/httphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func handleHTTPListener(check *channelForwardMsg, stringPort string, requestMessages string, listenerHolder *utils.ListenerHolder, state *utils.State, sshConn *utils.SSHConnection, scheme string) (*utils.HTTPHolder, *url.URL, string, error) {
hostUrl, pH := utils.GetOpenHost(check.Addr, state, sshConn)

if (hostUrl == nil || !strings.HasPrefix(hostUrl.Host, strings.ToLower(check.Addr))) && viper.GetBool("force-requested-subdomains") {
if (hostUrl == nil || !strings.HasPrefix(hostUrl.Host, check.Addr)) && viper.GetBool("force-requested-subdomains") {
return nil, nil, "", fmt.Errorf("error assigning requested subdomain to tunnel")
}

Expand Down
5 changes: 3 additions & 2 deletions sshmuxer/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *utils.SSHConnection,
log.Println("Error unmarshaling remote forward payload:", err)
}

originalAddress := check.Addr
check.Addr = strings.ToLower(check.Addr)

bindPort := check.Rport
Expand Down Expand Up @@ -299,9 +300,9 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *utils.SSHConnection,
}

resp := &forwardedTCPPayload{
Addr: check.Addr,
Addr: originalAddress,
Port: portChannelForwardReplyPayload.Rport,
OriginAddr: check.Addr,
OriginAddr: originalAddress,
OriginPort: portChannelForwardReplyPayload.Rport,
}

Expand Down

0 comments on commit 62dec83

Please sign in to comment.