Skip to content

Commit f0a989c

Browse files
denjilunny
authored andcommitted
Correction LDAP validation (#342)
* Correction LDAP username validation As https://msdn.microsoft.com/en-us/library/aa366101(v=vs.85).aspx describe spaces should not be in start or at the end of username but they can be inside the username. So please check my solution for it. * Check for zero length passwords in LDAP module. According to https://tools.ietf.org/search/rfc4513#section-5.1.2 LDAP client should always check before bind whether a password is an empty value. There are at least one LDAP implementation which does not return error if you try to bind with DN set and empty password - AD. * Clearing the login/email spaces at the [start/end]
1 parent abcd39f commit f0a989c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

models/login_source.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,9 @@ func ExternalUserLogin(user *User, login, password string, source *LoginSource,
548548
func UserSignIn(username, password string) (*User, error) {
549549
var user *User
550550
if strings.Contains(username, "@") {
551-
user = &User{Email: strings.ToLower(username)}
551+
user = &User{Email: strings.ToLower(strings.TrimSpace(username))}
552552
} else {
553-
user = &User{LowerName: strings.ToLower(username)}
553+
user = &User{LowerName: strings.ToLower(strings.TrimSpace(username))}
554554
}
555555

556556
hasUser, err := x.Get(user)

modules/auth/ldap/ldap.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ func bindUser(l *ldap.Conn, userDN, passwd string) error {
151151

152152
// SearchEntry : search an LDAP source if an entry (name, passwd) is valid and in the specific filter
153153
func (ls *Source) SearchEntry(name, passwd string, directBind bool) (string, string, string, string, bool, bool) {
154+
// See https://tools.ietf.org/search/rfc4513#section-5.1.2
155+
if len(passwd) == 0 {
156+
log.Debug("Auth. failed for %s, password cannot be empty")
157+
return "", "", "", "", false, false
158+
}
154159
l, err := dial(ls)
155160
if err != nil {
156161
log.Error(4, "LDAP Connect error, %s:%v", ls.Host, err)

0 commit comments

Comments
 (0)