Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(3.8.2 proposed fix) Fix update and get user v4 endpoints to sanitize properly #6195

Merged
merged 1 commit into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion api4/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
if HandleEtag(etag, "Get User", w, r) {
return
} else {
app.SanitizeProfile(user, c.IsSystemAdmin())
if c.Session.UserId == user.Id {
user.Sanitize(map[string]bool{})
} else {
app.SanitizeProfile(user, c.IsSystemAdmin())
}
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
w.Write([]byte(user.ToJson()))
return
Expand Down
12 changes: 5 additions & 7 deletions app/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,7 @@ func UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppEr
return nil, err
}

SanitizeProfile(updatedUser, asAdmin)

sendUpdatedUserEvent(updatedUser)
sendUpdatedUserEvent(*updatedUser, asAdmin)

return updatedUser, nil
}
Expand All @@ -960,14 +958,14 @@ func PatchUser(userId string, patch *model.UserPatch, asAdmin bool) (*model.User
return nil, err
}

SanitizeProfile(updatedUser, asAdmin)

sendUpdatedUserEvent(updatedUser)
sendUpdatedUserEvent(*updatedUser, asAdmin)

return updatedUser, nil
}

func sendUpdatedUserEvent(user *model.User) {
func sendUpdatedUserEvent(user model.User, asAdmin bool) {
SanitizeProfile(&user, asAdmin)

omitUsers := make(map[string]bool, 1)
omitUsers[user.Id] = true
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_UPDATED, "", "", "", omitUsers)
Expand Down
8 changes: 8 additions & 0 deletions store/sql_user_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreCha
} else if count != 1 {
result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.app_error", nil, fmt.Sprintf("user_id=%v, count=%v", user.Id, count))
} else {
user.Password = ""
user.AuthData = new(string)
*user.AuthData = ""
user.MfaSecret = ""
oldUser.Password = ""
oldUser.AuthData = new(string)
*oldUser.AuthData = ""
oldUser.MfaSecret = ""
result.Data = [2]*model.User{user, oldUser}
}
}
Expand Down