Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing headers when comparing to base laravel 429 #184

Open
lk77 opened this issue Dec 5, 2022 · 0 comments
Open

Missing headers when comparing to base laravel 429 #184

lk77 opened this issue Dec 5, 2022 · 0 comments

Comments

@lk77
Copy link

lk77 commented Dec 5, 2022

Hello,

the firewall does not provide/override some headers that laravel provide,

firewall 429 headers :

HTTP/1.1 429 Too Many Requests
[...]
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 53
[...]

those are set by laravel ThrottleRequests middleware, but are not overriden by the firewall when under attack

laravel throttling 429 headers when the limit is reach on ThrottleRequests middleware :

HTTP/1.1 429 Too Many Requests
[...]
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
Retry-After: 27
X-RateLimit-Reset: 1670235836
[...]

I've overriden Responder:respond to add those headers :

if ($response['code'] == 429)
{
    return Response::make($response['message'], $response['code'], [
            "Retry-After"           => $maxSeconds,
            "X-RateLimit-Limit"     => $maxRequestCount,
            "X-RateLimit-Remaining" => max($maxRequestCount - $data['ip']['requestCount'], 0),
            'X-RateLimit-Reset'     => \Carbon\Carbon::now()->timestamp + ($maxSeconds * 1000),
        ]);
}
if ($this->isAttack()) {
    return (new Responder())->respond($this->getResponseConfig(), $this->record, $this->maxRequestCount, $this->maxSeconds);
}

Expected feature

when under attack, and on a 429 response, override Retry-After and X-RateLimit-* headers according to maxRequestCount and maxSeconds.

And optionally, when under attack or not, be able to lower X-RateLimit-Remaining, if the laravel throttle remaining request is actually higher than the firewall remaining requests, i'm not sure if it's easily doable though, i'm not sure if calling RateLimiter::remaining is an option inside AttackBlocker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant