mirror of https://github.com/portainer/portainer
fix(auth): prevent user enumeration attack [EE-6832] (#11589)
parent
d9df58e93a
commit
48bc7d0d92
|
@ -75,7 +75,12 @@ func (handler *Handler) authenticate(rw http.ResponseWriter, r *http.Request) *h
|
||||||
if settings.AuthenticationMethod == portainer.AuthenticationInternal ||
|
if settings.AuthenticationMethod == portainer.AuthenticationInternal ||
|
||||||
settings.AuthenticationMethod == portainer.AuthenticationOAuth ||
|
settings.AuthenticationMethod == portainer.AuthenticationOAuth ||
|
||||||
(settings.AuthenticationMethod == portainer.AuthenticationLDAP && !settings.LDAPSettings.AutoCreateUsers) {
|
(settings.AuthenticationMethod == portainer.AuthenticationLDAP && !settings.LDAPSettings.AutoCreateUsers) {
|
||||||
return httperror.NewError(http.StatusUnprocessableEntity, "Invalid credentials", httperrors.ErrUnauthorized)
|
// avoid username enumeration timing attack by creating a fake user
|
||||||
|
// https://en.wikipedia.org/wiki/Timing_attack
|
||||||
|
user = &portainer.User{
|
||||||
|
Username: "portainer-fake-username",
|
||||||
|
Password: "$2a$10$abcdefghijklmnopqrstuvwx..ABCDEFGHIJKLMNOPQRSTUVWXYZ12", // fake but valid format bcrypt hash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +117,11 @@ func (handler *Handler) authenticateInternal(w http.ResponseWriter, user *portai
|
||||||
func (handler *Handler) authenticateLDAP(w http.ResponseWriter, user *portainer.User, username, password string, ldapSettings *portainer.LDAPSettings) *httperror.HandlerError {
|
func (handler *Handler) authenticateLDAP(w http.ResponseWriter, user *portainer.User, username, password string, ldapSettings *portainer.LDAPSettings) *httperror.HandlerError {
|
||||||
err := handler.LDAPService.AuthenticateUser(username, password, ldapSettings)
|
err := handler.LDAPService.AuthenticateUser(username, password, ldapSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.Forbidden("Only initial admin is allowed to login without oauth", err)
|
if errors.Is(err, httperrors.ErrUnauthorized) {
|
||||||
|
return httperror.NewError(http.StatusUnprocessableEntity, "Invalid credentials", httperrors.ErrUnauthorized)
|
||||||
|
}
|
||||||
|
|
||||||
|
return httperror.InternalServerError("Unable to authenticate user against LDAP", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
|
|
|
@ -75,8 +75,15 @@ func (*Service) AuthenticateUser(username, password string, settings *portainer.
|
||||||
|
|
||||||
userDN, err := searchUser(username, connection, settings.SearchSettings)
|
userDN, err := searchUser(username, connection, settings.SearchSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, errUserNotFound) {
|
||||||
|
// prevent user enumeration timing attack by attempting the bind with a fake user
|
||||||
|
// and whatever password was provided should definately fail
|
||||||
|
// https://en.wikipedia.org/wiki/Timing_attack
|
||||||
|
userDN = "portainer-fake-ldap-username"
|
||||||
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = connection.Bind(userDN, password)
|
err = connection.Bind(userDN, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue