Add 'X-Forwarded-For' to (s)FTP requests (#20709)

Fixes #20707
This commit is contained in:
Klaus Post
2024-11-29 04:55:37 -08:00
committed by GitHub
parent f0d4ef604c
commit abd6bf060d
3 changed files with 38 additions and 6 deletions

View File

@@ -488,7 +488,12 @@ func startSFTPServer(args []string) {
sshConfig.AddHostKey(private)
handleSFTPSession := func(channel ssh.Channel, sconn *ssh.ServerConn) {
server := sftp.NewRequestServer(channel, NewSFTPDriver(sconn.Permissions), sftp.WithRSAllocator())
var remoteIP string
if host, _, err := net.SplitHostPort(sconn.RemoteAddr().String()); err == nil {
remoteIP = host
}
server := sftp.NewRequestServer(channel, NewSFTPDriver(sconn.Permissions, remoteIP), sftp.WithRSAllocator())
defer server.Close()
server.Serve()
}