fix(auth): reject signup when normalized home dir collides (GHSA-7rc3-g7h6-22m7)
cleanUsername is many-to-one, so distinct usernames (e.g. "teamone/x" and "teamone-x") can normalize to the same home directory. With CreateUserDir enabled, the second registrant silently reused the first user's directory, breaking per-user isolation. Add a GetByScope lookup and reject a signup whose derived scope is already taken. The check is gated on CreateUserDir: when it is off, signups intentionally share the configured default scope. Adds a regression test for the colliding-username case.
This commit is contained in:
5 files changed
+111
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
// StorageBackend is the interface to implement for a users storage.
|
||||
type StorageBackend interface {
|
||||
GetBy(interface{}) (*User, error)
|
||||
GetByScope(scope string) (*User, error)
|
||||
Gets() ([]*User, error)
|
||||
Save(u *User) error
|
||||
Update(u *User, fields ...string) error
|
||||
@@ -20,6 +21,7 @@ type StorageBackend interface {
|
||||
|
||||
type Store interface {
|
||||
Get(baseScope string, followExternalSymlinks bool, id interface{}) (user *User, err error)
|
||||
GetByScope(scope string) (*User, error)
|
||||
Gets(baseScope string, followExternalSymlinks bool) ([]*User, error)
|
||||
Update(user *User, fields ...string) error
|
||||
Save(user *User) error
|
||||
@@ -56,6 +58,13 @@ func (s *Storage) Get(baseScope string, followExternalSymlinks bool, id interfac
|
||||
return
|
||||
}
|
||||
|
||||
// GetByScope returns the first user whose scope matches the given one, or
|
||||
// ErrNotExist if none does. The user is returned as stored, without setting up
|
||||
// its filesystem, as it is meant for existence checks rather than serving.
|
||||
func (s *Storage) GetByScope(scope string) (*User, error) {
|
||||
return s.back.GetByScope(scope)
|
||||
}
|
||||
|
||||
// Gets gets a list of all users.
|
||||
func (s *Storage) Gets(baseScope string, followExternalSymlinks bool) ([]*User, error) {
|
||||
users, err := s.back.Gets()
|
||||
|
||||
Reference in new issue
Block a user