Skip to content

Commit 72d71fd

Browse files
authored
fix(relocation): Add rate limiter to username claiming (#68797)
The follows up on the comment from #68630, which went unaddressed due to auto-merge.
1 parent 51707c6 commit 72d71fd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/sentry/web/frontend/accounts.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def relocate_reclaim(request, user_id):
177177
@set_referrer_policy("strict-origin-when-cross-origin")
178178
@control_silo_function
179179
def recover_confirm(request, user_id, hash, mode="recover"):
180+
from sentry import ratelimits as ratelimiter
181+
180182
try:
181183
password_hash = LostPasswordHash.objects.get(user=user_id, hash=hash)
182184
if not password_hash.is_valid():
@@ -186,6 +188,24 @@ def recover_confirm(request, user_id, hash, mode="recover"):
186188
except LostPasswordHash.DoesNotExist:
187189
return render_to_response(get_template(mode, "failure"), {"user_id": user_id}, request)
188190

191+
extra = {
192+
"ip_address": request.META["REMOTE_ADDR"],
193+
"user_agent": request.META.get("HTTP_USER_AGENT"),
194+
}
195+
196+
if request.method == "POST" and ratelimiter.backend.is_limited(
197+
"accounts:confirm:{}".format(extra["ip_address"]),
198+
limit=5,
199+
window=60, # 5 per minute should be enough for anyone
200+
):
201+
logger.warning("confirm.rate-limited", extra=extra)
202+
203+
return HttpResponse(
204+
"You have made too many attempts. Please try again later.",
205+
content_type="text/plain",
206+
status=429,
207+
)
208+
189209
# TODO(getsentry/team-ospo#190): Clean up ternary logic and only show relocation form if user is unclaimed
190210
form_cls = RelocationForm if mode == "relocate" else ChangePasswordRecoverForm
191211
if request.method == "POST":

0 commit comments

Comments
 (0)