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:
Henrique Dias committed 2026-06-27 09:08:56 +02:00
1 parent 8503ba61ff
commit 883a36f02f
5 files changed
+111

No files matched your search

+14
View File
@@ -6,6 +6,7 @@ import (
"reflect"
"github.com/asdine/storm/v3"
"github.com/asdine/storm/v3/q"
bolt "go.etcd.io/bbolt"
fberrors "github.com/filebrowser/filebrowser/v2/errors"
@@ -41,6 +42,19 @@ func (st usersBackend) GetBy(i interface{}) (user *users.User, err error) {
return
}
func (st usersBackend) GetByScope(scope string) (*users.User, error) {
user := &users.User{}
err := st.db.Select(q.Eq("Scope", scope)).First(user)
if err != nil {
if errors.Is(err, storm.ErrNotFound) {
return nil, fberrors.ErrNotExist
}
return nil, err
}
return user, nil
}
func (st usersBackend) Gets() ([]*users.User, error) {
var allUsers []*users.User
err := st.db.All(&allUsers)