API rate limits and spending caps: protecting your backend and your bill
Set API request, resource and spending limits to reduce overload and unexpected third-party service costs.
An API that answers every request without limits can be overloaded, or can run up costs, by one script. OWASP lists this as API4:2023 Unrestricted Resource Consumption (https://owasp.org/API-Security/editions/2023/en/0xa4-unrestricted-resource-consumption/) in its 2023 API Security Top 10.
What can be exhausted
OWASP says satisfying requests uses network bandwidth, CPU, memory and storage, and sometimes paid third-party services such as SMS, email, phone calls or biometric checks, billed per request.
OWASP's limit checklist
OWASP says an API is vulnerable if at least one of these limits is missing or set inappropriately:
- execution timeouts
- maximum allocable memory
- maximum number of file descriptors
- maximum number of processes
- maximum upload file size
- number of operations in a single client request (for example GraphQL batching)
- number of records returned per page
- third-party providers' spending limits
Three scenarios from OWASP
- Paid SMS flow. A "forgot password" API triggers a third-party SMS at a stated $0.05 per call. An attacker scripts tens of thousands of calls and, in OWASP's scenario, the company loses thousands of dollars in minutes.
- GraphQL batching. A per-endpoint rate limit and a file-size check are bypassed by sending hundreds of upload operations in one request, exhausting server memory.
- Cloud bill. A file grows beyond a cache's 15 GB limit, every client pulls it directly, and with no cost alerts or maximum cost allowance, the monthly bill rises from about $13 to $8k in OWASP's example.
These are OWASP's illustrations, not Omnistu client cases.
How OWASP says to prevent it
- Limit memory, CPU, restarts, file descriptors and processes, for example through containers or serverless code.
- Define and enforce maximum sizes on all incoming parameters and payloads: string length, array size, upload size.
- Rate limit how often a client can call the API in a time window, tuned to business needs, with stricter policies for some endpoints.
- Throttle how often one client can run a single sensitive operation, such as validating an OTP or requesting password recovery.
- Validate server-side the parameters that control how many records come back.
- Configure spending limits for every provider or integration; if not possible, set billing alerts and define a response process. Alerts do not stop charges by themselves; enforce application-side limits where possible.
Questions for your developer
- Which of the limits above exist today, and what are their values?
- Do our SMS, email and AI provider accounts have spending limits or billing alerts?
- Can one request trigger many expensive operations?
- Is there a cap on page size?
Limits
This is OWASP's guidance for one risk category. We did not research rate-limiting tools or specific cloud services, and give no recommended numbers because they depend on your product.
By Omnistu.