fix(user-token): prevent admin read tokens of other admins EE-5858 (#10489)

pull/10445/head
cmeng 1 year ago committed by GitHub
parent 03155685ab
commit bc0050a7b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,23 +33,23 @@ func (handler *Handler) userGetAccessTokens(w http.ResponseWriter, r *http.Reque
return httperror.BadRequest("Invalid user identifier route variable", err)
}
user, err := handler.DataStore.User().Read(portainer.UserID(userID))
if err != nil {
if handler.DataStore.IsErrObjectNotFound(err) {
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
}
return httperror.InternalServerError("Unable to find a user with the specified identifier inside the database", err)
}
tokenData, err := security.RetrieveTokenData(r)
if err != nil {
return httperror.InternalServerError("Unable to retrieve user authentication token", err)
}
if tokenData.Role != portainer.AdministratorRole && tokenData.ID != portainer.UserID(userID) {
if tokenData.ID != portainer.UserID(userID) && (tokenData.Role != portainer.AdministratorRole || user.Role == portainer.AdministratorRole) {
return httperror.Forbidden("Permission denied to get user access tokens", httperrors.ErrUnauthorized)
}
_, err = handler.DataStore.User().Read(portainer.UserID(userID))
if err != nil {
if handler.DataStore.IsErrObjectNotFound(err) {
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
}
return httperror.InternalServerError("Unable to find a user with the specified identifier inside the database", err)
}
apiKeys, err := handler.apiKeyService.GetAPIKeys(portainer.UserID(userID))
if err != nil {
return httperror.InternalServerError("Internal Server Error", err)

Loading…
Cancel
Save