[MM-15767] Mask errors in login flow only explicitly (#11051)

* Explicit list of errors that should be masked for login flow

* Fix unit test

* fix test #2

* Use of whitelist of passed through errors; Rework error messages
Этот коммит содержится в:
Daniel Schalla
2019-06-10 23:25:25 +02:00
коммит произвёл GitHub
родитель 41774b671a
Коммит 79fb20bc1a
3 изменённых файлов: 131 добавлений и 21 удалений

Просмотреть файл

@@ -1242,13 +1242,56 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
func login(c *Context, w http.ResponseWriter, r *http.Request) {
// Translate all login errors to generic. MFA error being an exception, since it's required for the login flow itself
defer func() {
if c.Err != nil &&
c.Err.Id != "mfa.validate_token.authenticate.app_error" &&
c.Err.Id != "api.user.login.blank_pwd.app_error" &&
c.Err.Id != "api.user.login.bot_login_forbidden.app_error" &&
c.Err.Id != "api.user.login.client_side_cert.certificate.app_error" {
c.Err = model.NewAppError("login", "api.user.login.invalid_credentials", nil, "", http.StatusUnauthorized)
if c.Err == nil {
return
}
unmaskedErrors := []string{
"mfa.validate_token.authenticate.app_error",
"api.user.check_user_mfa.bad_code.app_error",
"api.user.login.blank_pwd.app_error",
"api.user.login.bot_login_forbidden.app_error",
"api.user.login.client_side_cert.certificate.app_error",
"api.user.login.inactive.app_error",
"api.user.login.not_verified.app_error",
}
maskError := true
for _, unmaskedError := range unmaskedErrors {
if c.Err.Id == unmaskedError {
maskError = false
}
}
if !maskError {
return
}
config := c.App.Config()
enableUsername := *config.EmailSettings.EnableSignInWithUsername
enableEmail := *config.EmailSettings.EnableSignInWithEmail
samlEnabled := *config.SamlSettings.Enable
gitlabEnabled := *config.GetSSOService("gitlab").Enable
googleEnabled := *config.GetSSOService("google").Enable
office365Enabled := *config.GetSSOService("office365").Enable
if samlEnabled || gitlabEnabled || googleEnabled || office365Enabled {
c.Err = model.NewAppError("login", "api.user.login.invalid_credentials_sso", nil, "", http.StatusUnauthorized)
return
}
if enableUsername && !enableEmail {
c.Err = model.NewAppError("login", "api.user.login.invalid_credentials_username", nil, "", http.StatusUnauthorized)
return
}
if !enableUsername && enableEmail {
c.Err = model.NewAppError("login", "api.user.login.invalid_credentials_email", nil, "", http.StatusUnauthorized)
return
}
c.Err = model.NewAppError("login", "api.user.login.invalid_credentials_email_username", nil, "", http.StatusUnauthorized)
}()
props := model.MapFromJson(r.Body)