|
| 1 | +.. _rate_limits: |
| 2 | + |
| 3 | +Rate Limits |
| 4 | +=========== |
| 5 | + |
| 6 | +In order to be secure out of the box various rate limits are in place. The rate |
| 7 | +limit mechanism is backed by a Django cache. Hence, rate limiting will not work |
| 8 | +properly if you are using the `DummyCache`. |
| 9 | + |
| 10 | +When rate limits are hit the ``429.html`` template is rendered, |
| 11 | +alternatively, you can configure a custom handler by declaring |
| 12 | +a ``handler429`` view in your root URLconf. |
| 13 | + |
| 14 | +Rate limits are consumed by triggering actions, the full list of which is |
| 15 | +documented below. Per action, the rate can be configured. The rate itself is an |
| 16 | +amount, per time unit, per either IP address, user or action-specific key. |
| 17 | + |
| 18 | +For example, requesting a password reset is an action that is both limited |
| 19 | +globally by IP address, as well as per email. Here, the email address used is |
| 20 | +the specific key. |
| 21 | + |
| 22 | + |
| 23 | +Implementation Notes |
| 24 | +-------------------- |
| 25 | + |
| 26 | +The builtin rate limitting relies on a cache and uses non-atomic operations, |
| 27 | +making it vulnerable to race conditions. As a result, users may occasionally |
| 28 | +bypass the intended rate limit due to concurrent access. However, such race |
| 29 | +conditions are rare in practice. For example, if the limit is set to 10 requests |
| 30 | +per minute and a large number of parallel processes attempt to test that limit, |
| 31 | +you may occasionally observe slight overruns—such as 11 or 12 requests slipping |
| 32 | +through. Nevertheless, exceeding the limit by a large margin is highly unlikely |
| 33 | +due to the low probability of many processes entering the critical non-atomic |
| 34 | +code section simultaneously. |
| 35 | + |
| 36 | + |
| 37 | +Testing |
| 38 | +------- |
| 39 | + |
| 40 | +Unless the rate limit is disabled or the default limits are increased, you might |
| 41 | +run intro problems if you're running unit tests that are dependant on |
| 42 | +funcionalities covered by the rate limits. For example, if you're testing the |
| 43 | +`confirm_email` functionality in your unit tests and you're testing if the |
| 44 | +verification email is sent twice after requesting it twice, only one of the |
| 45 | +emails will be sent. |
0 commit comments