-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add rate limiting to login requests #1777
Conversation
Add rate limiting to login requests using rack-attack. As a starting point, we are setting a limit of 5 request per minute to /api/users/sign_in.
Enable devise lockable to lock users after 5 consecutive incorrect login attempts. Account will be unlocked automatically after 1 hour.
e60a914
to
0b658cd
Compare
028a3ca
to
ae61d9a
Compare
- Moved limits to the configuration file - Added tests for all limits
ae61d9a
to
266768c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo, but after I fixed it locally, I was able to verify both features:
- User account locked after failed login attempts
- Rate limit error when many calls are made to the GraphQL API endpoint
FYI @jayjay-w: You don't need to explicitly call .to_i
when retrieving a configuration value... you can pass a :integer
parameter to CheckConfig.get
: https://github.com/meedan/check-api/blob/develop/app/lib/check_config.rb#L10
6090a70
to
44de8b7
Compare
Reduce the number of actual api calls to 2 per test when testing rate limiting.
Code Climate has analyzed commit 4b03a98 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (100% is the threshold). This pull request will bring the total coverage in the repository to 99.9% (0.0% change). View more on Code Climate. |
hey @jayjay-w , there was a failed test :)
|
Interesting...@caiosba I will fix it in a new PR. |
Description
Add rate limiting to login requests using rack-attack. As a starting point, we are setting a limit of 5 request per minute to /api/users/sign_in.
References: CV2-4164
How has this been tested?
Tested by confirming that:
429: Too many requests
error. This can be validated using both the check web application or an api client. . The default limit is 10 requests per minute.429
error as well. The default limit is 100 requests per minute.Things to pay attention to during code review
Checklist