Language: Go
Label: vulnerable
CWE: NVD-CWE-noinfo \u2014 

Code:
func (r *RoleBindingReflector) GetUserNamespacesFromRequest(req request.Request) ([]string, error) {
	var err error

	username, groups, _ := req.GetUserAndGroups()

	namespaces := sets.NewString()

	userOwnerKind := capsulev1beta2.UserOwner

	var userRoleBindings []interface{}

	if strings.HasPrefix(username, serviceaccount.ServiceAccountUsernamePrefix) {
		userOwnerKind = capsulev1beta2.ServiceAccountOwner

		_, username, err = serviceaccount.SplitUsername(username)
		if err != nil {
			return nil, errors.Wrap(err, "Unable to parse serviceAccount name")
		}
	}

	userRoleBindings, err = r.store.ByIndex(subjectIndex, fmt.Sprintf("%s-%s", userOwnerKind, username))
	if err != nil {
		return nil, errors.Wrap(err, "Unable to find rolebindings in index for user")
	}

	for _, rb := range userRoleBindings {
		rb := rb.(*rbacv1.RoleBinding)
		namespaces.Insert(rb.GetNamespace())
	}

	for _, group := range groups {
		groupRoleBindings, err := r.store.ByIndex(subjectIndex, fmt.Sprintf("%s-%s", capsulev1beta2.GroupOwner, group))
		if err != nil {
			return nil, errors.Wrap(err, "Unable to find rolebindings in index for groups")
		}

		for _, rb := range groupRoleBindings {
			rb := rb.(*rbacv1.RoleBinding)
			namespaces.Insert(rb.GetNamespace())
		}
	}

	return namespaces.List(), nil
}