Skip to content

Commit 5aa77f7

Browse files
authored
Merge pull request rails#52981 from gregmolnar/rate-limit-guides
mention the rate limiter in the security guides [ci-skip]
2 parents 2052ca4 + 45b2aea commit 5aa77f7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

guides/source/security.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,29 @@ There are a number of authentication plug-ins for Rails available. Good ones, su
445445

446446
### Brute-Forcing Accounts
447447

448-
NOTE: _Brute-force attacks on accounts are trial and error attacks on the login credentials. Fend them off with more generic error messages and possibly require to enter a CAPTCHA._
448+
NOTE: _Brute-force attacks on accounts are trial and error attacks on the login credentials. Fend them off with rate-limiting, more generic error messages and possibly require to enter a CAPTCHA._
449449

450450
A list of usernames for your web application may be misused to brute-force the corresponding passwords, because most people don't use sophisticated passwords. Most passwords are a combination of dictionary words and possibly numbers. So armed with a list of usernames and a dictionary, an automatic program may find the correct password in a matter of minutes.
451451

452452
Because of this, most web applications will display a generic error message "username or password not correct", if one of these are not correct. If it said "the username you entered has not been found", an attacker could automatically compile a list of usernames.
453453

454454
However, what most web application designers neglect, are the forgot-password pages. These pages often admit that the entered username or e-mail address has (not) been found. This allows an attacker to compile a list of usernames and brute-force the accounts.
455455

456-
In order to mitigate such attacks, _display a generic error message on forgot-password pages, too_. Moreover, you can _require to enter a CAPTCHA after a number of failed logins from a certain IP address_. Note, however, that this is not a bullet-proof solution against automatic programs, because these programs may change their IP address exactly as often. However, it raises the barrier of an attack.
456+
In order to mitigate such attacks, you can use rate limiting. Rails comes with a
457+
built-in [rate-limiter](https://edgeapi.rubyonrails.org/classes/ActionController/RateLimiting/ClassMethods.html#method-i-rate_limit). You can enable it in your sessions controller with a single line:
458+
459+
```
460+
class SessionsController < ApplicationController
461+
rate_limit to: 10, within: 3.minutes, only: :create
462+
end
463+
```
464+
465+
Refer to the [API documentation](https://edgeapi.rubyonrails.org/classes/ActionController/RateLimiting/ClassMethods.html#method-i-rate_limit) for details about the various parameters.
466+
467+
Additionally, you can _display a generic error message on forgot-password pages, too_. Moreover, you can _require to enter a CAPTCHA after a number of failed logins from a certain IP address_.
468+
469+
NOTE: All of these mitigation techniques are not a bullet-proof solution against automatic programs, because these programs may change their IP address exactly as often. However, it raises the barrier of an attack.
470+
457471

458472
### Account Hijacking
459473

0 commit comments

Comments
 (0)