Skip to content

Commit 32b2c09

Browse files
committed
docs: rate limits vs atomicity
1 parent f08c6fe commit 32b2c09

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

docs/account/rate_limits.rst

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
Rate Limits
22
===========
33

4-
In order to be secure out of the box various rate limits are in place. The rate
5-
limit mechanism is backed by a Django cache. Hence, rate limiting will not work
6-
properly if you are using the `DummyCache`.
7-
8-
When rate limits are hit the ``429.html`` template is rendered,
9-
alternatively, you can configure a custom handler by declaring
10-
a ``handler429`` view in your root URLconf.
11-
12-
Rate limits are consumed by triggering actions, the full list of which is
13-
documented below. Per action, the rate can be configured. The rate itself is an
14-
amount, per time unit, per either IP address, user or action-specific key.
15-
16-
For example, requesting a password reset is an action that is both limited
17-
globally by IP address, as well as per email. Here, the email address used is
18-
the specific key.
4+
In this section the ratelimits related to the ``allauth.account`` app are
5+
documented. Refer to the :doc:`overall rate limit documentation <../common/rate_limits>`
6+
for more background information on the mechanism itself.
197

208
The rate limits are configured through the ``ACCOUNT_RATE_LIMITS`` setting:
219

@@ -63,13 +51,3 @@ The following actions are available for configuration:
6351
Users can request email confirmation mails via the email management view, and,
6452
implicitly, when logging in with an unverified account. This rate limit
6553
prevents users from sending too many of these mails.
66-
67-
68-
Additional notes:
69-
70-
Unless the rate limit is disabled or the default limits are increased, you might
71-
run intro problems if you're running unit tests that are dependant on
72-
funcionalities covered by the rate limits. For example, if you're testing the
73-
`confirm_email` functionality in your unit tests and you're testing if the
74-
verification email is sent twice after requesting it twice, only one of the
75-
emails will be sent.

docs/common/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Common Functionality
99
templates
1010
messages
1111
admin
12+
rate_limits

docs/common/rate_limits.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)