Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

sftp: reject empty passwords in PasswordAuthenticator (#11938)

Chris Luea859a084427
diff --git a/weed/sftpd/auth/password.go b/weed/sftpd/auth/password.go
index 21216d3ff8..7498adc7e0 100644
--- a/weed/sftpd/auth/password.go
+++ b/weed/sftpd/auth/password.go
@@ -37,8 +37,9 @@ func (a *PasswordAuthenticator) Authenticate(conn ssh.ConnMetadata, password []b
return nil, fmt.Errorf("password authentication disabled")
}
- // Validate password against user store
- if a.userStore.ValidatePassword(username, password) {
+ // An empty password is never valid; skip the store so a store without its
+ // own empty-secret check cannot match on zero-length input.
+ if len(password) != 0 && a.userStore.ValidatePassword(username, password) {
return &ssh.Permissions{
Extensions: map[string]string{
"username": username,
diff --git a/weed/sftpd/auth/password_test.go b/weed/sftpd/auth/password_test.go
new file mode 100644
index 0000000000..b54f6d29ce
--- /dev/null
+++ b/weed/sftpd/auth/password_test.go
@@ -0,0 +1,43 @@
+package auth
+
+import "testing"
+
+// acceptAllStore records whether the store was consulted and accepts any password.
+type acceptAllStore struct {
+ stubStore
+ called bool
+}
+
+func (s *acceptAllStore) ValidatePassword(string, []byte) bool {
+ s.called = true
+ return true
+}
+
+// An empty password must be rejected before the store is consulted, so a store
+// without its own empty-secret check cannot authenticate on zero-length input.
+func TestPasswordAuthenticatorRejectsEmptyPassword(t *testing.T) {
+ store := &acceptAllStore{}
+ a := NewPasswordAuthenticator(store, true)
+
+ for _, password := range [][]byte{nil, {}} {
+ if _, err := a.Authenticate(&fakeConnMetadata{user: "alice"}, password); err == nil {
+ t.Fatalf("expected empty password %v to be rejected", password)
+ }
+ }
+ if store.called {
+ t.Fatal("store must not be consulted for an empty password")
+ }
+}
+
+func TestPasswordAuthenticatorConsultsStore(t *testing.T) {
+ store := &acceptAllStore{}
+ a := NewPasswordAuthenticator(store, true)
+
+ perms, err := a.Authenticate(&fakeConnMetadata{user: "alice"}, []byte("s3cret"))
+ if err != nil {
+ t.Fatalf("expected non-empty password to reach the store: %v", err)
+ }
+ if perms.Extensions["username"] != "alice" {
+ t.Fatalf("expected username extension alice, got %q", perms.Extensions["username"])
+ }
+}