yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

Incorrect value for X-Rate-Limit-Reset header in RateLimiter #15432

Closed bizley closed 6 years ago

bizley commented 6 years ago

I suspect that method addRateLimitHeaders gets incorrect value for $reset argument resulting in incorrect header X-Rate-Limit-Reset value but I'm not sure of that because I can not believe no one noticed it for more than 3 years - please correct me if I'm wrong here.

What steps will reproduce the problem?

Implement methods from RateLimitInterface like in docs.
Set rate limit to [2, 10] (2 requests per 10 seconds).
Send request and check headers.

What is the expected result?

X-Rate-Limit-Limit = 2
X-Rate-Limit-Remaining = 1
X-Rate-Limit-Reset = 5

What do you get instead?

X-Rate-Limit-Limit = 2
X-Rate-Limit-Remaining = 1
X-Rate-Limit-Reset = 0

Additional info

According to docs X-Rate-Limit-Reset is

the number of seconds to wait in order to get the maximum number of allowed requests

Q A
Yii version 2.0.13.1
samdark commented 6 years ago

You're not wrong :)

pujaydv commented 1 year ago

I have added rate limter config in our project but didn't get any below parameters in response headers X-Rate-Limit-Limit X-Rate-Limit-Remaining X-Rate-Limit-Reset Please any one guide me on this. How to implement ratelimiter in yii2.

bizley commented 1 year ago

Check 2 things (as in the guide):

  1. Implement RateLimitInterface for your user identity class.
  2. Either use rest based controller, or add rate limiter filter in the controller behaviors.

If this not help please ask at the forum.