-
Notifications
You must be signed in to change notification settings - Fork 599
[ENG-158] feat: Abuse protection for OTP based login #3632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 18 commits
aff7eda
45b86b9
c8eb2e3
c77cf11
3fe211c
516ab65
74dac3d
b497806
fbd837e
62b719a
4a5fafc
b22ff0d
f21c324
7931218
93d844c
e7d5dea
451a508
0a01e97
19761fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from django.conf import settings | ||
|
|
||
| from care.utils.lock import Lock | ||
|
|
||
|
|
||
| class OTPSendLock(Lock): | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| def __init__(self, phone_number, timeout=settings.LOCK_TIMEOUT): | ||
| self.key = f"lock:otp_send:{phone_number}" | ||
| self.timeout = timeout | ||
|
|
||
|
|
||
| class OTPVerifyLock(Lock): | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
praffq marked this conversation as resolved.
Dismissed
|
||
| def __init__(self, phone_number, timeout=settings.LOCK_TIMEOUT): | ||
| self.key = f"lock:otp_verify:{phone_number}" | ||
| self.timeout = timeout | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from datetime import timedelta | ||
| from logging import Logger | ||
|
|
||
| from celery import shared_task | ||
| from celery.utils.log import get_task_logger | ||
| from django.conf import settings | ||
|
|
||
| from care.facility.models.patient import MobileOTP | ||
| from care.utils.time_util import care_now | ||
|
|
||
| logger: Logger = get_task_logger(__name__) | ||
|
|
||
|
|
||
| @shared_task | ||
| def cleanup_expired_otps(): | ||
| """ | ||
| Hard-deletes MobileOTP rows older than the lockout window | ||
| """ | ||
| cutoff = care_now() - timedelta(minutes=settings.OTP_LOCKOUT_MINUTES) | ||
| count, _ = MobileOTP.objects.filter(modified_date__lt=cutoff).delete() | ||
|
Comment on lines
+19
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The cleanup task deletes rows where Concrete bypass: send 9 reset-password OTPs before 11 pm; the midnight cleanup deletes them ( |
||
| logger.info("Deleted %d expired OTP rows", count) | ||
Uh oh!
There was an error while loading. Please reload this page.