mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-03 06:28:06 +01:00
Fail authentication when username is empty (#2300)
This commit is contained in:
parent
64fad766f6
commit
7b0646760c
@ -36,6 +36,10 @@ const metaChars = "&|!=~*<>()"
|
||||
func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
|
||||
|
||||
p := m.Principal
|
||||
if len(strings.TrimSpace(p)) == 0 {
|
||||
log.Debugf("LDAP authentication failed for empty user id.")
|
||||
return nil, nil
|
||||
}
|
||||
for _, c := range metaChars {
|
||||
if strings.ContainsRune(p, c) {
|
||||
return nil, fmt.Errorf("the principal contains meta char: %q", c)
|
||||
|
@ -131,4 +131,13 @@ func TestAuthenticate(t *testing.T) {
|
||||
if user != nil {
|
||||
t.Errorf("Nil user expected for wrong password")
|
||||
}
|
||||
person.Principal = ""
|
||||
person.Password = ""
|
||||
user, err = auth.Authenticate(person)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected ldap error: %v", err)
|
||||
}
|
||||
if user != nil {
|
||||
t.Errorf("Nil user for empty credentials")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user