Skip to content

Commit 6b5a4ae

Browse files
authored
Merge pull request #3754 from semaphoreui/fix/ldap_filter_injection
fix(ldap): issue with filter injection
2 parents 021a801 + b96c4b8 commit 6b5a4ae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

api/login.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func tryFindLDAPUser(username, password string) (*db.User, error) {
7272
searchRequest := ldap.NewSearchRequest(
7373
util.Config.LdapSearchDN,
7474
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
75-
fmt.Sprintf(util.Config.LdapSearchFilter, username),
75+
fmt.Sprintf(util.Config.LdapSearchFilter, ldap.EscapeFilter(username)),
7676
[]string{util.Config.LdapMappings.DN},
7777
nil,
7878
)
@@ -105,7 +105,7 @@ func tryFindLDAPUser(username, password string) (*db.User, error) {
105105
searchRequest = ldap.NewSearchRequest(
106106
util.Config.LdapSearchDN,
107107
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
108-
fmt.Sprintf(util.Config.LdapSearchFilter, username),
108+
fmt.Sprintf(util.Config.LdapSearchFilter, ldap.EscapeFilter(username)),
109109
[]string{util.Config.LdapMappings.DN, util.Config.LdapMappings.Mail, util.Config.LdapMappings.UID, util.Config.LdapMappings.CN},
110110
nil,
111111
)
@@ -333,7 +333,7 @@ func login(w http.ResponseWriter, r *http.Request) {
333333
"context": "ldap",
334334
"auth": login.Auth,
335335
}).Warn("Failed to find user in LDAP")
336-
w.WriteHeader(http.StatusInternalServerError)
336+
w.WriteHeader(http.StatusUnauthorized)
337337
return
338338
}
339339
}

0 commit comments

Comments
 (0)