bitwarden/server · error · BadRequestException

You cannot import this much data at once, the limit is 1000

Error message

You cannot import this much data at once, the limit is 1000 projects and 6000 secrets.

What it means

Thrown at SecretsManagerPortingController.cs:70 inside Import. The payload's project count exceeds 1000 or the secret count exceeds 6000 (importRequest.Projects?.Count() > 1000 || importRequest.Secrets?.Count() > 6000). The controller throws BadRequestException with the message about the 1000-project / 6000-secret limit -> HTTP 400. These are hard per-request caps to bound import work.

Source

Thrown at src/Api/SecretsManager/Controllers/SecretsManagerPortingController.cs:70

        if (projects == null && secrets == null)
        {
            throw new NotFoundException();
        }

        return new SMExportResponseModel(projects.Select(p => p.Project), secrets.Select(s => s.Secret));
    }

    [HttpPost("sm/{organizationId}/import")]
    public async Task Import([FromRoute] Guid organizationId, [FromBody] SMImportRequestModel importRequest)
    {
        if (!await _currentContext.OrganizationAdmin(organizationId) || !_currentContext.AccessSecretsManager(organizationId))
        {
            throw new NotFoundException();
        }

        if (importRequest.Projects?.Count() > 1000 || importRequest.Secrets?.Count() > 6000)
        {
            throw new BadRequestException("You cannot import this much data at once, the limit is 1000 projects and 6000 secrets.");
        }

        if (importRequest.Secrets.Any(s => s.ProjectIds.Count() > 1))
        {
            throw new BadRequestException("A secret can only be in one project at a time.");
        }

        var projectsToAdd = importRequest.Projects?.Count();
        if (projectsToAdd is > 0)
        {
            var (max, overMax) = await _maxProjectsQuery.GetByOrgIdAsync(organizationId, projectsToAdd.Value);
            if (overMax != null && overMax.Value)
            {
                throw new BadRequestException($"The maximum number of projects for this plan is ({max}).");
            }
        }

        await _importCommand.ImportAsync(organizationId, importRequest.ToSMImport());

View on GitHub (pinned to e93b962371)

Solutions

  1. Chunk the import into batches of at most 1000 projects and 6000 secrets per request.
  2. Pre-count the parsed payload and split before sending.
  3. Stream/ paginate the source file so each request stays under both limits.

Example fix

// before: one giant import
await adminClient.PostAsync($"/sm/{orgId}/import", FullImport(allProjects, allSecrets)); // 400

// after: paginate respecting both caps
foreach (var batch in ImportBatches(allProjects, allSecrets, maxProjects: 1000, maxSecrets: 6000))
    await adminClient.PostAsync($"/sm/{orgId}/import", batch);
Defensive patterns

Strategy: validation

Validate before calling

const int MaxProjects = 1000, MaxSecrets = 6000;
if (import.Projects?.Count() > MaxProjects || import.Secrets?.Count() > MaxSecrets)
    throw new ArgumentException($"Import exceeds {MaxProjects} projects / {MaxSecrets} secrets");

Prevention

When it happens

Trigger: POST /sm/{org}/import with a body containing more than 1000 projects or more than 6000 secrets in a single request.

Common situations: Bulk-migrating a large vault from another secrets backend in one shot; CI import job reading an un-split JSON/CSV file; miscounted payload generation.

Related errors


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