Skip to content

Commit 70085e8

Browse files
authored
feat: add rate limiting to 2fa attempts (#18584)
Limits specifically calls to the 2FA-related actions: - checking a recovery code - checking a TOTP value - checking a Webauthn value The rate limits were selected to be a balance of usability vs how long it would take a slow-roll actor to continue trying. Metrics are emitted for monitoring and alerting purposes. Refs: #8456 Signed-off-by: Mike Fiedler <[email protected]>
1 parent c941a3e commit 70085e8

File tree

6 files changed

+417
-36
lines changed

6 files changed

+417
-36
lines changed

tests/unit/accounts/test_core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def test_includeme(monkeypatch):
138138
"warehouse.account.user_login_ratelimit_string": "10 per 5 minutes",
139139
"warehouse.account.ip_login_ratelimit_string": "10 per 5 minutes",
140140
"warehouse.account.global_login_ratelimit_string": "1000 per 5 minutes",
141+
"warehouse.account.2fa_user_ratelimit_string": "5 per 5 minutes, 20 per hour, 50 per day", # noqa: E501
142+
"warehouse.account.2fa_ip_ratelimit_string": "10 per 5 minutes, 50 per hour", # noqa: E501
141143
"warehouse.account.email_add_ratelimit_string": "2 per day",
142144
"warehouse.account.verify_email_ratelimit_string": "3 per 6 hours",
143145
"warehouse.account.password_reset_ratelimit_string": "5 per day",
@@ -184,6 +186,14 @@ def test_includeme(monkeypatch):
184186
pretend.call(
185187
RateLimit("1000 per 5 minutes"), IRateLimiter, name="global.login"
186188
),
189+
pretend.call(
190+
RateLimit("5 per 5 minutes, 20 per hour, 50 per day"),
191+
IRateLimiter,
192+
name="2fa.user",
193+
),
194+
pretend.call(
195+
RateLimit("10 per 5 minutes, 50 per hour"), IRateLimiter, name="2fa.ip"
196+
),
187197
pretend.call(RateLimit("2 per day"), IRateLimiter, name="email.add"),
188198
pretend.call(RateLimit("5 per day"), IRateLimiter, name="password.reset"),
189199
pretend.call(RateLimit("3 per 6 hours"), IRateLimiter, name="email.verify"),

0 commit comments

Comments
 (0)