-
Notifications
You must be signed in to change notification settings - Fork 9
Closed
internetarchive/openlibrary
#11288Description
The OTP must first be sanitized by a regex.
from openlibrary.core import cache
class thirdparty_otp(delegate.page):
path = "/account/otp/send"
def POST(self):
import time
i = web.input(otp=None, email=None, ts=None, ip=None)
if not (i.ip and i.email and i.ts and i.otp):
return web.badrequest()
mc = cache.get_memcache()
# IP-based throttle
ip_key = f"otp:ip:{i.ip}"
if not mc.add(ip_key, 1, expires=60): # 60s TTL
return web.forbidden("This IP must wait before requesting again")
# Email-based throttle
email_key = f"otp:email:{i.email}"
if not mc.add(email_key, 1, expires=60):
return web.forbidden("This email must wait before requesting again")
web.sendmail(
config.from_address,
i.email,
subject="Your One Time Password",
message=web.safestr(f"Your one time password is: {i.otp}"),
)
return delegate.RawText(f"OTP Successfully Sent")
Metadata
Metadata
Assignees
Labels
No labels