---
title: "An API without limits bills you for someone else: set a cap"
description: "According to OWASP, an API is exposed if even one limit is missing or set wrong: execution time, memory, upload size, operations per request, records per page, or a third-party spending limit."
url: https://ihsanalapsi.dev/articles/api-unrestricted-resource-consumption
lang: en
date: 2026-11-25
updated: 2026-11-25
tags: ["App security", "Web development"]
author: Ihsan Alapsi (إحسان العبسي)
---
# An API without limits bills you for someone else: set a cap

Your "forgot password" page sends a code by SMS, and every message costs you cents. The page works correctly for each user, and the problem only shows when someone requests it tens of thousands of times with a script. By the end of this article you will know what this class of flaw is, the limits every API needs, and how to start on them today.

## What is OWASP API4:2023?

API4:2023 Unrestricted Resource Consumption is a category in the OWASP API Security Top 10. It means the API lets a client consume resources or money with no cap.

According to [OWASP's API4:2023 page](https://api-security.owasp.org/editions/2023/en/0xa4-unrestricted-resource-consumption), an API is vulnerable if at least one limit is missing or set inappropriately, meaning too low or too high. Resources here are not only CPU and memory: an SMS or a call to a paid outside service is a resource too.

## How does a message that costs cents turn into thousands of dollars?

It happens when every request from the browser creates a cost on your account, and nobody counts how many requests came from the same client.

The first scenario on the same page: a social network sends a "forgot password" code by SMS through a third-party provider, and the provider charges $0.05 per message. The attacker wrote a script that called this page tens of thousands of times, and the company lost thousands of dollars within minutes.

The mistake here is one of logic, not technology: the page was built for a user who forgot a password once, and nobody asked what happens if the same request comes a hundred thousand times. The code is correct, and the bill has no ceiling. To see what the whole reset path should look like, read the [password reset token flow article](/articles/password-reset-token-flow).

## Which limits does every API need?

OWASP names eight limits, and any one of them missing is enough to open the door:


| Limit                                                     | What happens without it                        |
| --------------------------------------------------------- | ---------------------------------------------- |
| Execution timeout                                         | One request keeps running and holds the server |
| Maximum allocable memory                                  | A heavy request exhausts server memory         |
| Maximum file descriptors                                  | The server stops opening new connections       |
| Maximum processes                                         | Processes eat the CPU                          |
| Maximum upload file size                                  | A huge file fills the storage                  |
| Operations in a single request (such as GraphQL batching) | One request does the work of many requests     |
| Records per page                                          | One request pulls the whole table              |
| Third-party spending limit                                | The bill grows with nobody to stop it          |


The second column is mine, to show why each limit matters. And having a limit is not enough: OWASP says a limit set too low or too high is also wrong.

## How do you close it in your code today?

You close it with limits on every request from the same client, a stricter limit on sensitive pages, and a cap on every number that comes from the request.

1. Limit how often each client can call the API in a set time window (rate limiting), and make it stricter on pages that cost money or are sensitive, such as verification codes and password recovery.
2. Set a maximum size for every input: string length, number of elements in arrays, and upload file size.
3. Check on the server every number that decides how many records come back, and cap it:

```js
// the server decides the limit, not the request
const pageSize = Math.min(requestedSize, MAX_PAGE_SIZE)
```

4. Set a spending limit with every outside provider you pay per request, and where there is none, configure billing alerts.

The same idea applies to your login page ([defending login from credential stuffing](/articles/credential-stuffing-login-defense)), and to any feature that calls an AI model you pay for per request ([unbounded consumption in LLM apps](/articles/llm-unbounded-consumption)).

## Where do you start now?

The lesson for us as developers: every page that spends money or resources on each request needs a per-client counter and a ceiling, because code that is correct for one user does not protect you from a script that calls it thousands of times. Open the list of your API routes now, mark every one that sends an SMS or email or calls a paid service, and check whether it has a limit. And if you want someone to test your API the way an attacker would, [Muhassan](/muhassan) does that. Which page costs you the most per request?

## FAQ

**Is a per-minute rate limit enough on its own?**

No. OWASP gives the example of one GraphQL request holding many upload operations, which passes the rate limit and exhausts server memory. You also need a limit on operations per request.

**What if my provider has no spending limit?**

OWASP says to set spending limits with the provider, and where that is not possible, to configure billing alerts so you find out early.

**Can the browser decide how many records a page returns?**

The browser can ask, but the server must check the number and cap it, because anyone can change the request and ask for the whole table.
