Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

serve sftp: fix auth proxy configured via rc being silently ignored GHSA-p569-5gjg-9cmj CVE-PENDING

Nick Craig-Wood65735be4da67
diff --git a/cmd/serve/sftp/server.go b/cmd/serve/sftp/server.go
index cc8d65676..81f3790e4 100644
--- a/cmd/serve/sftp/server.go
+++ b/cmd/serve/sftp/server.go
@@ -143,12 +143,12 @@ func (s *server) configure() (err error) {
var authorizedKeysMap map[string]struct{}
// ensure the user isn't trying to use conflicting flags
- if proxy.Opt.AuthProxy != "" && s.opt.AuthorizedKeys != "" && s.opt.AuthorizedKeys != Opt.AuthorizedKeys {
+ if s.provider.IsProxy() && s.opt.AuthorizedKeys != "" && s.opt.AuthorizedKeys != Opt.AuthorizedKeys {
return errors.New("--auth-proxy and --authorized-keys cannot be used at the same time")
}
// Load the authorized keys
- if s.opt.AuthorizedKeys != "" && proxy.Opt.AuthProxy == "" {
+ if s.opt.AuthorizedKeys != "" && !s.provider.IsProxy() {
authKeysFile := env.ShellExpand(s.opt.AuthorizedKeys)
authorizedKeysMap, err = loadAuthorizedKeys(authKeysFile)
// If user set the flag away from the default then report an error
diff --git a/cmd/serve/sftp/sftp_test.go b/cmd/serve/sftp/sftp_test.go
index ecbe500cb..de6c89d8e 100644
--- a/cmd/serve/sftp/sftp_test.go
+++ b/cmd/serve/sftp/sftp_test.go
@@ -78,6 +78,32 @@ func TestSftp(t *testing.T) {
servetest.Run(t, "sftp", start)
}
+// TestNewServerPerServerAuthProxy checks that a per-server proxyOpt.AuthProxy
+// enables proxy mode even when the process-global proxy.Opt.AuthProxy is empty,
+// which is the normal case when the server is configured via serve/start.
+func TestNewServerPerServerAuthProxy(t *testing.T) {
+ // Ensure the global is empty so we only test the per-server option.
+ assert.Equal(t, "", proxy.Opt.AuthProxy)
+
+ opt := Opt
+ opt.ListenAddr = testBindAddress
+
+ proxyOpt := proxy.Opt
+ proxyOpt.AuthProxy = "/path/to/auth/proxy"
+
+ w, err := newServer(context.Background(), nil, &opt, &vfscommon.Opt, &proxyOpt)
+ require.NoError(t, err)
+ // Shutdown waits for Serve to finish, so Serve must be running first.
+ go func() {
+ assert.NoError(t, w.Serve())
+ }()
+ defer func() {
+ assert.NoError(t, w.Shutdown())
+ }()
+ assert.True(t, w.provider.IsProxy(), "expected auth proxy to be enabled by per-server option")
+ assert.Nil(t, w.provider.VFS(), "expected no fixed VFS when auth proxy is in use")
+}
+
func TestRc(t *testing.T) {
servetest.TestRc(t, rc.Params{
"type": "sftp",