Safeguard
Security Guides•

What page size limits should an API and its SDK enforce by default?

Set a modest default page size, a hard maximum and a rate limit, and make SDK helpers paginate for the caller. Covers OWASP API4 and a limits checklist.

Safeguard Security Team
4 min read

An API should apply a modest default page size and a hard maximum even when the client asks for more, and the SDK should paginate for the caller instead of requesting everything at once. Unbounded list requests are an easy way to exhaust memory, bandwidth and budget.

The risk, in OWASP terms

OWASP lists unrestricted resource consumption as API4 in its 2023 API Security Top 10. It notes that APIs often do not limit client interactions, and that crafted requests, including ones with parameters that control how many resources are returned, can exhaust capacity. It names limits that may be missing: execution timeouts, maximum memory, maximum upload file size, number of operations in a single request, and the number of records per page to return in a single request response. Its mitigation guidance asks you to define and enforce a maximum size of data on incoming parameters and payloads, such as maximum length for strings, maximum number of elements in arrays and maximum upload size, and to limit how often a client can call the API.

Limits to set, in one table

LimitWhere it livesNotes
Default page sizeServerApplied when the client sends none
Maximum page sizeServerClamp requests above it, or reject with a clear error
Maximum request body sizeGateway and serverInclude per field string and array limits
Rate limit per clientGatewayReturn Retry-After on throttle
Query timeoutServerStops expensive filters hanging
Total result windowServerCap how deep a client can page

Steps to implement

  1. Choose a default that serves most callers in one request, and a maximum that you can serve at peak load. Test both with realistic data volumes.
  2. Clamp or reject. Silent clamping is friendly, but document it, and return the effective page size in the response so clients are not confused.
  3. Prefer cursor based pagination for large or changing collections. Offset pagination gets slower the deeper it goes, which attackers can exploit.
  4. Limit expensive filters and sorts to indexed fields, and cap the number of filters in one request.
  5. Pair limits with rate limits per credential, and send a Retry-After header when you throttle, as the HTTP specification describes.
  6. In the SDK, provide an iterator that follows cursors and applies backoff, and make the default page size match the server default.
  7. Set a spending limit or alert on any third party service your endpoints call, as OWASP suggests, so a single abusive client cannot run up the bill.
  8. Monitor the distribution of requested page sizes. A sudden jump in requests at the maximum is a signal worth investigating.

What the SDK should not do

It should not offer an "all" option that loops forever and loads everything into memory. If callers need a full export, give them a documented export endpoint with its own limits, authentication scope and audit logging. See data minimization in API design for ways to shrink what each response carries.

Try it yourself

Open the demo to see how an API security scan reports findings, and look for any that relate to missing limits.

Click through it at your own pace, or open it full screen.

Quick check

Should a request above the maximum be clamped or rejected?

Either works if documented. Clamping is friendlier, rejection is more explicit. Return the effective page size so clients know what happened.

Is a rate limit enough without page limits?

No. A single large request can be costly on its own, so size limits and rate limits work together.

Safeguard's API security scanning, policies and gates, and free scan at gold.safeguard.sh/scan help you check endpoints against rules like these before release.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.