Skip to content

Commit 870db6c

Browse files
Rate limit Buildbot by client IP
Old behavior used request_uri as the rate-limit key, so the bucket was shared globally per exact URL. One aggressive client hammering a common URL could consume that URL's allowance and cause unrelated users to be rate-limited too. It also did not catch scanners that spread requests across many unique URLs, since each URL had its own bucket. New behavior uses binary_remote_addr as the key and allows 10 requests per second with a burst of 200 before returning 429. This isolates aggressive scanners to their source IP and leaves other client IPs unaffected. The tradeoff is that users behind the same NAT, VPN, or proxy still share one client-IP bucket.
1 parent a96fcbf commit 870db6c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

docker-compose/nginx/templates/bb.conf.template

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ server {
1414
}
1515
}
1616

17-
# Default rate limited zone, with 30 requests per minute
18-
limit_req_zone $request_uri zone=bb:10m rate=30r/m;
17+
# Per-client rate limited zone. This catches scanners walking many unique
18+
# URLs without sharing one bucket across all visitors of a popular URL.
19+
limit_req_zone $binary_remote_addr zone=bb:10m rate=10r/s;
1920
client_max_body_size 10M;
2021

2122
server {
@@ -32,9 +33,9 @@ server {
3233
proxy_set_header X-Forwarded-Server $host;
3334
proxy_set_header X-Forwarded-Host $host;
3435

35-
# Use default zone for rate limiting, allow burst of 10 requests with
36-
# no delay
37-
limit_req zone=bb burst=10 nodelay;
36+
# Allow normal page/API bursts, but reject sustained aggressive clients.
37+
limit_req zone=bb burst=200 nodelay;
38+
limit_req_status 429;
3839

3940
location / {
4041
proxy_pass http://127.0.0.1:8010;

0 commit comments

Comments
 (0)