Appearance
Rate limits Since v0.1
Rate limits stop a client from sending more requests than an endpoint should see: password guessing on a login form, scraping, or one caller using up an API. Each limit counts the matching requests in a sliding time window and, above the limit, answers 429 Too Many Requests, only logs, or bans the client. A separate cap limits how many requests one client may have in progress at the same time.
Before you begin
- Role:
operatorfor the application (viewercan read the limits). - To count per API consumer (
by: consumer), set up API authentication for the application first, so that requests carry a known consumer. - If clients reach the product through a proxy or load balancer, add it under Traffic > Trusted proxies. Otherwise every client counts as the proxy's address.
Add a rate limit
text
1. Open Applications > All applications, and select the application.
2. In the application menu, open Request checks > Access and rate limits.
3. On the Rate limits tab, under Rules, select Add rate limit.
4. Enter a Name, the number of Requests and the window (Per).
5. Narrow it with Paths and Methods, choose Counted by and Action.
6. Select Preview changes, add a comment and select Apply.sh
waap rules get -app shop -list rate_limits > rate.yaml
# edit rate.yaml, then preview and apply
waap rules set -app shop -list rate_limits -f rate.yaml -dry-run
waap rules set -app shop -list rate_limits -f rate.yaml -m "limit login attempts"yaml
# rate.yaml (waap rules set), or applications[].policy.rate_limits.rules in the configuration
- name: login
when:
paths: ["/login"]
methods: [POST]
limit: 10
per: 1mEvery matching limit counts
Unlike access rules, rate limits are not first-match. Each limit that matches a request counts it, and the client is refused if it is over any of them. Order does not matter.
Start in log
Give a new limit action: log and watch the events for a few days before switching it to block. Limits suggested from your traffic (below) are added this way.
Use suggested limits Since v0.2
The product can propose limits per path from the traffic log: the suggested number of requests per minute per client, and how many clients and requests the limit would have affected.
text
1. Open the application's Access and rate limits page, Suggestions tab.
2. To compute them now, select Run suggestions.
3. Review each suggestion: Path, Limit, Clients limited, Requests limited.
4. To accept one, select Preview changes on it, then Apply: it is added
as a rate limit with action log. Select Reject to hide it for good.
5. Change the new limit's Action to block on the Rate limits tab when the
events show only unwanted traffic.sh
waap ratelimit suggestions list -app shop
waap ratelimit suggestions run -app shop -window 24h
waap ratelimit suggestions accept ID -app shop -m "from suggestions"
waap ratelimit suggestions reject ID -app shopyaml
# An accepted suggestion becomes an ordinary rate limit that only logs:
- name: ... # chosen by the product
when: {paths: [...]}
limit: ...
per: 1m
action: logrun computes suggestions now from the last -window of traffic (1m to 7d, default 24h) and replaces the open ones; the computation also runs once a day.
Cap requests in progress per client
Requests in progress per client refuses a client that already has that many requests open, with 429 and Retry-After: 1. It protects slow endpoints from one client holding many connections.
text
1. Open the application's Access and rate limits page, Rate limits tab.
2. Set Requests in progress per client (0: no cap).
3. Select Preview changes, then Apply.sh
waap apps set -app shop -m "cap parallel requests" policy.rate_limits.per_client_concurrency=20yaml
applications:
- name: shop
policy:
rate_limits:
per_client_concurrency: 20 # 0: no capSwitch rate limits to block
text
1. Open the application's Access and rate limits page, Rate limits tab.
2. Set Rate limit protection mode to block (or leave it empty to follow
the application).
3. Select Preview changes, then Apply.sh
waap apps set -app shop -m "enforce rate limits" policy.rate_limits.mode=blockyaml
applications:
- name: shop
policy:
mode: block
rate_limits:
mode: block # empty: same as the application; detect winsAutomatic bans depend on this mode
Automatic bans are counted by the rate-limit module. They work only while this module is in block. For details, see Bans.
Settings reference
Module settings
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Rate limit protection mode (policy.rate_limits.mode) | Whether limits refuse (429) or only log. | empty (same as the application) | detect, block, empty | all; detect wins over the application's block |
Requests in progress per client (policy.rate_limits.per_client_concurrency) | Refuses a client with this many requests open. | 0 (no cap) | 0 to 10000 | refuses only in block mode |
Rate limit
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Name (name) | Identifies the limit in configuration and events; it is the event's rule ID. | none (required) | lowercase letters, digits and dashes, 1 to 63 characters, starting with a letter or digit; unique in the list | all |
Requests (limit) | Requests accepted in the window; the next one is over the limit. | none (required) | 1 to 1000000 | all |
Per (per) | The sliding window the requests are counted in. | none (required) | duration, 1s to 24h | all |
Paths (when.paths) | Only requests to these paths are counted. | none (every request) | up to 100; exact, or a prefix ending in *; must start with /; no query string | all |
Methods (when.methods) | Only requests with these methods are counted. | none (any method) | up to 100; uppercase | all |
Counted by (by) | What is counted: each client address, each API consumer, or all matching requests together (one quota for the endpoint). | client | client, consumer, all | consumer: requests without a consumer are not counted |
Action (action) | What happens over the limit. | block | block (429), log, ban | block, ban act only in block mode |
Ban for (ban_for) | How long a client over the limit is banned. | none | duration, 1s to 168h (required with ban) | action ban only; needs Counted by client |
What the client receives
| Action | Response in block mode | Retry-After |
|---|---|---|
block | 429 | the window (Per) in seconds |
ban | 429, and the address is banned | Ban for in seconds |
log | the request passes | none |
| concurrency cap | 429 | 1 |
Requests refused for being over a limit still count, so a client that keeps sending stays over the limit until its rate drops. While a client stays over a limit, one event per client and limit is recorded each minute.
Examples
Slow down password guessing, banning persistent clients for 15 minutes:
yaml
- name: login
when: {paths: ["/login"], methods: [POST]}
limit: 10
per: 1m
action: ban
ban_for: 15mA general per-client limit on the API, and a shared quota for an expensive export:
yaml
- name: api-per-client
when: {paths: ["/api/*"]}
limit: 600
per: 1m
- name: export-quota
when: {paths: ["/api/export"]}
limit: 100
per: 1h
by: allA per-consumer limit that only logs while you measure:
yaml
- name: api-per-consumer
when: {paths: ["/api/*"]}
limit: 1000
per: 1m
by: consumer
action: logLimits
| Limit | Value |
|---|---|
| Rate limits per application | 200 |
| Requests per limit | 1 to 1,000,000 |
| Window | 1s to 24h |
| Paths and methods per limit | 100 each |
| Requests in progress per client | 0 to 10,000 |
| Ban for | 1s to 168h |
| Counters | per node: in a high-availability pair each node counts its own requests |
Troubleshooting
Legitimate clients get 429
- Cause: the limit is too low for the endpoint, or many users share one address (a proxy that is not a trusted proxy, or a corporate gateway).
- Check: the event names the limit, the count and the window; compare with the Suggestions tab.
- Fix: raise Requests, narrow Paths, add the proxy under Traffic > Trusted proxies, or exempt known clients with an access rule
trustand Skip modulesrate_limits.
Preview refuses: ban needs by: client (a ban is for a client address)
- Cause: a ban applies to an address, so it cannot follow a per-consumer or shared count.
- Fix: use
action: blockwithby: consumerorall, or set Counted by toclient.
A limit never triggers
- Cause: the application or Rate limit protection mode is in
detect(events say the limit was exceeded but the request passes),by: consumeron requests without a consumer, or Paths that do not match (paths match without the query string). - Fix: check the mode, the consumer setup, and the path pattern (
/api/*for a prefix).
No suggestions appear
- Cause: not enough traffic in the window for a path; such paths are shown as skipped.
- Fix: run
waap ratelimit suggestions run -app NAME -window 7d, or wait for more traffic.