caddy-ratelimit: I am sure that rate limit not working well
I have nextjs app behind caddy server and I have DDOS attacks. I’ve setup rate limit in caddy file.
rate_limit {
distributed
zone ip_rate {
key {remote_host}
events 250
window 300s
}
zone ip_rate_min {
key {remote_host}
events 70
window 100s
}
}
And in nextjs app I made app level rate limiter
const ip = headers["x-forwarded-for"] as string;
try {
await limiter.check(70, ip);
} catch (e) {
console.log("will block ip", ip);
appContext.ctx.req?.destroy();
}
And I still get over than 100 lines in log
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 19 (8 by maintainers)
I really understand that you need a way to reproduce the issue to be able to solve it. I don’t know how to reproduce it but I’m 100% sure of the validity of the issue. thanks alot @mholt @mohammed90
I’m not able to reproduce it. I used Vegeta for the load testing, and I don’t see requests passing once the rate limit is hit. Here are the results I witnessed.
Run 1: Without
distributed
Run 2: with
distributed
Sample Caddy log line on rate-limit:
If your config has more than what’s shared, please share the full details without redaction. Also check if you’re truly running the configuration you think you’re running.
Unfortunately, I couldn’t reproduce it. But I can see attackers’ IPs passing the web server’s rate limit and reach the application layer rate limit.
I will try to find a way to reproduce it.
Note that any rate limiter using the remote IP as the zone key won’t stop DDoS attacks because you’ll have a lot of different IPs.
Once we have the information needed to reproduce the bug we’ll take a look!