kin: BATON-008-backend_dev
This commit is contained in:
parent
e21bcb1eb4
commit
4c9fec17de
11 changed files with 651 additions and 4 deletions
|
|
@ -16,6 +16,9 @@ _RATE_WINDOW = 600 # 10 minutes
|
|||
_SIGNAL_RATE_LIMIT = 10
|
||||
_SIGNAL_RATE_WINDOW = 60 # 1 minute
|
||||
|
||||
_AUTH_REGISTER_RATE_LIMIT = 3
|
||||
_AUTH_REGISTER_RATE_WINDOW = 600 # 10 minutes
|
||||
|
||||
|
||||
def _get_client_ip(request: Request) -> str:
|
||||
return (
|
||||
|
|
@ -55,3 +58,10 @@ async def rate_limit_signal(request: Request) -> None:
|
|||
count = await db.rate_limit_increment(key, _SIGNAL_RATE_WINDOW)
|
||||
if count > _SIGNAL_RATE_LIMIT:
|
||||
raise HTTPException(status_code=429, detail="Too Many Requests")
|
||||
|
||||
|
||||
async def rate_limit_auth_register(request: Request) -> None:
|
||||
key = f"authreg:{_get_client_ip(request)}"
|
||||
count = await db.rate_limit_increment(key, _AUTH_REGISTER_RATE_WINDOW)
|
||||
if count > _AUTH_REGISTER_RATE_LIMIT:
|
||||
raise HTTPException(status_code=429, detail="Too Many Requests")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue