bitwarden/server · warning · BadRequestException

You cannot remove yourself.

Error message

You cannot remove yourself.

What it means

Thrown by ProviderService.RemoveUsers when the ProviderUser being removed has the same UserId as deletingUserId (the actor performing the removal). This prevents a provider admin from deleting their own membership, which would lock them out. It is a BadRequestException (HTTP 400) and, like the other per-user checks, is caught inside the foreach and returned as an error string for that specific user rather than failing the whole request.

Source

Thrown at bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs:405

        {
            throw new BadRequestException("Provider must have at least one confirmed ProviderAdmin.");
        }

        var result = new List<Tuple<ProviderUser, string>>();
        var deletedUserIds = new List<Guid>();
        var events = new List<(ProviderUser, EventType, DateTime?)>();

        foreach (var providerUser in providerUsers)
        {
            try
            {
                if (providerUser.ProviderId != providerId)
                {
                    throw new BadRequestException("Invalid user.");
                }
                if (providerUser.UserId == deletingUserId)
                {
                    throw new BadRequestException("You cannot remove yourself.");
                }

                events.Add((providerUser, EventType.ProviderUser_Removed, null));

                var user = keyedUsers.GetValueOrDefault(providerUser.UserId.GetValueOrDefault());
                var email = user == null ? providerUser.Email : user.Email;
                if (!string.IsNullOrWhiteSpace(email))
                {
                    await _mailService.SendProviderUserRemoved(provider.DisplayName(), email);
                }

                result.Add(Tuple.Create(providerUser, ""));
                deletedUserIds.Add(providerUser.Id);
            }
            catch (BadRequestException e)
            {
                result.Add(Tuple.Create(providerUser, e.Message));
            }

View on GitHub (pinned to e93b962371)

Solutions

  1. Exclude the current user's own providerUserId from the removal payload before submitting.
  2. In the UI, disable/prevent self-selection in the removal grid when the row's UserId matches the logged-in user.
  3. Treat the returned per-user error string for the self row as expected and inform the user they were skipped.

Example fix

// before
await providerService.RemoveUsers(providerId, selectedUserIds);

// after
var safeUserIds = selectedUserIds
    .Where(id => id != currentProviderUserId)
    .ToList();
await providerService.RemoveUsers(providerId, safeUserIds);
Defensive patterns

Strategy: validation

Validate before calling

var safeUserIds = selectedUserIds.Where(id => id != currentProviderUserId).ToList();

Type guard

static bool IsSelf(Guid providerUserId, Guid currentUserId, Dictionary<Guid,ProviderUser> map) =>
    map.TryGetValue(providerUserId, out var pu) && pu.UserId == currentUserId;

Prevention

When it happens

Trigger: A provider admin includes their own providerUserId (where UserId == the authenticated deletingUserId) in the batch removal payload. Happens with 'select all' UI actions or when an admin pastes a full user list including themselves.

Common situations: Bulk-remove dialog with 'select all on page'; an automated cleanup script that lists every member; an admin who forgets they are in the list.

Related errors


AI-assisted analysis of bitwarden/server@e93b962371 (2026-08-13). Data as JSON: /api/errors/665568af62e30921. Report an issue: GitHub.