{"record":{"id":"03e6cf480b2f05aa","repo":"owasp-amass/amass","slug":"createassetsbulk-too-many-items-max-d","errorCode":null,"errorMessage":"CreateAssetsBulk: too many items; max=%d","messagePattern":"CreateAssetsBulk: too many items; max=(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/api/client/v1/client.go","lineNumber":258,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"createAsset: status=%s error=%s\", resp.Status, msg)\n\t}\n\n\tvar r AddAssetResponse\n\tif err := json.Unmarshal([]byte(resp.Body), &r); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn r.EntityID, nil\n}\n\n// Creates multiple assets in bulk on the server associated with the provided token.\nfunc (c *Client) CreateAssetsBulk(ctx context.Context, token uuid.UUID, atype string, assets []oam.Asset) (int, error) {\n\tatype = strings.ToLower(strings.TrimSpace(atype))\n\n\tif atype == \"\" {\n\t\treturn 0, fmt.Errorf(\"CreateAssetsBulk: asset type required\")\n\t}\n\tif len(assets) > MaxBulkItems {\n\t\treturn 0, fmt.Errorf(\"CreateAssetsBulk: too many items; max=%d\", MaxBulkItems)\n\t}\n\n\titems := make([]json.RawMessage, 0, len(assets))\n\tfor _, asset := range assets {\n\t\tif !strings.EqualFold(atype, string(asset.AssetType())) {\n\t\t\treturn 0, fmt.Errorf(\"CreateAssetsBulk: mixed asset types not allowed\")\n\t\t}\n\n\t\traw, err := asset.JSON()\n\t\tif err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t\titems = append(items, json.RawMessage(raw))\n\t}\n\n\tsessionID := token.String()\n\tbody, _ := json.Marshal(BulkAddAssetsRequest{Items: items})\n\tu := fmt.Sprintf(\"%s/sessions/%s/assets/%s:bulk\", c.base, sessionID, atype)","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/engine/api/client/v1/client.go#L240-L276","documentation":"CreateAssetsBulk enforces a client-side maximum batch size (MaxBulkItems) to keep the bulk POST payload reasonable. Supplying more assets than the limit rejects the entire call before any network request, protecting both client and server from oversized requests.","triggerScenarios":"Calling Client.CreateAssetsBulk with len(assets) > MaxBulkItems — e.g. passing thousands of collected assets from a large enumeration in one call.","commonSituations":"Batching logic that collects assets for a whole scan without chunking; long-running sessions that accumulate assets faster than they are flushed.","solutions":["Split the asset slice into chunks of at most MaxBulkItems and call CreateAssetsBulk per chunk.","Check MaxBulkItems in this package to size batches correctly.","Buffer assets through a queue that flushes when the chunk limit is reached.","Reduce per-call volume by flushing assets incrementally during collection."],"exampleFix":"// before\ncount, err := client.CreateAssetsBulk(ctx, token, atype, allAssets)\n// after\nfor len(allAssets) > 0 {\n    end := min(len(allAssets), MaxBulkItems)\n    if _, err := client.CreateAssetsBulk(ctx, token, atype, allAssets[:end]); err != nil { return err }\n    allAssets = allAssets[end:]\n}","handlingStrategy":"validation","validationCode":"if len(assets) > MaxBulkItems { return fmt.Errorf(\"%d assets exceed MaxBulkItems=%d\", len(assets), MaxBulkItems) }","typeGuard":"func withinBulkLimit(assets []oam.Asset) bool { return len(assets) <= MaxBulkItems }","tryCatchPattern":"if !withinBulkLimit(assets) {\n    for chunk := range slices.Chunk(assets, MaxBulkItems) {\n        if _, err := client.CreateAssetsBulk(ctx, token, atype, chunk); err != nil { return err }\n    }\n    return nil\n}","preventionTips":["Chunk batches to MaxBulkItems before every bulk call.","Flush assets incrementally during collection instead of at the end.","Reference the MaxBulkItems constant rather than hardcoding limits.","Add a unit test asserting batch sizes never exceed the limit."],"tags":["validation","api-client","bulk-size-limit"],"backgroundTag":"payload-too-large","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}