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

When lifetime is reset with refreshTimeoutOnRequest? #14

Closed
SyRenity opened this issue May 25, 2015 · 7 comments
Closed

When lifetime is reset with refreshTimeoutOnRequest? #14

SyRenity opened this issue May 25, 2015 · 7 comments

Comments

@SyRenity
Copy link

First of all, thanks for the great module!

From reading the documentation, I'm not very clear when exactly the lifetime is reset with refreshTimeoutOnRequest set to true.

Is it once the lifetime ends a new one starts then?

@AdamPflug
Copy link
Owner

So basically the lifetime is how long the record of request counts for an IP is kept. refreshTimeoutOnRequests renews that timeout each time a new request comes from that IP if it's set to true, while if it's set to false the timeout is the time since the first request from that IP.

If you look at the globalBruteforce example in the README, you'll see it's set to false - so that there is a limited number of requests from an IP in a given 24 hour period. If refreshTimeoutOnRequest was set to true (as is default) you would be locked out for 24 hours from the last request rather than 24 hours from the first request.

If you want to manually reset the count (for example because of a successful login) just call req.brute.reset(). I'm not sure I'm making this clear enough in the current "Basic Example" maybe I need to add the call to that.

Thoughts?

  • Adam

@SyRenity
Copy link
Author

So for example, following settings:

var genericBruteforce = new ExpressBrute(store, {
    freeRetries: 100,
    lifetime: 30,
    attachResetToRequest: false,
    refreshTimeoutOnRequest: false,
});
  • allow up 100 requests during 30 seconds from a particular IP
  • ban 101 request and higher from the IP during these 30 seconds
  • once these 30 seconds are over, the IP can send up to 100 requests more
    Is this correct?

However if the refreshTimeoutOnRequest set to true, then it will not ban at all (with counter resetting every request)? Or perhaps I misunderstand how lifetime works?

@AdamPflug
Copy link
Owner

Almost. You would also want to set minWait and maxWait to 31. Oh, and I guess freeRetries would need to be 99. Then it would work as you described for the refreshTimeoutOnRequest: false case.

If true it would:

  • Allow up 100 requests from a particular IP. Then:
  • Ban 101 request and higher from the IP for 30 seconds from the last un-blocked request.
  • Once these 30 seconds are over, the IP can send up to 100 requests more
  • Additionally, if more than 30 seconds elapse between any two requests the request count is set back to 1

@SyRenity
Copy link
Author

@AdamPflug Thanks, it's more clear now.

Would be great to have these 2 cases described more clearly in doc, e.g.:

  • Option 1 - limit amount of requests in a certain time-period
  • Option 2 - limit amount of requests over a period

The problem imho that the difference is too subtle, perhaps use case examples would help.

@AdamPflug
Copy link
Owner

I'm trying to balance keeping the documentation as simple as short as possible with providing enough information. Hopefully rephrasing it makes things a little clearer - if not I've linked to this issue.

@kangwen
Copy link

kangwen commented Aug 22, 2017

very nice

@bbock
Copy link

bbock commented Feb 16, 2018

minWaitand maxWait are in ms, so I guess in the example above they should be set to 30001 instead of 31 as described in #14 (comment). At least, fo me it does the trick 😉

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

4 participants